from django.shortcuts import render
from BizPit_app.models import *
#from BizPit_api.BizPit_api_app import property_details
import requests
from time import time, strftime, gmtime, sleep
import datetime
import os

from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.shortcuts import render_to_response

# Create your views here.

@csrf_exempt
def mainpage(request):

	return render_to_response('login.html')


import xlrd
import MySQLdb

@csrf_exempt
def Excel_add(request):
	
	#return render_to_response('mainpage.html')
        print "am innn "
       	list1=[]
        path="static/my_data.xlsx"
        book1 = xlrd.open_workbook(path)

	for sheet in book1.sheets():
		
		for r in range(1, sheet.nrows):
			property_name=sheet.cell(r,0).value
			property_type=sheet.cell(r,1).value
			subtype=sheet.cell(r,2).value
			status=sheet.cell(r,3).value
			location=sheet.cell(r,4).value
			address=sheet.cell(r,5).value
			lat=sheet.cell(r,6).value
			lon=sheet.cell(r,7).value
			price=sheet.cell(r,8).value
			submitted_by=sheet.cell(r,9).value

			my_id1=0
			data1 = Property_Details.objects.all()
			for i in data1:
				my_id1=i.property_id
			myid=my_id1+1


			print "My data... ",property_name,property_type,subtype,status,location,address,lat,lon,price,submitted_by


			data=Property_Details(property_id=myid,status=status,property_type=property_type,property_subtype=subtype,property_name=property_name,location=location,address=address,latitude=lat,longitude=lon,starting_price=price,submitted_by=submitted_by)

			data.save()

        return render_to_response('login.html')

@csrf_exempt
def add_property(request):
	user=request.POST["user"]
	password=request.POST["password"]
	email_id=[]
	data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                owner="Owner"
        else:
                owner="Super_owner"
        non_week_day=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
        return render_to_response('property.html',{"non_week_day":non_week_day,"user":user,"password":password,"owner_id":owner})



from geopy.geocoders import Nominatim
import geopy

@csrf_exempt
def Save_property(request):

	new_cur_pathlist=[]
	prop_name=request.POST["name_proj"]
	address=request.POST["searchTextField"]
	phone=request.POST["phone"]
	price=request.POST["price"]
	
	user=request.POST["user"]
        password=request.POST["Password"]
	print "user........",user

	#geolocator = Nominatim()

	#addres = str(raw_input("Enter the name or address of the location : "))
	print address
	#location = geolocator.geocode(address)
	#print(location.address)
	#print((location.latitude, location.longitude))
	#lat=location.latitude
	#lon=location.longitude
	#add=location.address
	#split_loc=add.split(' ', 1 )
	#loc=split_loc[0]

	lat=request.POST['cityLat']
	lon=request.POST['cityLng']
	loc=request.POST['city2']
	print "latit..",lat
	print "long...",lon
	print "loc....",loc
	lat_cut=float('%.2f' % float(lat))
        lon_cut=float('%.2f' % float(lon))
	time=datetime.datetime.now()

	typ_list=[]
	
	my_type=request.POST.getlist("type_list[]")

	p_type_p=0
        p_type_t=0
        p_type_e=0
        p_type_m=0
        
	for i in my_type:
		
              typ_list.append(str(i))

       	print "type_list--->",typ_list		
        for pt in typ_list:
                print "pt in p_type1---->",pt
                if "Plug & Play" in pt:
                	p_type_p="checked"
                if "Training Room" in pt:
                        p_type_t="checked"
                if "Meeting_Room" in pt:
                        p_type_m="checked"
                if "Event_Hall" in pt:
                        p_type_e="checked"

                if 'Plug & Play' in typ_list:
                         my_val_plug = "Plug & Play"
                         print "pppp",my_val_plug
                else:
                         my_val_plug = "none"
                         print "pppp",my_val_plug

                if "Training Room" in typ_list:
                         my_val_Training = "Training Room"
                else:
                         my_val_Training = "none"
                if "Event_Hall" in typ_list:
                         my_val_event = "Event_Hall"
                else:
                         my_val_event = "none"

                if "Meeting_Room" in typ_list:
                         my_val_meeting = "Meeting_Room"
                         print "meeting room--->",my_val_meeting
                else:
                         my_val_meeting = "none"
                         print "meeting room--->",my_val_meeting

	

	
	
       	new_cur_typlist=",".join(typ_list)
	prop_status=request.POST["status"]
	default=request.POST["default"]
	sub_type=request.POST["sub_type"]
	try:
                super_sub_type=request.POST["super_sub_type"]
        except:
                super_sub_type=""
	start_time=request.POST["str_time"]
	end_time=request.POST["end_time"]
        description=request.POST["description"]
	offer=request.POST["offer"]
	try:
                holiday_value=request.POST["holi"]
                final_holiday_value=datetime.datetime.strptime(holiday_value, '%Y-%m-%d').strftime('%d/%m/%Y')
        except:
                holiday_value=""
                final_holiday_value=""
        
        try:
                non_working_days1=request.POST.getlist("non_work[]")
                non_working_days=",".join(non_working_days1)
                print "non working days--->",non_working_days
        except:
                non_working_days=""
	#try:
	upimages=request.FILES.getlist('new_images')
	#except:
	#	up_images=0
	#upimages = 'new_images' in request.POST and request.POST['new_images']
	print "up images...................",upimages
	sub_id1=0
	data_sub = Property_Details.objects.all()
	for s in data_sub:
		sub_id1=s.submitted_by_id
	subid=sub_id1+1

	own_id1=0
	data_own = Property_Details.objects.all()
	for o in data_own:
		own_id1=s.Owner_id
	ownid=own_id1+1	

	my_id1=0
	data1 = Property_Details.objects.all()
	for i in data1:
		my_id1=i.property_id
	myid=my_id1+1


	if upimages:
	      print "in this code..............."
	      cur_pathlist=[]
              path=upload_image(upimages,myid)

              print "path",path
              print "\n\n path_of_image :",path,type(path)
              for link in path:
                     tmp_path1 = link.split("/")
                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                     print "temp path1 :",cur_path1
                     cur_pathlist.append(cur_path1)
              new_cur_pathlist=",".join(cur_pathlist)
              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
              print "aasd",new_cur_pathlist

	data=Property_Details(property_id=myid,status=prop_status,property_super_subtype=super_sub_type,
                              property_subtype=str(sub_type),default_type=str(default),
                              description=description,offer=offer,property_type=new_cur_typlist,
                              property_name=prop_name,address=address,starting_price=price,
                              operating_strattime=start_time,operating_stoptime=end_time,timestamp=time,
                              submitted_by=user,
                              latitude=lat,longitude=lon,location=loc,new_latitude=lat_cut,
                              new_longitude=lon_cut,Owner_id=ownid,submitted_by_id=subid,images=new_cur_pathlist)

	data.save()

	holiday=Holidays(property_id=myid,holidays=final_holiday_value)
        holiday.save()
        not_working_days=Non_Working_Days(property_id=myid,Non_Working_days=non_working_days)
        not_working_days.save()
	return render_to_response('nextpage.html',{"user":user,"password":password,"super_sub_type":super_sub_type,
                                                   "my_val_event":my_val_event,"my_val_plug" : my_val_plug,
                                                   "my_val_Training":my_val_Training,"my_val_meeting":my_val_meeting,
                                                   "myid":myid})



@csrf_exempt
def Save_property_next(request):
	print "Iam in..."
	new_cur_pathlist=[]
	new_cur_pathlist1=[]
	new_cur_pathlist12=[]
	new_cur_pathlist123=[]
	book_property_type=""

	user=request.POST["user"]
        password=request.POST["Password"]
	print "user........",user
	
	try:
                my_val_plug=str(request.POST['my_val_plug'])
                print "my_val_plug",my_val_plug
	except:
                my_val_plug=""
	try:
                my_val_meeting=str(request.POST['my_val_meeting'])
                print "my_val_meeting",my_val_meeting
	except:
                my_val_meeting=""

        try:
                my_val_event=str(request.POST['my_val_event'])
                print "my_val_event",my_val_event
	except:
                my_val_event=""

        try:
                my_val_Training=str(request.POST['my_val_Training'])
                print "my_val_Training",my_val_Training
	except:
                my_val_Training=""
                
        prop_id=request.POST['prop_id']
	print "property id.........",prop_id

        book=Booking_Type()
        book.property_id=prop_id
        book_type=[]
	if(my_val_plug):

                try:
                        super_sub_type=request.POST["super_sub_type"]
                except:
                        super_sub_type=""

                if(super_sub_type == "Pvt_Ofc"):

                        room_no=0
                        try:
                                total_row=int(request.POST["val_pvt"])
                                print "total row...",total_row
                                tot_row=total_row+1
                                print "tot_row",tot_row
                        except:
                                total_row=0
                        
                        if(total_row):

                                try:
                                        shared_capacity=request.POST["capacity1_pvt"]
                                        print "my capacity...",shared_capacity
                                        if(shared_capacity):
                                                print"am here"
                                        else:
                                                shared_capacity=0

                                except:
                                        
                                        shared_capacity=0

                                try:	
                                        shared_monthly=request.POST["rate_month_pvt"]
                                        book_type.append("Monthly")
                                        book_property_type="Plug & Play"
                                except:
                                        shared_monthly=0

                                sh_images=request.FILES.getlist('shared_img_pvt')
                                print "shared.................",sh_images

                                if sh_images:
                                      print "in this code..............."
                                      cur_pathlist=[]
                                      path1=upload_image(sh_images,prop_id)

                                      print "path",path1
                                      print "\n\n path_of_image :",path1,type(path1)
                                      for link in path1:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist.append(cur_path1)
                                      new_cur_pathlist=",".join(cur_pathlist)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                                      print "aasd",new_cur_pathlist
                                if(shared_capacity > 0):
                                        data=Shared_area(property_id=prop_id,pvt_ofc_no=1,capacity=shared_capacity,rate_monthly=shared_monthly,shared_images=new_cur_pathlist)

                                        data.save()
                                count=2
                                for i in range(1,int(tot_row)):
                                        print "iam in range.."
                                        new_room_no=int(i+1)
                                        capacity_val="capacity_monthly_"+str(i)
                                        weekly_val="rate_monthly_"+str(i)
                                        image_val="shared_img_pvt_"+str(i)
                                
                                        try:
                                                new_shared_capacity=int(request.POST[capacity_val])
                                                print "new_capa...",new_shared_capacity
                                        except:
                                                new_shared_capacity=0
                                                print "new_capa...",new_shared_capacity

                                        try:
                                                new_shared_monthly=request.POST[weekly_val]
                                                print "new_weekly",new_shared_monthly
                                        except:
                                                new_shared_monthly=0

                                        try:
                                                new_sh_img=request.FILES.getlist(image_val)
                                        except:
                                                new_sh_img=0
                                        
                                        new_cur_pathlist11=""
                                        if new_sh_img:
                                              print "in this code..............."
                                              cur_pathlist11=[]
                                              path2=upload_image(new_sh_img,prop_id)

                                              print "path",path2
                                              print "\n\n path_of_image :",path2,type(path2)
                                              for link in path2:
                                                     tmp_path1 = link.split("/")
                                                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                                     print "temp path1 :",cur_path1
                                                     cur_pathlist11.append(cur_path1)
                                              new_cur_pathlist11=",".join(cur_pathlist11)
                                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                              print "aasd",new_cur_pathlist11
                                        
                                        if(new_shared_capacity > 0):
                                                new_room_no1=count
                                                new_data1=Shared_area(property_id=prop_id,capacity=new_shared_capacity,
                                                                      pvt_ofc_no=new_room_no1,
                                                                      rate_monthly=new_shared_monthly,
                                                                      shared_images=new_cur_pathlist)

                                                new_data1.save()
                                                cont=count+1

                        else:

                                try:
                                        shared_capacity=request.POST["capacity1_pvt"]
                                        print "my capacity...",shared_capacity
                                        if(shared_capacity):
                                                print"am here"
                                        else:
                                                shared_capacity=0

                                except:
                                        
                                        shared_capacity=0

                                try:	
                                        shared_monthly=request.POST["rate_month_pvt"]
                                        book_type.append("Monthly")
                                        book_property_type="Plug & Play"
                                except:
                                        shared_monthly=0

                                sh_images=request.FILES.getlist('shared_img_pvt')
                                print "shared.................",sh_images

                                if sh_images:
                                      print "in this code..............."
                                      cur_pathlist=[]
                                      path1=upload_image(sh_images,prop_id)

                                      print "path",path1
                                      print "\n\n path_of_image :",path1,type(path1)
                                      for link in path1:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist.append(cur_path1)
                                      new_cur_pathlist=",".join(cur_pathlist)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                                      print "aasd",new_cur_pathlist
                                if(shared_capacity > 0):
                                        data=Shared_area(property_id=prop_id,pvt_ofc_no=1,capacity=shared_capacity,rate_monthly=shared_monthly,shared_images=new_cur_pathlist)

                                        data.save()

                        

                else:

                        try:
                                shared_capacity=request.POST["capacity1"]
                                print "my capacity...",shared_capacity
                                if(shared_capacity):
                                        print"am here"
                                else:
                                        shared_capacity=0

                        except:
                                
                                shared_capacity=0

                        try:
                                shared_hr=request.POST["rate_hr"]
                                book_type.append("Hourly")
                                book_property_type="Plug & Play"
                        except:
                                shared_hr=0
                        try:
                                shared_daily=request.POST["rate_daily"]
                                book_type.append("Daily")
                                book_property_type="Plug & Play"
                        except:
                                shared_daily=0
                        try:	
                                shared_weekly=request.POST["rate_week"]
                                book_type.append("Weekly")
                                book_property_type="Plug & Play"
                        except:
                                shared_weekly=0
                        try:	
                                shared_monthly=request.POST["rate_month"]
                                book_type.append("Monthly")
                                book_property_type="Plug & Play"
                        except:
                                shared_monthly=0

                        if(shared_hr==""):
                                shared_hr=0
                        if(shared_daily==""):
                                shared_daily=0
                        if(shared_weekly==""):
                                shared_weekly=0
                        if(shared_monthly==""):
                                shared_monthly=0
                        sh_images=request.FILES.getlist('shared_img')
                        print "shared.................",sh_images

                        
                        '''my_id1=0
                        data1 = Shared_area.objects.all()
                        for i in data1:
                                my_id1=i.property_id
                        myid=my_id1+1'''

                        if sh_images:
                              print "in this code..............."
                              cur_pathlist=[]
                              path1=upload_image(sh_images,prop_id)

                              print "path",path1
                              print "\n\n path_of_image :",path1,type(path1)
                              for link in path1:
                                     tmp_path1 = link.split("/")
                                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path1
                                     cur_pathlist.append(cur_path1)
                              new_cur_pathlist=",".join(cur_pathlist)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                              print "aasd",new_cur_pathlist
                        if(shared_capacity > 0):
                                data=Shared_area(property_id=prop_id,capacity=shared_capacity,rate_hr=shared_hr,rate_daily=shared_daily,rate_weekly=shared_weekly,rate_monthly=shared_monthly,shared_images=new_cur_pathlist)

                                data.save()


        
        if(my_val_meeting):
                room_no=0
                try:
                        total_row=int(request.POST["val"])
                        print "total row...",total_row
                        tot_row=total_row+1
                        print "tot_row",tot_row
                except:
                        total_row=0
                
                if(total_row):

                        try:
                                meeting_capacity=request.POST["capacity2"]
                                print "now capacity...",meeting_capacity
                                if(meeting_capacity):
                                        print"am here"
                                else:
                                        meeting_capacity=0
                                
                                room_no1=room_no+1
                                
                        except:
                                
                                meeting_capacity=0
                                
                        print "dxfyghdrfhdfghdgfh"
                        try:
                                meeting_hr=request.POST["rate_hr2"]
                                book_type.append("Hourly")
                                book_property_type="Meeting_Room"
                                print "rate per hr is..",meeting_hr
                                
                        except:
                                meeting_hr=0
                        try:
                                meeting_daily=request.POST["rate_daily2"]
                                book_type.append("Daily")
                                book_property_type="Meeting_Room"
                                print "rate per daily is..",meeting_daily
                        except:
                                meeting_daily=0
                                print "rate per daily is..",meeting_daily
                        try:	
                                meeting_weekly=request.POST["rate_week2"]
                                book_type.append("Weekly")
                                book_property_type="Meeting_Room"
                                print "rate per weekly is..",meeting_weekly
                        except:
                                meeting_weekly=0
                                print "rate per weekly is..",meeting_weekly
                        
                        
                        try:
                                meeting_images=request.FILES.getlist('meeting_img')
                                print "image.........",meeting_images

                        except:

                                meeting_images=0
                        if(meeting_hr==""):
                                meeting_hr=0
                        if(meeting_daily==""):
                                meeting_daily=0
                        if(meeting_weekly==""):
                                meeting_weekly=0
                        if meeting_images:
                              print "in this code..............."
                              cur_pathlist1=[]
                              path2=upload_image(meeting_images,prop_id)

                              print "path",path2
                              print "\n\n path_of_image :",path2,type(path2)
                              for link in path2:
                                     tmp_path1 = link.split("/")
                                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path1
                                     cur_pathlist1.append(cur_path1)
                              new_cur_pathlist1=",".join(cur_pathlist1)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist1,type(new_cur_pathlist1)
                              print "aasd",new_cur_pathlist1
                        print "meet data is..",meeting_hr,meeting_daily,meeting_weekly,new_cur_pathlist1,meeting_capacity
                        if(meeting_capacity > 0):
                                data1=Meeting_room(property_id=prop_id,room_no=1,capacity=meeting_capacity,rate_hr=meeting_hr,rate_daily=meeting_daily,
                                           rate_weekly=meeting_weekly,meeting_room_images=new_cur_pathlist1)

                                data1.save()
                        count=2
                        for i in range(1,int(tot_row)):
                                print "iam in range.."
                                new_room_no=int(i+1)
                                capacity_val="capacity_"+str(i)
                                hr_val="rate_hr_"+str(i)
                                daily_val="rate_daily_"+str(i)
                                weekly_val="rate_week_"+str(i)
                                image_val="meeting_img_"+str(i)
                        
                                try:
                                        new_capa=int(request.POST[capacity_val])
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hrly=request.POST[hr_val]
                                        print "new_hrly",new_hrly
                                except:
                                        new_hrly=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                try:
                                        new_weekly=request.POST[weekly_val]
                                        print "new_weekly",new_weekly
                                except:
                                        new_weekly=0

                                try:
                                        new_meet_img=request.FILES.getlist(image_val)
                                except:
                                        new_meet_img=0
                                if(new_hrly==""):
                                        new_hrly=0
                                if(new_daily==""):
                                        new_daily=0
                                if(new_weekly==""):
                                        new_weekly=0
                                        
                                new_cur_pathlist11=""
                                if new_meet_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_meet_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                print "meet data is..",new_hrly,new_daily,new_weekly,new_cur_pathlist11,new_capa,new_room_no
                                if(new_capa > 0):
                                        new_room_no1=count
                                        new_data1=Meeting_room(property_id=prop_id,room_no=new_room_no1,
                                                       capacity=new_capa,rate_hr=new_hrly,rate_daily=new_daily,
                                           rate_weekly=new_weekly,meeting_room_images=new_cur_pathlist11)

                                        new_data1.save()
                                        count=count+1
                

                else:
                        try:
                                meeting_capacity=request.POST["capacity2"]
                                print "now capacity...",meeting_capacity
                                if(meeting_capacity):
                                        print"am here"
                                else:
                                        meeting_capacity=0
                                
                                room_no1=room_no+1
                                
                        except:
                                
                                meeting_capacity=0
                                
                        print "dxfyghdrfhdfghdgfh"
                        try:
                                meeting_hr=request.POST["rate_hr2"]
                                book_type.append("Hourly")
                                book_property_type="Meeting_Room"
                                print "rate per hr is..",meeting_hr
                                
                        except:
                                meeting_hr=0
                        try:
                                meeting_daily=request.POST["rate_daily2"]
                                book_type.append("Daily")
                                book_property_type="Meeting_Room"
                                print "rate per daily is..",meeting_daily
                        except:
                                meeting_daily=0
                                print "rate per daily is..",meeting_daily
                        try:	
                                meeting_weekly=request.POST["rate_week2"]
                                book_type.append("Weekly")
                                book_property_type="Meeting_Room"
                                print "rate per weekly is..",meeting_weekly
                        except:
                                meeting_weekly=0
                                print "rate per weekly is..",meeting_weekly
                        print"am hererererererererer"
                        #meeting_images=request.FILES.getlist('b2212')	
                        try:
                                meeting_images=request.FILES.getlist('meeting_img')
                                print "image.........",meeting_images

                        except:

                                meeting_images=0

                        if(meeting_hr==""):
                                meeting_hr=0
                        if(meeting_daily==""):
                                meeting_daily=0
                        if(meeting_weekly==""):
                                meeting_weekly=0
                        '''my_id12=0
                        data12 = Meeting_room.objects.all()
                        for i in data12:
                                my_id12=i.property_id
                        myid1=my_id12+1'''

                        if meeting_images:
                              print "in this code..............."
                              cur_pathlist1=[]
                              path2=upload_image(meeting_images,prop_id)

                              print "path",path2
                              print "\n\n path_of_image :",path2,type(path2)
                              for link in path2:
                                     tmp_path1 = link.split("/")
                                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path1
                                     cur_pathlist1.append(cur_path1)
                              new_cur_pathlist1=",".join(cur_pathlist1)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist1,type(new_cur_pathlist1)
                              print "aasd",new_cur_pathlist1
                        print "meet data is..",meeting_hr,meeting_daily,meeting_weekly,new_cur_pathlist1,meeting_capacity
                        if(meeting_capacity > 0):
                                data1=Meeting_room(property_id=prop_id,room_no=1,capacity=meeting_capacity,rate_hr=meeting_hr,rate_daily=meeting_daily,
                                           rate_weekly=meeting_weekly,meeting_room_images=new_cur_pathlist1)

                                data1.save()


        if(my_val_Training):

                room_no=0
                try:
                        total_row=int(request.POST["val_train"])
                        print "total row...",total_row
                        tot_row=total_row+1
                        print "tot_row",tot_row
                except:
                        total_row=0
                
                if(total_row):
                        
                        try:
                                training_capacity=request.POST["capacity7"]
                                print "now capacity...",training_capacity
                                if(training_capacity):
                                        print"am here"
                                else:
                                        training_capacity=0
                                
                                
                                
                        except:
                                
                                training_capacity=0
                                
                        print "dxfyghdrfhdfghdgfh"
                        try:
                                training_hr=request.POST["rate_half7"]
                                book_property_type="Training Room"
                                book_type.append("HalfDay")
                        except:
                                training_hr=0

                        try:
                                training_daily=request.POST["rate_daily7"]
                                book_property_type="Training Room"
                                book_type.append("FullDay")
                        except:
                                training_daily=0
                        try:	
                                training_weekly=request.POST["rate_week7"]
                                book_property_type="Training Room"
                                book_type.append("Weekly")
                        except:
                                training_weekly=0
                        
                        try:
                                training_images=request.FILES.getlist('training_img')

                        except:

                                training_images=0

                        if(training_hr==""):
                                training_hr=0
                        if(training_daily==""):
                                training_daily=0

                        if(training_weekly==""):
                                training_weekly=0

                        if training_images:
                              print "in this code..............."
                              cur_pathlist12=[]
                              path3=upload_image(training_images,prop_id)

                              print "path",path3
                              print "\n\n path_of_image :",path3,type(path3)
                              for link in path3:
                                     tmp_path1 = link.split("/")
                                     cur_path12 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path12
                                     cur_pathlist12.append(cur_path12)
                              new_cur_pathlist12=",".join(cur_pathlist12)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist12,type(new_cur_pathlist12)
                              print "aasd",new_cur_pathlist12

                        if(training_capacity > 0):
                                data123=Training_room(property_id=prop_id,
                                              training_room_no=1,
                                              capacity=training_capacity,
                                              
                                              rate_half_day=training_hr,
                                              rate_full_day=training_daily,
                                              rate_weekly=training_weekly,
                                              rate_monthly=training_weekly,
                                              training_room_images=new_cur_pathlist12)

                                data123.save()
                        count=2
                        for i in range(1,int(tot_row)):
                                print "iam in range.."
                                new_room_no=int(i+1)
                                capacity_val="train_capacity_"+str(i)
                                half_val="train_rate_half_"+str(i)
                                daily_val="train_rate_daily_"+str(i)
                                weekly_val="train_rate_week_"+str(i)
                                image_val="trainin_img_"+str(i)
                        
                                try:
                                        new_capa=request.POST[capacity_val]
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hralf=request.POST[half_val]
                                        print "new_hrly",new_hrly
                                except:
                                        new_hralf=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                try:
                                        new_weekly=request.POST[weekly_val]
                                        print "new_daily",new_daily
                                except:
                                        new_weekly=0

                                try:
                                        new_train_img=request.FILES.getlist(image_val)
                                except:
                                        new_train_img=0
                                if(new_hralf==""):
                                        new_hralf=0
                                if(new_daily==""):
                                        new_daily=0

                                if(new_weekly==""):
                                        new_weekly=0
                                
                                        
                                new_cur_pathlist11=""
                                if new_train_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_train_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                print "meet data is..",new_hralf,new_daily,new_weekly,new_cur_pathlist11,new_capa,new_room_no

                                if(new_capa > 0):
                                        new_room_no1=count
                                        data123=Training_room(property_id=prop_id,
                                              training_room_no=new_room_no1,
                                              capacity=new_capa,
                                              
                                              rate_half_day=new_hralf,
                                              rate_full_day=new_daily,
                                              rate_weekly=new_weekly,
                                              rate_monthly=new_weekly,
                                              training_room_images=new_cur_pathlist11)

                                        data123.save()
                                        count=count+1

                else:

                        try:
                                training_capacity=request.POST["capacity7"]
                                print "now capacity...",training_capacity
                                if(training_capacity):
                                        print"am here"
                                else:
                                        training_capacity=0
                                
                                
                                
                        except:
                                
                                training_capacity=0
                                
                        print "dxfyghdrfhdfghdgfh"
                        try:
                                training_hr=request.POST["rate_half7"]
                                book_property_type="Training Room"
                                book_type.append("HalfDay")
                        except:
                                training_hr=0

                        try:
                                training_daily=request.POST["rate_daily7"]
                                book_property_type="Training Room"
                                book_type.append("FullDay")
                        except:
                                training_daily=0
                        try:	
                                training_weekly=request.POST["rate_week7"]
                                book_property_type="Training Room"
                                book_type.append("Weekly")
                        except:
                                training_weekly=0
                        
                        try:
                                training_images=request.FILES.getlist('training_img')

                        except:

                                training_images=0

                        
                        if(training_hr==""):
                                training_hr=0
                        if(training_daily==""):
                                training_daily=0

                        if(training_weekly==""):
                                training_weekly=0
                                
                        if training_images:
                              print "in this code..............."
                              cur_pathlist12=[]
                              path3=upload_image(training_images,prop_id)

                              print "path",path3
                              print "\n\n path_of_image :",path3,type(path3)
                              for link in path3:
                                     tmp_path1 = link.split("/")
                                     cur_path12 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path12
                                     cur_pathlist12.append(cur_path12)
                              new_cur_pathlist12=",".join(cur_pathlist12)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist12,type(new_cur_pathlist12)
                              print "aasd",new_cur_pathlist12

                        if(training_capacity > 0):
                                data123=Training_room(property_id=prop_id,
                                              training_room_no=1,
                                              capacity=training_capacity,
                                              
                                              rate_half_day=training_hr,
                                              rate_full_day=training_daily,
                                              rate_weekly=training_weekly,
                                              rate_monthly=training_weekly,
                                              training_room_images=new_cur_pathlist12)

                                data123.save()


        if(my_val_event):

                room_no=0
                try:
                        total_row=int(request.POST["val_event"])
                        print "total row...",total_row
                        tot_row=total_row+1
                        print "tot_row",tot_row
                except:
                        total_row=0
                
                if(total_row):
                        
                        try:
                                event_capacity=request.POST["capacity12"]
                                print "my capacity...",event_capacity
                                if(event_capacity):
                                        print"am here"
                                else:
                                        event_capacity=0

                        except:
                                
                                event_capacity=0

                        try:
                                event_hr=request.POST["rate_half12"]
                                book_type.append("HalfDay")
                                book_property_type="Event_Hall"
                        except:
                                event_hr=0
                        try:
                                event_daily=request.POST["rate_daily12"]
                                book_type.append("FullDay")
                                book_property_type="Event_Hall"
                        except:
                                event_daily=0
                        
                        try:
                                event_images=request.FILES.getlist('event_img')

                        except:

                                event_images=0
                        if(event_hr==""):
                                event_hr=0
                        if(event_daily==""):
                                event_daily=0

                        if event_images:
                              print "in this code..............."
                              cur_pathlist123=[]
                              path4=upload_image(event_images,prop_id)

                              print "path",path4
                              print "\n\n path_of_image :",path4,type(path4)
                              for link in path4:
                                     tmp_path1 = link.split("/")
                                     cur_path123 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path123
                                     cur_pathlist123.append(cur_path123)
                              new_cur_pathlist123=",".join(cur_pathlist123)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist123,type(new_cur_pathlist123)
                              print "aasd",new_cur_pathlist123

                        if(total_row > 0):
                                event_room_no=room_no+1
                                data01=Event_Halls(property_id=prop_id,
                                           capacity=event_capacity,
                                           rate_halfday=event_hr,
                                           rate_daily=event_daily,room_no=event_room_no,
                                           shared_images=new_cur_pathlist123)

                                data01.save()
                        count=2
                        for i in range(1,int(tot_row)):
                                print "iam in range.."
                                new_room_no=int(i+1)
                                capacity_val="event_capacity_"+str(i)
                                half_val="event_rate_half_"+str(i)
                                daily_val="event_rate_daily_"+str(i)
                                image_val="event_img_"+str(i)
                        
                                try:
                                        new_capa=int(request.POST[capacity_val])
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hralf=request.POST[half_val]
                                        print "new_hralf",new_hralf
                                except:
                                        new_hralf=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                try:
                                        new_event_img=request.FILES.getlist(image_val)
                                except:
                                        new_event_img=0
                                if(new_hralf==""):
                                        new_hralf=0
                                if(new_daily==""):
                                        new_daily=0
                                
                                        
                                new_cur_pathlist11=""
                                if new_event_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_event_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                print "meet data is..",new_hralf,new_daily,new_cur_pathlist11,new_capa,new_room_no

                                if(new_capa > 0):
                                        new_room_no1=count
                                        data01=Event_Halls(property_id=prop_id,room_no=new_room_no1,
                                           capacity=new_capa,
                                           rate_halfday=new_hralf,
                                           rate_daily=new_daily,
                                           shared_images=new_cur_pathlist11)

                                        data01.save()
                                        count=count+1

                else:

                        room_no=0
                
                        try:
                                event_capacity=request.POST["capacity12"]
                                print "my capacity...",event_capacity
                                if(event_capacity):
                                        print"am here"
                                else:
                                        event_capacity=0

                        except:
                                
                                event_capacity=0

                        try:
                                event_hr=request.POST["rate_half12"]
                                book_type.append("HalfDay")
                                book_property_type="Event_Hall"
                        except:
                                event_hr=0
                        try:
                                event_daily=request.POST["rate_daily12"]
                                book_type.append("FullDay")
                                book_property_type="Event_Hall"
                        except:
                                event_daily=0
                                
                        try:
                                event_images=request.FILES.getlist('event_img')

                        except:

                                event_images=0

                        if(event_hr==""):
                                event_hr=0
                        if(event_daily==""):
                                event_daily=0
                                
                        if event_images:
                              print "in this code..............."
                              cur_pathlist123=[]
                              path4=upload_image(event_images,prop_id)

                              print "path",path4
                              print "\n\n path_of_image :",path4,type(path4)
                              for link in path4:
                                     tmp_path1 = link.split("/")
                                     cur_path123 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                     print "temp path1 :",cur_path123
                                     cur_pathlist123.append(cur_path123)
                              new_cur_pathlist123=",".join(cur_pathlist123)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist123,type(new_cur_pathlist123)
                              print "aasd",new_cur_pathlist123


                        if(event_capacity > 0):
                                event_room_no=room_no+1
                                data01=Event_Halls(property_id=prop_id,
                                           capacity=event_capacity,
                                           rate_halfday=event_hr,
                                           rate_daily=event_daily,room_no=event_room_no,
                                           shared_images=new_cur_pathlist123)

                                data01.save()
                                
        book_type=list(set(book_type))
        b_typ=','.join(book_type)
        book.book_type=b_typ
        book.property_type=book_property_type
        book.save()
        book_type=[]
	return render_to_response('facility.html',{"user":user,"password":password,"prop_id":prop_id})


@csrf_exempt
def Save_data(request):

	prop_id=request.POST["prop_id"]
	print "prop.....id...",prop_id
	user=request.POST["user"]
        password=request.POST["Password"]
	print "user........",user
	try:

              wifi=request.POST["full_deal"]
              print "wifiiiiiiiiiiiiiiii",wifi
       	except:
              wifi=0

	print "wifiiiiiiiiiiiiiiii",wifi

	try:

              coffe=request.POST["coffe"]
              print "coffeeeeeeeeeeeeee",coffe
       	except:
              coffe=0
	print "coffeeeeeeeeeeee",coffe

	try:

              water=request.POST["water"]
              print "wateeeeeeeeeeeeeeeeer",water
       	except:
              water=0
	
	print "wateeeeeeeeeeeeeeeeer",water

	try:

              printer=request.POST["printer"]
              print "printer**************************************************************", printer
       	except:
              printer=0
	print "printer**************************************************************", printer


	try:

              charging=request.POST["charging"]
              print "charging1**************************************************************", charging
       	except:
              charging=0
        print "charging2**************************************************************", charging


	try:

              changing=request.POST["changing"]
              print "changing******************", changing
       	except:
              changing=0
	print "changing******************", changing

	try:

              library=request.POST["library"]
              print "library	111111",library
       	except:
              library=0
	print "library	111111",library

	try:

              chair=request.POST["chair"]
	      print "chair	111111",chair
       	except:
              chair=0
	print "chair	111111",chair


	try:
              locker=request.POST["locker"]
              print "locker	111111",locker
       	except:
              locker=0
        print "locker	111111",locker

	try:

              ac=request.POST["ac"]
 	      print "acccc	111111",ac
       	except:
              ac=0
	print "acccc	111111",ac

	try:

              hr_deal=request.POST["hr_deal"]
              print "hr deeal	111111",hr_deal
       	except:
              hr_deal=0
	print "hr deeal	111111",hr_deal

	try:

              half_deal=request.POST["half_deal"]
       	except:
              half_deal=0
	try:

              full_deal=request.POST["full_deal"]
       	except:
              full_deal=0
	try:

              projector=request.POST["projector"]
       	except:
              projector=0

	try:

              screen=request.POST["wifi"]
       	except:
              screen=0
	try:

              pa=request.POST["pa"]
       	except:
              pa=0
	try:

              pc=request.POST["pc"]
       	except:
              pc=0
	
	#********************code by aditya ****************************
	try:

			wifi1=request.POST["full_deal1"]
			print "wifi1 value is............",wifi1
	except:
			wifi1=0
			print "wifi1 value except is............",wifi1
	try:

			  coffe1=request.POST["coffe1"]
	except:
			  coffe1=0
	try:

			  water1=request.POST["water1"]
	except:
			  water1=0
	try:

			  printer1=request.POST["printer1"]
	except:

			  printer1=0
	try:

			  charging1=request.POST["charging1"]
	except:
			  charging1=0
	try:

			  changing1=request.POST["changing1"]
	except:
			  changing1=0
	try:

			  library1=request.POST["library1"]
	except:
			  library1=0
	try:

			  chair1=request.POST["chair1"]
	except:
			  chair1=0
	try:

			  locker1=request.POST["locker1"]
	except:
			  locker1=0
	try:

			  ac1=request.POST["ac1"]
	except:
			  ac1=0
	try:

			  hr_deal1=request.POST["hr_deal1"]
	except:
			  hr_deal1=0
	try:

			  half_deal1=request.POST["half_deal1"]
	except:
			  half_deal1=0
	try:

			  full_deal1=request.POST["full_deal1"]
	except:
			  full_deal1=0
	try:

			  projector1=request.POST["projector1"]
	except:
			  projector1=0
	try:

			  pc1=request.POST["pc1"]
	except:
			  pc1=0
	try:

			  screen1=request.POST["wifi1"]
	except:
			  screen1=0




	#description=request.POST["rate_daily7"]



	'''my_id10=0
	data10 =Property_Facility.objects.all()
	for i in data10:
		my_id10=i.property_id
	myid01=my_id10+1'''

	print "wifi value is",wifi
	print "wifi1 value is",wifi1
	data=Property_Facility(property_id=prop_id)


#********************code by aditya ****************************	
	if(wifi!=0 and wifi1==0):
              data.Wifi=0
              print "free property is selected"
    	elif(wifi==0 and wifi1!=0):
      	      data.Wifi=1
      	      print "paid prop is selected"
    	else:
    		  print "Nothing is selected&&&&&&&&&"
    		  data.wifi="ND"


	if(coffe!=0 and coffe1==0):
              data.Coffee_tea=0
              print "free coffee is selected"
    	elif(coffe==0 and coffe1!=0):
      	      data.Coffee_tea=1
      	      print "paid coffee is selected"
    	else:
    		  print "coffee  is not selected"
    		  data.Coffee_tea="ND"

	if(water!=0 and water1==0):
              data.Water_bottle=0
              print "free water is selected"
    	elif(water==0 and water1!=0):
      	      data.Water_bottle=1
      	      print "paid water is selected"
    	else:
    		  print " water is not selected"
    		  data.Water_bottle="ND"

	if(printer!=0 and printer1==0):
              data.Printer=0
    	elif(printer==0 and printer1!=0):
      	      data.Printer=1
    	else:
    		  data.Printer="ND"


	if(charging!=0 and charging1==0):
              data.Charging_Point=0
    	elif(charging==0 and charging1!=0):
      	      data.Charging_Point=1
    	else:
    		  data.Charging_Point="ND"

	if(changing!=0 and changing1==0):
              data.Changing_room=0
    	elif(changing==0 and changing1!=0):
      	      data.Changing_room=1
    	else:
    		  data.Changing_room="ND"

	if(library!=0 and library1==0):
              data.Library=0
    	elif(library==0 and library1!=0):
      	      data.Library=1
    	else:
    		  data.Library="ND"


	if(chair!=0 and chair1==0):
              data.Massage_chair=0
    	elif(chair==0 and chair1!=0):
      	      data.Massage_chair=1
    	else:
    		  data.Massage_chair="ND"

	if(locker!=0 and locker1==0):
              data.Locker=0
    	elif(locker==0 and locker1!=0):
      	      data.Locker=1
    	else:
    		  data.Locker="ND"



	if(ac!=0 and ac1==0):
              data.AC=0
    	elif(ac==0 and ac1!=0):
      	      data.AC=1
    	else:
    		  data.AC="ND"


	if(hr_deal!=0 and hr_deal1==0):
              data.Seat_up=0
    	elif(hr_deal==0 and hr_deal1!=0):
      	      data.Seat_up=1
    	else:
    		  data.Seat_up="ND"

	if(half_deal!=0 and half_deal1==0):
              data.Stationary=0
    	elif(half_deal==0 and half_deal1!=0):
      	      data.Stationary=1
    	else:
    		  data.Stationary="ND"

	if(full_deal!=0 and full_deal1==0):
              data.Full_day_deal=0
    	elif(full_deal==0 and full_deal1!=0):
      	      data.Full_day_deal=1
    	else:
    		  data.Full_day_deal="ND"
    
	if(projector !=0 and projector1 ==0):
              data.Projector=0
    	elif(projector==0 and projector1!=0):
      	      data.Projector=1
    	else:
    		  data.Projector="ND"

	if(screen !=0 and screen1 ==0):
              data. Projection_screen=0
    	elif(screen==0 and screen1!=0):
      	      data. Projection_screen=1
    	else:
    		  data.Projection_screen="ND"


	if(pc!=0 and pc1==0):
              data.PC_or_Laptop=0
    	elif(pc==0 and pc1!=0):
      	      data.PC_or_Laptop=1
    	else:
    		  data.PC_or_Laptop="ND"

	

	data.save()
	msg="Property data saved.."
	data=Property_Details.objects.filter(submitted_by=user).order_by('property_id')
	

        result=[]
        result1=[]
        first=[]
        names=[]
        print "am here"
        res="Ascending"
        res1="None"
        #print "sdafsdfdsfsdf",request.POST['desc']

        for i in data:
			first.append(i.property_id)
			
		        temp = int(i.property_id)
		        names.append(i.property_name)
		       
		        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
		        first.append(i.property_name)
		        address=i.address
			first.append(i.address)
			result.append(first)
			first=[]
	       #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"user":user,"password":password,"property":result})

@csrf_exempt
def login(request):
       response = render_to_response('login.html',{})
       #u_name=request.COOKIES.get('usr_name')
       response.delete_cookie('logged_in_liveup_status')
       #print u_name
       return response


@csrf_exempt
def property_page(request):

       print "am in............"
       data=Property_Details.objects.all().order_by('property_id')

       result=[]
       result1=[]
       first=[]
       names=[]
       print "am here"
       res="Ascending"
       res1="None"
      #print "sdafsdfdsfsdf",request.POST['desc']

       for i in data:
		first.append(i.property_id)
                temp = int(i.property_id)
                names.append(i.property_name)
                names.sort()
                #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                first.append(i.property_name)
                address=i.address
		first.append(address)
		result.append(first)

		

       return render_to_response('my_property.html',{"property":result})



@csrf_exempt
def display_homepage(request):

        owner=request.POST["owner"]
        print "ownerrrrr",owner

	if(owner=="Owner"):
            print "Iam in ownerrrrrrrrr"
            try:
                   
                   username_new = str(request.POST["Username"])
                   password = request.POST["Password"]
            

            except:
                   msg = "Username not found Please Sign Up!"
        ##           return render_to_response("login.html",{'flag':msg})
                   

            try:
                username=username_new.lower()
                instance = Login.objects.get(email_id = username).password
                if password == instance:
                       print "am in............"
                       
##                       return render_to_response('secondpage.html',{})
                       data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')

                       result=[]
                       result1=[]
                       first=[]
                       names=[]
                       comment=[]
                       comm=[]
                       rate=[]
                       print "am here"
                       res="Ascending"
                       res1="None"
                      #print "sdafsdfdsfsdf",request.POST['desc']

                       for i in data:
                                first.append(i.property_id)
                                
                                temp = int(i.property_id)
                                names.append(i.property_name)
                               
                                print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",i.property_name
                                first.append(i.property_name)
                                address=i.address
                                first.append(i.address)
                                comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                                if(comm_data):
                                        for c in comm_data:
                                                comment.append(c.comment)
                                                rate.append(c.rate)
                                else:
                                        comment.append("No comments..")
                                        rate.append(" ")
                                first.append(comment)
                                comm.append(comment)
                                count=0
                                new_rate=0
                                print "rate",rate
                                if(rate != [' ']):
                                        for r in rate:
                                               print "i",r
                                               new_rate=new_rate+float(r)
                                               count=count+1
                                        avg_rate=new_rate/float(count)
                                        print "avg_rate...",avg_rate
                                else:
                                        avg_rate=0
                                
                                first.append(avg_rate)
                                val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                                first.append(val)
                                result.append(first)
                                first=[]
                                comment=[]
                                rate=[]
                       for cc in comm:
                               if(cc != "No comments.."):
                                      comm=cc
                                      break
                               else:
                                      comm=" "
                       print "comments...",comm
                       
                       #print"result adsfasdfadsfasdfasdf",result  
                       return render_to_response('my_property.html',{"property":result,"owner":owner,"user":username,"comments":comm,"password":password})
                        
                       response.set_cookie('logged_in_liveup_status', username)
                       return response
                else:
                    msg = "Password is Invalid!!"
                    return render_to_response("login.html",{'flag':msg})
            except :
                msg = "Username not found.Please Sign Up!"
                return render_to_response("login.html",{'flag':msg})		

        elif(owner == "Super-Owner"):
                print "Iam in super owner"
                try:
                   
                   username_new = str(request.POST["Username"])
                   password = request.POST["Password"]


                except:
                   msg = "Username not found Please Sign Up!"
                ##           return render_to_response("login.html",{'flag':msg})
                   

                try:
                        username=username_new.lower()
                        instance = Sign_Up.objects.get(username = username).password
                        if password == instance:
                               print "am in............"
                               
                        ##                       return render_to_response('secondpage.html',{})
                               data=Property_Details.objects.all().order_by('property_id')

                               result=[]
                               result1=[]
                               first=[]
                               names=[]
                               comment=[]
                               comm=[]
                               rate=[]
                               print "am here"
                               res="Ascending"
                               res1="None"
                              #print "sdafsdfdsfsdf",request.POST['desc']

                               for i in data:
                                        first.append(i.property_id)
                                        
                                        temp = int(i.property_id)
                                        names.append(i.property_name)
                                       
                                        print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",i.property_name
                                        first.append(i.property_name)
                                        address=i.address
                                        first.append(i.address)
                                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                                        if(comm_data):
                                                for c in comm_data:
                                                        comment.append(c.comment)
                                                        rate.append(c.rate)
                                        else:
                                                comment.append("No comments..")
                                                rate.append(" ")
                                        first.append(comment)
                                        comm.append(comment)
                                        count=0
                                        new_rate=0
                                        print "rate",rate
                                        if(rate != [' ']):
                                                for r in rate:
                                                       print "i",r
                                                       new_rate=new_rate+float(r)
                                                       count=count+1
                                                avg_rate=new_rate/float(count)
                                                print "avg_rate...",avg_rate
                                        else:
                                                avg_rate=0
                                        
                                        first.append(avg_rate)
                                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                                        first.append(val)
                                        result.append(first)
                                        first=[]
                                        comment=[]
                                        rate=[]
                               for cc in comm:
                                       if(cc != "No comments.."):
                                              comm=cc
                                              break
                                       else:
                                              comm=" "
                               print "comments...",comm
                               
                               #print"result adsfasdfadsfasdfasdf",result  
                               return render_to_response('my_property.html',{"property":result,"owner":owner,"user":username,"comments":comm,"password":password})
                                
                               response.set_cookie('logged_in_liveup_status', username)
                               return response
                        else:
                            msg = "Password is Invalid!!"
                            return render_to_response("login.html",{'flag':msg})
                except :
                        msg = "Username not found.Please Sign Up!"
                        return render_to_response("login.html",{'flag':msg})
                
	else:
            print "in else "
	    try:
	        
                username_new = str(request.POST["Username"])
                password = str(request.POST["Password"])
            except:
                   msg = "Username not found Please Sign Up!"

	    username=username_new.lower()
            print "both the values of the username and password ",username,password
            data=Property_Details.objects.all().order_by('property_id')
            print "the ordered value of the property details ",data.count()
            result=[]
            result1=[]
            first=[]
            names=[]
            comment=[]
            comm=[]
            rate=[]
            print "am here"
            res="Ascending"
            res1="None"

            for i in data:
                first.append(i.property_id)
                
                temp = int(i.property_id)
                names.append(str(i.property_name))
               
                print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",i.property_name,type(str(i.property_name))
                print "names...",names
                first.append(i.property_name)
                address=i.address
                first.append(i.address)
                comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                if(comm_data):
                        for c in comm_data:
                                comment.append(c.comment)
                                rate.append(c.rate)
                else:
                        comment.append("No comments..")
                        rate.append(" ")
                first.append(comment)
                comm.append(comment)
                count=0
                new_rate=0
                print "rate",rate
                if(rate != [' ']):
                        for r in rate:
                               print "i",r
                               new_rate=new_rate+float(r)
                               count=count+1
                        avg_rate=new_rate/float(count)
                        print "avg_rate...",avg_rate
                else:
                        avg_rate=0
                
                first.append(avg_rate)
                val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                first.append(val)
                result.append(first)
                first=[]
                comment=[]
                rate=[]
            for cc in comm:
               if(cc != "No comments.."):
                      comm=cc
                      break
               else:
                      comm=" "
            print "comments...",comm

            return render_to_response('my_property.html',{"property":result,"owner":"Owner","user":username,"comments":comm,"password":password})

            
##                if(comm_data):
##                	for c in comm_data:
##                        	comment.append(c.comment)
##                                rate.append(c.rate)
##                else:
##                        rate=0
##                        if(rate != 0):
##                            pass
##                        else:
##                            avg_rate=0
##                                
##                            first.append(avg_rate)
##                            val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
##                            first.append(val)
##                            result.append(first)
##                            first=[]
##                            comment=[]
##                            rate=[]
##                        for cc in comm:
##                            if(cc != "No comments.."):
##                                comm=cc
##                                break
##                            else:
##                                comm=" "
##                        print "comments...",comm
                       
            #print"result adsfasdfadsfasdfasdf",result.count()
            

@csrf_exempt
def signup_data(request):
    print "In sign up data"
    username_new=str(request.POST["username"])
    firstname=request.POST["firstname"]
    lastname=request.POST["lastname"]
    mobilenumber=request.POST["mobilenumber"]
    password=request.POST["password"]
    confirmpassword=request.POST["confirm_pass"]
    admin_pass = request.POST["admin_pass"]
    typeofuser = str(request.POST["default"])
    print typeofuser
    username=username_new.lower()
    if password != confirmpassword:
        msg="Password don't match!"
        return render(request,'signup.html',{'flag':msg,"username":username,"firstname":firstname,"lastname":lastname,"mobilenumber":mobilenumber,"password":password,
                                             "confirm_pass":confirmpassword,"admin_pass":admin_pass})
    elif password != confirmpassword and len(mobilenumber)!= 10:
        msg= "Password don't match! And also mobilenumber should be 10 digits only!"
        return render(request,'signup.html',{'flag':msg,"username":username,"firstname":firstname,"lastname":lastname,"mobilenumber":mobilenumber,"password":password,
                                             "confirm_pass":confirmpassword,"admin_pass":admin_pass})
    elif len(mobilenumber)!= 10:
        msg = "Mobile number isn't 10 digits!"
        return render(request,'signup.html',{'flag':msg,"username":username,"firstname":firstname,"lastname":lastname,"mobilenumber":mobilenumber,"password":password,
                                             "confirm_pass":confirmpassword,"admin_pass":admin_pass})
    elif admin_pass != "brisa_admin":
        msg = "Admin password Error!"
        return render(request,'signup.html',{'flag':msg,"username":username,"firstname":firstname,"lastname":lastname,"mobilenumber":mobilenumber,"password":password,
                                             "confirm_pass":confirmpassword,"admin_pass":admin_pass})
    elif (Sign_Up.objects.filter(username = username).exists()) or (Login.objects.filter(email_id=username).exists()):
        msg = "Username Already exists! Please log in or request for new password"
        return render_to_response("login.html",{'flag':msg})

    else:
        from_mail = "hr@brisa-tech.com"
        TO = username
        message = "Dear "+firstname+" "+lastname+",\n"+"Your account has been created successfully in Grihhpravesh with following credentials.\n"+"Username :"+username+"\n"+"Password :"+password+"\n"+"Please log in with your new credentials"

        if(typeofuser == "owner"):
                data=Login()
                
                my_id1=0
                data1 = Login.objects.all()
                for i in data1:
                        my_id1=i.user_id
                myid=my_id1+1

                data.user_id=myid
                data.email_id=username
                data.user_password=mobilenumber
                data.user_type=typeofuser
                data.password=password
                data.user_name=firstname
                data.save()
        else:
                obj = Sign_Up(username=username,firstname=firstname,lastname=lastname,mobilenumber=mobilenumber,password=password,type_of_user=typeofuser)
                obj.save()
        msg = "Account successfully created. Please login!"
        return render(request,'login.html',{'flag':msg})


@csrf_exempt
def sign_up(request):
       return render_to_response('signup.html',{})

@csrf_exempt
def owner_details(request):

       owner=Login.objects.all()
       result=[]
       result1=[]
       first=[]
       
       print "am here"
       res="Ascending"
       res1="None"
      #print "sdafsdfdsfsdf",request.POST['desc']

       for i in owner:
                first.append(i.user_id)
                
                temp = int(i.user_id)
                names=(i.email_id)
                first.append(i.email_id)
                first.append(i.user_password)
                data=Property_Details.objects.filter(submitted_by=names)
                if(data):
                        count=Property_Details.objects.filter(submitted_by=names).count()
                else:
                        count=0
                first.append(count)

                result.append(first)
                first=[]

       return render_to_response('owner_details.html',{"property":result})


@csrf_exempt
def book_details(request):
        prop_id=request.POST["newID"]
        data=Booking_Master_Table.objects.filter(property_id=prop_id)
        result=[]
        result1=[]
        first=[]
        names=[]
        if(data):
                for d in data:
                        email_id=d.booked_by_id
                        booking_id=d.booking_id
                        booking_type=d.booking_type
                        property_type=d.property_type
                        
                        log_data=Login.objects.get(user_id=email_id)
                        if(log_data):
                                email=log_data.email_id
                                
                                phn_number=log_data.user_password
                        else:
                                phn_number=0
                        first.append(email)
                        first.append(booking_id)
                        first.append(booking_type)
                        first.append(property_type)
                        first.append(phn_number)
                        result.append(first)
                        first=[]
        return render_to_response('book_details.html',{"result":result})
@csrf_exempt
def check_comments(request):
        prop_id=request.POST["newID"]
        username=str(request.POST["user"])
        password=request.POST["password"]
        print "username............",username
        data=Submit_Comment.objects.filter(property_id=prop_id)
        result=[]
        result1=[]
        first=[]
        email_id=[]
        if(data):
                for d in data:
                        prop_id=d.property_id
                        new_data=Property_Details.objects.filter(property_id=prop_id)
                        for n in new_data:
                                property_name=str(n.property_name)
                        name=d.email_id
                        comment=d.comment
                        rate=d.rate
                        first.append(property_name)
                        first.append(name)
                        first.append(comment)
                        first.append(rate)
                        result.append(first)
                        first=[]
        data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(username in email_id):
                owner="Owner"
        else:
                owner="Super_owner"
        print owner
        return render_to_response('comment_details.html',{"result":result,"owner":owner,"user":username,"password":password})

        
@csrf_exempt
def click_details(request):

       owner_id=int(request.POST["newID"])
       print "iddddddddd",owner_id
       result=[]
       result1=[]
       first=[]
       names=[]
       comm=" "
       print "Haiiiiiiiiiiiiiiiiiiiiiii"
       data=Login.objects.filter(user_id=owner_id)
       if(data):
               print "Helloooooooooo"
               for d in data:
                       print "Haiiiiiiiiiiiiiiiiiiiiiii"
                       email=d.email_id
                       print "email...",email
                       
                       new_data=Property_Details.objects.filter(submitted_by=email)
                       if(new_data):
                               print "Iam innnnnnnnnnnnnnnnnnnnnn"
                               
                               for n in new_data:
                                        property_id=n.property_id
                                        data=Property_Details.objects.all().order_by('property_id')
	

                                        result=[]
                                        result1=[]
                                        first=[]
                                        names=[]
                                        comment=[]
                                        comm=[]
                                        rate=[]
                                        print "am here"
                                        res="Ascending"
                                        res1="None"
                                        #print "sdafsdfdsfsdf",request.POST['desc']

                                        

                                        
                                        
                                        for i in data:
                                                first.append(i.property_id)
                                                
                                                temp = int(i.property_id)
                                                names.append(i.property_name)
                                               
                                                #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                                                first.append(i.property_name)
                                                address=i.address
                                                first.append(i.address)
                                                comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                                                if(comm_data):
                                                        for c in comm_data:
                                                                comment.append(c.comment)
                                                                rate.append(c.rate)
                                                else:
                                                        comment.append("No comments..")
                                                        rate.append(" ")
                                                first.append(comment)
                                                comm.append(comment)
                                                count=0
                                                new_rate=0
                                                print "rate",rate
                                                if(rate != [' ']):
                                                        for r in rate:
                                                               print "i",r
                                                               new_rate=new_rate+float(r)
                                                               count=count+1
                                                        avg_rate=new_rate/float(count)
                                                        print "avg_rate...",avg_rate
                                                else:
                                                        avg_rate=0
                                                
                                                first.append(avg_rate)
                                                val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                                                first.append(val)
                                                result.append(first)
                                                first=[]
                                                comment=[]
                                                rate=[]
                                        for cc in comm:
                                               if(cc != "No comments.."):
                                                      comm=cc
                                                      break
                                               else:
                                                      comm=" "
                                        print "comments...",comm

                                        #print"result adsfasdfadsfasdfasdf",result  
       return render_to_response('my_property.html',{"property":result,"comments":comm})

@csrf_exempt
def super_user(request):

       print "Iam in super user........"
       
                       
       return render_to_response('super_user_details.html',{})


@csrf_exempt
def back_page(request):

       print "Iam in super user........"
       
                       
       return render_to_response('secondpage.html',{})

@csrf_exempt
def details_owner(request):
       owner=Login.objects.all()
       result=[]
       result1=[]
       first=[]
       invoice=[]
       
       print "am here"
       res="Ascending"
       res1="None"
      #print "sdafsdfdsfsdf",request.POST['desc']

       for i in owner:
                first.append(i.user_id)
                
                temp = int(i.user_id)
                names=(i.email_id)
                first.append(i.email_id)
                first.append(i.user_password)
                data=Property_Details.objects.filter(submitted_by=names)
                if(data):
                        count=Property_Details.objects.filter(submitted_by=names).count()
                        for d in data:
                            invoice.append(str(d.invoice_no))
                            
                else:
                        count=0
                first.append(count)
                invoice1=','.join(invoice)
                first.append(invoice1)

                result.append(first)
                invoice=[]
                first=[]

       return render_to_response('owner_details_next.html',{"property":result})

@csrf_exempt
def owner_property(request):

       owner_id=request.POST["newID"]
       print "iddddddddd",owner_id
       result=[]
       result1=[]
       first=[]
       names=[]
       print "Haiiiiiiiiiiiiiiiiiiiiiii"
       data=Login.objects.filter(user_id=owner_id)
       if(data):
               print "Helloooooooooo"
               for d in data:
                       print "Haiiiiiiiiiiiiiiiiiiiiiii"
                       email=d.email_id
                       print "email...",email
                       new_data=Property_Details.objects.filter(submitted_by=email)
                       if(new_data):
                               print "Iam innnnnnnnnnnnnnnnnnnnnn"

                               for n in new_data:
                                        first.append(n.property_id)
                                        
                                        temp = int(n.property_id)
                                        names.append(n.property_name)
                                       
                                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                                        first.append(n.property_name)
                                        address=n.address
                                        first.append(n.address)
                                        result.append(first)
                                        first=[]
       
       return render_to_response('my_property_owner.html',{"property":result})

@csrf_exempt
def user_details(request):

        user=Login.objects.filter(user_type="User")
        result=[]
        result1=[]
        first=[]
        names=[]
        if(user):
                for u in user:
                      first.append(u.user_id)
                
                      temp = int(u.user_id)
                      names=(u.email_id)
                      first.append(u.email_id)
                      first.append(u.user_password) 
                      result.append(first)
                      first=[]  

        return render_to_response('user_details.html',{"property":result})

@csrf_exempt
def edit_property(request):
        
	ownerID=request.POST["id_of_owner"]
        print "ownerID",ownerID

        prop_id=request.POST["id_val"]
       	user=request.POST["user"]
	print "iilsaslasdasd",user
	password=request.POST["password"]
	print "iilsaslasdasd",password
	
##        owner=request.POST["id_of_owner"]
        user=request.POST["user"]
	password=request.POST["password"]
	email_id=[]
	data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                owner="Owner"
        else:
                owner="Super_owner"
##	owner="Owner"
        
        prop_id=request.POST["id_val"]
        print "prop_id",prop_id
        non_work1=[]
        non_work=""
        holi=""
        holi1=[]
        super_type=""
        sub_type=""
        default_selected1=""
        default_selected2=""
        default_selected3=""
        default_selected4=""
        rate_halfday_event=0
        rate_daily_event=0
        halfday_event=0
        daily_event=0
        capacity_event=0
        room_no_event=0
        rate_half_day_train=0
        rate_full_day_train=0
        halfday_train=0
        fullday_train=0
        capacity_train=0
        room_no_train=0
        hourly_meet=0
        daily_meet=0
        weekly_meet=0
        rate_hr_meet=0
        rate_daily_meet=0
        rate_weekly_meet=0
        capacity_meet=0
        room_no_meet=0
        rate_hr_plug=0
        hourly_plug=0
        rate_daily_plug=0
        daily_plug=0
        rate_weekly_plug=0
        weekly_plug=0
        rate_monthly_plug=0
        monthly_plug=0
        capacity_plug=0
        daily_plug_data="disabled"
        weekly_plug_data="disabled"
        monthly_plug_data="disabled"
        hourly_data_plug="disabled"
        halfday_train_data="disabled"
        fullday_train_data="disabled"
        hourly_meet_data="disabled"
        daily_meet_data="disabled"
        weekly_meet_data="disabled"
        Start_Up=0
        Coffee_Shop=0
        result_meet=[]
        result_train=[]
        result_event=[]
        first=[]
        wifi=0
        wifi1=0
        ac=0
        ac1=0
        library=0
        library1=0
        printer=0
        printer1=0
        projection=0
        projection1=0
        coffee=0
        coffee1=0
        charging=0
        charging1=0
        chair=0
        seat=0
     	seat1=0
        chair1=0
        projector=0
        projector1=0
        water=0
        water1=0
        changing=0
        changing1=0
        locker=0
        locker1=0
        stationary=0
        stationary1=0
        pc=0
        pc1=0
        train_room_no=0
        plug_img1=[]
        result_month_pp=[]
        p_i=""
        t_i=""
        m_i=""
        e_i=""
        data=Property_Details.objects.filter(property_id=prop_id)
        if(data):
                for d in data:
                        property_name=d.property_name
                        address=d.address
                        loc=d.location
                        lat=d.latitude
                        lon=d.longitude
                        prop_status1=d.status
                        starting_price=d.starting_price
                        offer=d.offer
                        if(prop_status1 == "active" or prop_status1 == "Active"):
                                prop_status="Active"
                                active_selected="selected"
                                inactive_selected=""
                        else:
                                prop_status="In_Active"
                                active_selected=""
                                inactive_selected="selected"
                        print "prop_status......",prop_status
                        description=d.description
                        default=str(d.default_type)
                        if(default == "Plug & Play"):
                                default_selected1="selected"
                        if(default == "Training Room"):
                                default_selected2="selected"
                        if(default == "Event_Hall"):
                                default_selected3="selected"
                        if(default == "Meeting_Room"):
                                default_selected4="selected"
##                        else:
##                                default_selected1=""
##                                default_selected2=""
##                                default_selected3=""
##                                default_selected4=""
                        p_type=d.property_type
						
                        images=d.images
                        main_img=images.split(",")
						
                        p_type1=p_type.split(",")
                        p_type_p=0
                        p_type_t=0
                        p_type_e=0
                        p_type_m=0
                        print "p_type1--->",p_type1
			
                        for pt in p_type1:
                                print "pt in p_type1---->",pt
                                if "Plug & Play" in pt:
                                        p_type_p="checked"
                                if "Training Room" in pt:
                                        p_type_t="checked"
                                if "Meeting_Room" in pt:
                                        p_type_m="checked"
                                if "Event_Hall" in pt:
                                        p_type_e="checked"

                        if 'Plug & Play' in p_type1:
                                my_val_plug = "Plug & Play"
                                print "pppp",my_val_plug
                        else:
                                my_val_plug = "none"
                                print "pppp",my_val_plug

                        if "Training Room" in p_type1:
                                my_val_Training = "Training Room"
                        else:
                                my_val_Training = "none"
                        if "Event_Hall" in p_type1:
                                my_val_event = "Event_Hall"
                        else:
                                my_val_event = "none"

                        if "Meeting_Room" in p_type1:
                                my_val_meeting = "Meeting_Room"
                                print "meeting room--->",my_val_meeting
                        else:
                                my_val_meeting = "none"
                                print "meeting room--->",my_val_meeting

                        
                        start_time=d.operating_strattime
##                        start_time_selected="selected"
                        time=["12:00am","01:00am","02:00am","03:00am","04:00am","05:00am","06:00am","07:00am","08:00am","09:00am","10:00am","11:00am","12:00pm","01:00pm","02:00pm","03:00pm","04:00pm","05:00pm","06:00pm","07:00pm","08:00pm","09:00pm","10:00pm","11:00pm"]
                        start_time_selected=[]
                        for t in time:
                                if(start_time == t):
                        ##		n="_selected"
                                        start_time_selected.append("selected")
                                else:
                        ##		n=t+"_selected"
                                        start_time_selected.append("")
                        print start_time_selected
                                
                        end_time=d.operating_stoptime
                        time1=["12:00pm","01:00pm","02:00pm","03:00pm","04:00pm","05:00pm","06:00pm","07:00pm","08:00pm","09:00pm","10:00pm","11:00pm","12:00am","01:00am","02:00am","03:00am","04:00am","05:00am","06:00am","07:00am","08:00am","09:00am","10:00am","11:00am"]
                        end_time_selected=[]
                        for t in time1:
                                if(end_time == t):
                        ##		n="_selected"
                                        end_time_selected.append("selected")
                                else:
                        ##		n=t+"_selected"
                                        end_time_selected.append("")
                        print end_time_selected
                        non_working=Non_Working_Days.objects.filter(property_id=prop_id)
                        for n in non_working:
                                non_work1.append(n.Non_Working_days)
                                non_work=','.join(non_work1)
                        week_day=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
                        print "week_day........",week_day,type(week_day)
                        nonwork_selected=[]
                        non_week_day1=[]
                        non_week_day=[]
                        for w in week_day:
                                if(w in non_work):
                                        nonwork_selected.append("checked")
                                        non_week_day1.append(w)
                                        non_week_day1.append("checked")
                                        non_week_day.append(non_week_day1)
                                        non_week_day1=[]
                                else:
                                        nonwork_selected.append("")
                                        non_week_day1.append(w)
                                        non_week_day1.append("")
                                        non_week_day.append(non_week_day1)
                                        non_week_day1=[]
                        print "nonwork_selected..........",nonwork_selected
                        print "non_week_day..............",non_week_day
                        holiday=Holidays.objects.filter(property_id=prop_id)
                        for h in holiday:
                                holi1.append(h.holidays)
                                print "holiiiiiiii1",holi1,type(holi1)
                                holi=",".join(holi1)
                        print "hooooooooooooooooooooooooliiiiiiiiiiii",holi,type(holi)

                        if "Plug & Play" in p_type1:
                                sub_type=d.property_subtype
                                if (("Start Up/Co-Working" in sub_type) or ("Co-Working" in sub_type )or ("Start Up" in sub_type)) :
                                      Start_Up="checked"
                                if "Coffee Shop" in sub_type:
                                       Coffee_Shop="checked"
                                if (("Start Up/Co-Working" in sub_type)):
                                        super_type=str(d.property_super_subtype)
                                        print "super_type......................",super_type,type(super_type)

                                        if(super_type == "Hot_Seat"):
                                
                                                plug_n_play=Shared_area.objects.filter(property_id=prop_id)
                                                if(plug_n_play):
                                                        for plug in plug_n_play:
                                                                if(plug.rate_hr > 0):
                                                                        rate_hr_plug=plug.rate_hr
                                                                        hourly_plug="checked"
                                                                        if(hourly_plug == "checked"):
                                                                                hourly_data_plug=" "
                                                                        
                                                                        print "hourly_data_plug=",hourly_data_plug
                                                                if(plug.rate_daily > 0):
                                                                        rate_daily_plug=plug.rate_daily
                                                                        daily_plug="checked"
                                                                        if(daily_plug == "checked"):
                                                                                daily_plug_data=" "
                                                                        
                                                                if(plug.rate_weekly > 0):
                                                                        rate_weekly_plug=plug.rate_weekly
                                                                        weekly_plug="checked"
                                                                        if(weekly_plug == "checked"):
                                                                                weekly_plug_data=" "
                                                                        
                                                                if(plug.rate_monthly > 0):
                                                                        rate_monthly_plug=plug.rate_monthly
                                                                        monthly_plug="checked"
                                                                        if(monthly_plug == "checked"):
                                                                                monthly_plug_data=" "
                                                                        
                                                                if(plug.shared_images):
                                                                        plug_img=(str(plug.shared_images))
                                                                        plug_img1=str(plug_img)
                                                                        p_i=plug_img.split(",")
                                                                        print "p_i------------",p_i
                                                                        
                                                                        
                                                                
                                                                capacity_plug=plug.capacity

                                        if(super_type == "Pvt_Ofc"):
                                                 plug_n_play=Shared_area.objects.filter(property_id=prop_id)
                                                 if(plug_n_play):
                                                        for plug in plug_n_play:
                                                                rate_monthly_val=0
                                                                monthly_val=0
                                                                monthly_plug_data="disabled"
                                                                room_no=int(plug.pvt_ofc_no)
                                                                plug_n_play_data=Shared_area.objects.filter(property_id=prop_id,pvt_ofc_no=room_no)
                                                                for pg in plug_n_play_data:
                                                                        monthly_plug_data="disabled"
                                                                        monthly_plug_data=" "
                                                                        room_no=int(plug.pvt_ofc_no)

                                                                        if(pg.rate_monthly > 0):
                                                                                rate_monthly_val=pg.rate_monthly
                                                                                monthly_val="checked"

                                                                        if(pg.shared_images):
                                                                                plug_img=(str(pg.shared_images))
                                                                                plug_img1=str(plug_img)
                                                                                p_i=plug_img.split(",")
                                                                                print "p_i------------",p_i
                                                                        capacity_pg=pg.capacity
                                                                        room_no_pg=pg.pvt_ofc_no
                                                                        first.append(rate_monthly_val)
                                                                        first.append(monthly_val)
                                                                        first.append(monthly_plug_data)
                                                                        first.append(capacity_pg)
                                                                        first.append(room_no_pg)
                                                                        first.append(p_i)
                                                                        result_month_pp.append(first)
                                                                        first=[]

                                                                        
                                else:
                                        plug_n_play=Shared_area.objects.filter(property_id=prop_id)
                                        if(plug_n_play):
                                                for plug in plug_n_play:
                                                        if(plug.rate_hr > 0):
                                                                rate_hr_plug=plug.rate_hr
                                                                hourly_plug="checked"
                                                                if(hourly_plug == "checked"):
                                                                        hourly_data_plug=" "
                                                                
                                                                print "hourly_data_plug=",hourly_data_plug
                                                        if(plug.rate_daily > 0):
                                                                rate_daily_plug=plug.rate_daily
                                                                daily_plug="checked"
                                                                if(daily_plug == "checked"):
                                                                        daily_plug_data=" "
                                                                
                                                        if(plug.rate_weekly > 0):
                                                                rate_weekly_plug=plug.rate_weekly
                                                                weekly_plug="checked"
                                                                if(weekly_plug == "checked"):
                                                                        weekly_plug_data=" "
                                                                
                                                        if(plug.rate_monthly > 0):
                                                                rate_monthly_plug=plug.rate_monthly
                                                                monthly_plug="checked"
                                                                if(monthly_plug == "checked"):
                                                                        monthly_plug_data=" "
                                                                
                                                        if(plug.shared_images):
                                                                plug_img=(str(plug.shared_images))
                                                                plug_img1=str(plug_img)
                                                                p_i=plug_img.split(",")
                                                                print "p_i------------",p_i
                                                                
                                                                
                                                        
                                                        capacity_plug=plug.capacity 
                                        

                        if "Training Room" in p_type1:
                                
                                train1=Training_room.objects.filter(property_id=prop_id)
                                if(train1):
                                        for tr1 in train1:
                                                rate_half_day_train=0
                                                halfday_train=0
                                                rate_full_day_train=0
                                                fullday_train=0
                                                halfday_train_data="disabled"
                                                fullday_train_data="disabled"
                                                room_no=int(tr1.training_room_no)
                                                train=Training_room.objects.filter(property_id=prop_id,training_room_no=room_no)
                                                
                                                for tr in train:
                                                        halfday_train_data="disabled"
                                                        fullday_train_data="disabled"
                                                        train_room_no=tr.training_room_no
                                                        print "kkkkkkkkkkkkkkkkkk",tr.rate_half_day,tr.rate_full_day
                                                        
                                                        if(tr.rate_half_day > 0):
                                                                rate_half_day_train=tr.rate_half_day
                                                                halfday_train="checked"
                                                                halfday_train_data=" "
                                                                
                                                        if(tr.rate_full_day > 0):
                                                                rate_full_day_train=tr.rate_full_day
                                                                fullday_train="checked"
                                                                fullday_train_data=" "
                                                        
                                                        print "hkhflerjlgfjl;k;",halfday_train_data,fullday_train_data
                                                        capacity_train=tr.capacity
                                                        room_no_train=tr.training_room_no
                                                        first.append(halfday_train)
                                                        first.append(fullday_train)
                                                        first.append(rate_half_day_train)
                                                        first.append(rate_full_day_train)
                                                        first.append(capacity_train)
                                                        first.append(room_no_train)
                                                        first.append(halfday_train_data)
                                                        first.append(fullday_train_data)
                                                        result_train.append(first)
                                                        first=[]

                                                        if(tr.training_room_images):
                                                                tr_img=str(tr.training_room_images)
                                                                tr_img1=str(tr_img)
                                                                t_i=tr_img.split(",")
                                                        

                        if "Meeting_Room" in p_type1:
                        	print "Hai....Iam in meeting room"
                                meeting1=Meeting_room.objects.filter(property_id=prop_id)
                                if(meeting1):
                                        for meet1 in meeting1:
                                                rate_hr_meet=0
                                                hourly_meet=0
                                                rate_daily_meet=0
                                                daily_meet=0
                                                rate_weekly_meet=0
                                                weekly_meet=0
                                                hourly_meet_data="disabled"
                                                daily_meet_data="disabled"
                                                weekly_meet_data="disabled"
                                                room_no=int(meet1.room_no)

                                                meeting=Meeting_room.objects.filter(property_id=prop_id,room_no=room_no)
                                                for meet in meeting:
                                                
                                                        if(meet.rate_hr > 0):
                                                                rate_hr_meet=meet.rate_hr
                                                                hourly_meet="checked"
                                                                hourly_meet_data=" "
                                                        if(meet.rate_daily > 0):
                                                                rate_daily_meet=meet.rate_daily
                                                                daily_meet="checked"
                                                                daily_meet_data=" "
                                                        if(meet.rate_weekly > 0):
                                                                rate_weekly_meet=meet.rate_weekly
                                                                weekly_meet="checked"
                                                                weekly_meet_data=" "
                                                        
                                                        capacity_meet=meet.capacity
                                                        room_no_meet=meet.room_no
                                                        first.append(hourly_meet)
                                                        first.append(rate_hr_meet)
                                                        first.append(daily_meet)
                                                        first.append(rate_daily_meet)
                                                        first.append(capacity_meet)
                                                        first.append(room_no_meet)
                                                        first.append(weekly_meet)
                                                        first.append(rate_weekly_meet)
                                                        first.append(hourly_meet_data)
                                                        first.append(daily_meet_data)
                                                        first.append(weekly_meet_data)
                                                        result_meet.append(first)
                                                        first=[]

                                                        if(meet.meeting_room_images):
                                                                meet_img=str(meet.meeting_room_images)
                                                                meet_img1=str(meet_img)
                                                                m_i=meet_img.split(",")
                                                        


                        if "Event_Hall" in p_type1:
                                
                                eventhall=Event_Halls.objects.filter(property_id=prop_id)
                                if(eventhall):
                                        for event1 in eventhall:
                                                rate_halfday_event=0
                                                halfday_event=0
                                                rate_daily_event=0
                                                daily_event=0
                                                room_no=event1.room_no
                                                daily_event_data="disabled"
                                                halfday_event_data="disabled"
                                                eventhall0=Event_Halls.objects.filter(property_id=prop_id,room_no=room_no)
                                                for event in eventhall0:
                                                        if(event.rate_halfday > 0):
                                                                rate_halfday_event=event.rate_halfday
                                                                halfday_event="checked"
                                                                halfday_event_data=" "
                                                        if(event.rate_daily > 0):
                                                                rate_daily_event=event.rate_daily
                                                                daily_event="checked"
                                                                daily_event_data=" "
                                                        
                                                        capacity_event=event.capacity
                                                        room_no_event=event.room_no

                                                        first.append(halfday_event)
                                                        first.append(daily_event)
                                                        first.append(rate_halfday_event)
                                                        first.append(rate_daily_event)
                                                        first.append(capacity_event)
                                                        first.append(room_no_event)
                                                        first.append(halfday_event_data)
                                                        first.append(daily_event_data)
                                                        result_event.append(first)
                                                        first=[]

                                                        if(event.shared_images):
                                                                event_img=(str(event.shared_images))
                                                                event_img1=str(event_img)
                                                                e_i=event_img.split(",")
                        
			                        
                        print "Fetching Db"
                        facility=Property_Facility.objects.filter(property_id=prop_id)
                        if(facility):
                            print "This is database",facility
                            for f in facility:
                                        if(f.Wifi!='ND'):
                                                free_wifi=int(f.Wifi)
                                                print "freeeeee Wifiiiiiiiiiiii",free_wifi
                                                if(free_wifi==0):
                                                        print "freeeeee Wifiiiiiiiiiiii",free_wifi
                                                        wifi="checked"
                                                        wifi1=""
                                                        print "wifi is free facility",wifi
                                                elif(free_wifi==1):
                                                        wifi1="checked"
                                                        wifi=""
                                        if(f.AC!='ND'):
                                            free_ac=int(f.AC)
                                            if(free_ac==0):
                                                ac="checked"
                                                ac1=""
                                                print "wifi is free facility",wifi
                                            elif(free_ac==1):
                                                ac1="checked"
                                                ac=""

                                        if(f.Library!='ND'):
                                            free_library=int(f.Library)
                                            if(free_library==0):
                                                library="checked"
                                                library1=""
                                                print "wifi is free facility",wifi
                                            elif(free_library==1):
                                                library1="checked"
                                                library=""

                                        if(f.Printer!='ND'):
                                            free_printer=int(f.Printer)
                                            if(free_printer==0):
                                                printer="checked"
                                                printer1=""
                                                print "wifi is free facility",wifi
                                            elif(free_printer==1):
                                                printer1="checked"
                                                printer=""

                                        if(f.Projection_screen!='ND'):
                                            free_screen=int(f.Projection_screen)
                                            if(free_screen==0):
                                                projection="checked"
                                                projection1=""
                                                print "wifi is free facility",wifi
                                            elif(free_screen==1):
                                                projection1="checked"
                                                projection=""

                                        if(f.Coffee_tea!='ND'):
                                            free_coffee=int(f.Coffee_tea)
                                            if(free_coffee==0):
                                                coffee="checked"
                                                coffee1=""
                                            elif(free_coffee==1):
                                                coffee1="checked"
                                                coffee=""

                                        if(f.Charging_Point!='ND'):
                                                free_charging=int(f.Charging_Point)
                                                if(free_charging==0):
                                                        charging="checked"
                                                        charging1=""
                                                elif(free_charging==1):
                                                        charging1="checked"
                                                        charging=""

                                        if(f.Massage_chair!='ND'):
                                                free_chair=int(f.Massage_chair)
                                                if(free_chair==0):
                                                        chair="checked"
                                                        chair1=""
                                                elif(free_chair==1):
                                                        chair1="checked"
                                                        chair=""

                                        if(f.Projector!='ND'):    
                                            free_proj=int(f.Projector)
                                            if(free_proj==0):
                                                projector="checked"
                                                projector1=""
                                            elif(free_proj==1):
                                                projector1="checked"
                                                projector=""

                                        if(f.Water_bottle!='ND'):
                                                free_bottle=int(f.Water_bottle)
                                                if(free_bottle==0):
                                                        water="checked"
                                                        water1=""
                                                elif(free_bottle==1):
                                                        water1="checked"
                                                        water=""

                                        if(f.Changing_room!='ND'):
                                            free_room=int(f.Changing_room)
                                            if(free_room==0):
                                                changing="checked"
                                                changing1=""
                                            elif(free_room==1):
                                                changing1="checked"
                                                changing=""

                                        if(f.Locker!='ND'):
                                            free_locker=int(f.Locker)
                                            if(free_locker==0):
                                                locker="checked"
                                                locker1=""
                                            elif(free_locker==1):
                                                locker1="checked"
                                                locker=""
                                                
                                        if(f.Stationary!='ND'):
                                                free_stationary=int(f.Stationary)
                                                if(free_stationary==0):
                                                        stationary="checked"
                                                        stationary1=""
                                                elif(free_stationary==1):
                                                        stationary1="checked"
                                                        stationary=""

                                        if(f.PC_or_Laptop!='ND'):
                                                free_pc=int(f.PC_or_Laptop)
                                                if(free_pc==0):
                                                        pc="checked"
                                                        pc1=""
                                                elif(free_pc==1):
                                                        pc1="checked"
                                                        pc=""

                                        if(f.Seat_up!='ND'):
                                                free_seatup=int(f.Seat_up)
                                                if(free_seatup==0):
                                                        seat="checked"
                                                        seat1=""
                                                elif(free_seatup==1):
                                                        seat1="checked"
                                                        seat=""
                                       
                        
                                       
                           
                
                                                
                                                
                        

        
        #********************code by aditya ****************************
##        prop_id=request.POST["newID"]
##	print "prop id..",prop_id
	print "wifi",wifi
        return render_to_response('edit_propertypage_3aug.html',{"owner_id":owner,"active_selected":active_selected,"inactive_selected":inactive_selected,
                                                            "default_selected1":default_selected1,"default_selected2":default_selected2,
                                                            "default_selected3":default_selected3,"default_selected4":default_selected4,
                                                            "non_week_day":non_week_day,"week_day":week_day,"nonwork_selected":nonwork_selected,"end_time_selected":end_time_selected,"start_time_selected":start_time_selected,"user":user,"password":password,"ownerID":ownerID,"status":prop_status,"prop_id":prop_id,"property_name":property_name,"price":starting_price,"offer":offer,
                                                            "address":address,"loc":loc,"lat":lat,"lon":lon,"default":default,"ac1":ac1,
                                                            "result_month_pp":result_month_pp,"super_type":super_type,"sub_type":sub_type,"p_type_p":p_type_p,"p_type_t":p_type_t,"p_type_e":p_type_e,"charging1":charging1,
                                                            "p_type_m":p_type_m,"start_time":start_time,"end_time":end_time,"changing1":changing1,"printer1":printer1,
                                                            "train_room_no":train_room_no,"non_work":non_work,"holi":holi,"description":description,"stationary1":stationary1,
                                                            "pc":pc,"stationary":stationary,"locker":locker,"changing":changing,"water1":water1,
                                                            "water":water,"projector":projector,"seat":seat,"seat1":seat1,"chair":chair,"chair1":chair1,"projector1":projector1,
                                                            "charging":charging,"coffee":coffee,"projection":projection,"projection1":projection1,
                                                            "printer":printer,"library":library,"ac":ac,"wifi":wifi,"wifi1":wifi1,"library1":library1,
                                                            "my_val_plug":my_val_plug,"my_val_Training":my_val_Training,"pc1":pc1,"locker1":locker1,
                                                            "my_val_event":my_val_event,"my_val_meeting":my_val_meeting,"coffee1":coffee1,
                                                            "result_meet":result_meet,"result_train":result_train,"result_event":result_event,
                                                            "rate_halfday_event":rate_halfday_event,"rate_daily_event":rate_daily_event,
                                                            "hourly_data_plug":hourly_data_plug,"daily_plug_data":daily_plug_data,
                                                            "weekly_plug_data":weekly_plug_data,"monthly_plug_data":monthly_plug_data,
                                                            "halfday_event":halfday_event,"daily_event":daily_event,
                                                            "plug_img":p_i,"tr_img":t_i,"meet_img":m_i,"event_img":e_i,"main_img":main_img,
                                                            "capacity_event":capacity_event,"room_no_event":room_no_event,
                                                            "rate_half_day_train":rate_half_day_train,"rate_full_day_train":rate_full_day_train,
                                                            "halfday_train":halfday_train,"fullday_train":fullday_train,
                                                            "capacity_train":capacity_train,"room_no_train":room_no_train,
                                                            "capacity_plug":capacity_plug,"rate_hr_plug":rate_hr_plug,
                                                            "rate_daily_plug":rate_daily_plug,"rate_weekly_plug":rate_weekly_plug,
                                                            "rate_monthly_plug":rate_monthly_plug,"hourly_plug":hourly_plug,
                                                            "daily_plug":daily_plug,"weekly_plug":weekly_plug,
                                                            "monthly_plug":monthly_plug,"Start_Up":Start_Up,"Coffee_Shop":Coffee_Shop})


def upload_image(images,pid):
        pathlist=[]
        temp_image=images
        print "temp_image",temp_image
        for lis in temp_image:
                print "list",lis
                pathrelative="/var/www/BizPit/BizPit_Backend/static"+"/"+str(pid)+"/"+str(lis)
                print "Ppathrel",pathrelative
                path=os.getcwd() + pathrelative
                print "pathsjdjjfj",path
                d = os.path.dirname(path)
                print "D",d


                if not os.path.exists(d):
                        os.makedirs(d, 0777)
                with open(path, 'wb+') as fileName:
                        for chunk in lis.chunks():
                                fileName.write(chunk)
                                #pathcomp=d+pathrelative
                                pathlist.append(pathrelative)
	pathlist=list(set(pathlist))
        return pathlist



			

@csrf_exempt
def Save_edit_property(request):
        print "em am exactly in the save edit property "
	prop_id=int(request.POST['prop_id'])
	print "property id----->",prop_id
        user = str(request.POST["Username"])
	property_name=request.POST["name_proj"]
        starting_price=request.POST["price"]
        offer=request.POST["offer"]
	print "property name----->",property_name
	address=request.POST["searchTextField"]
	print "address--->",address

	lat=request.POST["cityLat2"]
	lon=request.POST["cityLng2"]
	loc=str(request.POST["city22"])
	print "latit..",lat
	print "long...",lon
	print "loc....",loc
	

        if(lat != "" and lon != ""):
                print "Iam in... lat lon"
                new_lat=lat
                new_lon=lon
                lat_cut=float('%.2f' % float(new_lat))
                lon_cut=float('%.2f' % float(new_lon))
                new_d=Property_Details.objects.get(property_id=prop_id)
                new_d.latitude=new_lat
                new_d.longitude=new_lon
                new_d.new_latitude=lat_cut
                new_d.new_longitude=lon_cut
                new_d.location=loc
                new_d.save()
        
	default=request.POST["default"]
	print "default--->",default
	prop_status1=request.POST["status"]
	if(prop_status1 == "Active" or prop_status1 == "active"):
                prop_status="active"
        else:
                prop_status="in_active"
	description=str(request.POST["description"])
	print "description:",description
        
	main_img=request.FILES.getlist('new_images')
        try:
                plug_type=request.POST["plu_n_play"]
        except:
                plug_type=0

        try:
                train_type=request.POST["training"]
                
        except:
                train_type=0

        try:
                meet_type=request.POST["meeting_room"]
        except:
                meet_type=0

        try:
                event_type=request.POST["event_hall"]
        except:
                event_type=0
        my_type=[]
        if(plug_type):
                my_type.append("Plug & Play")
        if(train_type):
                my_type.append("Training Room")
        if(meet_type):
                my_type.append("Meeting_Room")
        if(event_type):
                my_type.append("Event_Hall")
                
        
        new_cur_pathlist0=""
	if main_img:
	      print "in this code..............."
	      cur_pathlist=[]
              path1=upload_image(main_img,prop_id)

              print "path",path1
              print "\n\n path_of_image :",path1,type(path1)
              for link in path1:
                     tmp_path1 = link.split("/")
                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                     print "temp path1 :",cur_path1
                     cur_pathlist.append(cur_path1)
              new_cur_pathlist0=",".join(cur_pathlist)
              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist0,type(new_cur_pathlist0)
              print "aasd",new_cur_pathlist0
	
	typ_list=[]
        
	print "my valu---------------------------------------------------------------------------------------------------->",my_type

	for i in my_type:
		
              typ_list.append(str(i))
        typ_list1=list(set(typ_list))
       	print "type_list--->",typ_list1
        new_cur_typlist=",".join(typ_list1)
	if "Plug & Play" in typ_list1:
		my_val_plug = "Plug & Play"
	else:
		my_val_plug = "none"

	if "Meeting_Room" in typ_list1:
		my_val_meeting = "Meeting_Room"
	else:
		my_val_meeting= "none"

	if "Training Room" in typ_list1:
		my_val_Training = "Training"
	else:
		my_val_Training = "none"
	if "Event_Hall" in typ_list1:
		my_val_event = "Event Hall"
	else:
		my_val_event = "none"
        
	start_time=request.POST["str_time"]
        print "start_time--->",start_time
        end_time=request.POST["end_time"]
        print "end_time--->",end_time
        try:
                sub_type=str(request.POST["sub_type"])
                print "Iam in sub type try block.."
        except:
                sub_type="Start Up/Co-Working"

        #if(sub_type == "Start Up/Co-Working"):
                
        try:
		super_type=str(request.POST["super_sub_type"])
        except:
		super_type=""
        print "totalllyyyyyyyyyyyyyyyyy",my_val_plug,my_val_meeting,my_val_Training,my_val_event

        

	new_data=Property_Details.objects.get(property_id=prop_id)
	new_data.property_name=property_name
	new_data.property_type=new_cur_typlist
	new_data.address=address
	new_data.status=prop_status
	new_data.property_subtype=sub_type
	new_data.property_super_subtype=super_type
	new_data.operating_strattime=start_time
	new_data.operating_stoptime=end_time
        new_data.default_type=default
	new_data.description=description
        new_data.starting_price=starting_price
##        new_data.submitted_by=user
        new_data.offer=offer
	if(new_data.images):
                new_img=new_data.images+","+new_cur_pathlist0
                new_img1=new_img.split(",")
                new_i=list(set(new_img1))
                image=",".join(new_i)
                new_data.images=image
        else:
                new_data.images=new_cur_pathlist0
        

	new_data.save()	

	try:
                non_working_days1=request.POST.getlist("non_work[]")
                non_working_days=",".join(non_working_days1)
                print "non working days--->",non_working_days
        except:
                non_working_days=""
	if(Non_Working_Days.objects.filter(property_id=prop_id).exists()):
                Non_Working_Days.objects.filter(property_id=prop_id).update(Non_Working_days=non_working_days)
        else:
                Non_Working_Days(property_id=prop_id,Non_Working_days=non_working_days).save()
	#new_data=Non_Working_Days.objects.filter(property_id=prop_id)
	try:
                holidays=request.POST["holi"]
                final_holiday_value=datetime.datetime.strptime(holidays, '%Y-%m-%d').strftime('%d/%m/%Y')
        except:
                final_holiday_value=""
                
	if(Holidays.objects.filter(property_id=prop_id).exists()):
                Holidays.objects.filter(property_id=prop_id).update(holidays=final_holiday_value)
        else:
                Holidays(property_id=prop_id,holidays=final_holiday_value).save()
	#holiday_data=Holidays.objects.filter(property_id=prop_id)
	try:
                my_type_plug_n_play=str(request.POST["plu_n_play"])
        except:
                my_type_plug_n_play=""

        try:
                my_type_training=str(request.POST["training"])
        except:
                my_type_training=""
        try:
                my_type_meeting=str(request.POST["meeting_room"])
        except:
                my_type_meeting=""
        try:
                my_type_event_hall=str(request.POST["event_hall"])
        except:
                my_type_event_hall=""

        print "Nowwwwwwwwwwwwwwwwwwww",my_type_plug_n_play,my_type_training,my_type_meeting,my_type_event_hall

        if(my_type_plug_n_play):
                print "Iam in Plug and play block.................."
                try:
                        sub_type=str(request.POST["sub_type"])
                        print "Iam in sub type try block.."
                except:
                        sub_type="Start Up/Co-Working"

                if(sub_type == "Start Up/Co-Working"):
                        
                        try:
                                super_type=str(request.POST["super_sub_type"])
                        except:
                                super_type=""
                        if(super_type == "Hot_Seat"):
                                new_data_prop=Property_Details.objects.get(property_id=prop_id)
                                new_data_prop.property_subtype=sub_type
                                new_data_prop.property_super_subtype=super_type
                                new_data_prop.save()
                                
                                try:
                                    shared_capacity=request.POST["capacity1"]
                                    print "my capacity--->",shared_capacity
                                    if(shared_capacity):
                                        print"am here"
                                    else:
                                        shared_capacity=0

                                except:
                                    shared_capacity=0

                                try:
                                        shared_hr=request.POST["rate_hr"]
                                except:
                                        shared_hr=0
                                try:
                                        shared_daily=request.POST["rate_daily2"]
                                except:
                                        shared_daily=0
                                try:	
                                        shared_weekly=request.POST["rate_week2"]
                                except:
                                        shared_weekly=0
                                try:	
                                        shared_monthly=request.POST["rate_month"]
                                except:
                                        shared_monthly=0

                                sh_images=request.FILES.getlist('shared_img')
                                print "shared.................",sh_images

                                
                                
                                new_cur_pathlist=""
                                if sh_images:
                                      print "in this code..............."
                                      cur_pathlist=[]
                                      path1=upload_image(sh_images,prop_id)

                                      print "path",path1
                                      print "\n\n path_of_image :",path1,type(path1)
                                      for link in path1:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist.append(cur_path1)
                                      new_cur_pathlist=",".join(cur_pathlist)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                                      print "aasd",new_cur_pathlist
                        

                                new_cur_pathlist=""
                                #print "this is try------------------------------------------------------------>",my_type_plug_n_play
                                if(shared_capacity > 0):
                                        new_data1=Shared_area.objects.filter(property_id=prop_id)
                                        if(new_data1):
                                                print "Iam innnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"
                                                new_data=Shared_area.objects.get(property_id=prop_id)
                                                new_data.capacity=shared_capacity
                                                new_data.rate_hr=shared_hr
                                                new_data.rate_daily=shared_daily
                                                new_data.rate_weekly=shared_weekly
                                                new_data.rate_monthly=shared_monthly
                                                if(new_data.shared_images):
                                                        new_img=new_data.shared_images+","+new_cur_pathlist
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        new_data.shared_images=image
                                                else:
                                                        new_data.shared_images=new_cur_pathlist

                                                new_data.save()
                                        else:
                                                new_data=Shared_area()
                                                new_data.property_id=prop_id
                                                new_data.capacity=shared_capacity
                                                new_data.rate_hr=shared_hr
                                                new_data.rate_daily=shared_daily
                                                new_data.rate_weekly=shared_weekly
                                                new_data.rate_monthly=shared_monthly
                                                if(new_data.shared_images):
                                                        new_img=new_data.shared_images+","+new_cur_pathlist
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        new_data.shared_images=image
                                                else:
                                                        new_data.shared_images=new_cur_pathlist

                                                new_data.save()

                        elif(super_type == "Pvt_Ofc"):
                                print "Iam in pvt ofc save edit part............."
                                room_no=0
                                try:
                                        new_tot_row=int(request.POST["new_val_pvt"])
                                        print "new_tot_row........",new_tot_row
                                        total_row=int(request.POST["val_pvt"])
                                        print "total row...",total_row
                                        if(new_tot_row > total_row):
                                                tot_row=new_tot_row
                                        else:
                                                tot_row=total_row
                                        print "tot_row",tot_row
                                except:
                                        total_row=0
                                        print "total row except...",total_row
                                
                                if(total_row):

                                        
                                        count=1
                                        print "\n\ntot_row\t",tot_row
                                        e_val = int(tot_row+1)
                                        print "\n\ne_val\t",e_val
                                        for i in range(1,e_val):
                                                print "iam in range.."
                                                new_room_no=int(i)
                                                capacity_val= "pvt_capacity_monthly_"+str(i)
                                                print "\n capacity_val ",capacity_val
                                                weekly_val=str("rate_monthly_"+str(i))
                                                image_val=str("shared_img_pvt_"+str(i))
                                        
                                                try:
                                                        new_shared_capacity=int(request.POST[capacity_val])
                                                        print "new_capa...",new_shared_capacity
                                                except:
                                                        new_shared_capacity=0
                                                        print "new_capa...",new_shared_capacity

                                                try:
                                                        new_shared_monthly=request.POST[weekly_val]
                                                        print "new_weekly",new_shared_monthly
                                                except:
                                                        new_shared_monthly=0

                                                try:
                                                        new_sh_img=request.FILES.getlist(image_val)
                                                except:
                                                        new_sh_img=0
                                                
                                                new_cur_pathlist11=""
                                                if new_sh_img:
                                                      print "in this code..............."
                                                      cur_pathlist11=[]
                                                      path2=upload_image(new_sh_img,prop_id)

                                                      print "path",path2
                                                      print "\n\n path_of_image :",path2,type(path2)
                                                      for link in path2:
                                                             tmp_path1 = link.split("/")
                                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                                             print "temp path1 :",cur_path1
                                                             cur_pathlist11.append(cur_path1)
                                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                                      print "aasd",new_cur_pathlist11
                                                if(new_shared_capacity > 0):
                                                        new_room_no1=count
                                                        new_data1=Shared_area.objects.filter(property_id=prop_id,pvt_ofc_no=new_room_no)
                                                        if(new_data1):
                                                                new_data=Shared_area.objects.get(property_id=prop_id,
                                                                                                 pvt_ofc_no=new_room_no1)
                                                                new_data.capacity=new_shared_capacity
                                                                new_data.rate_monthly=new_shared_monthly
                                                                if(new_data.shared_images):
                                                                        new_img=new_data.shared_images+","+new_cur_pathlist11
                                                                        new_img1=new_img.split(",")
                                                                        new_i=list(set(new_img1))
                                                                        image=",".join(new_i)
                                                                        new_data.shared_images=image
                                                                else:
                                                                        new_data.shared_images=new_cur_pathlist11

                                                                new_data.save()
                                                        else:
                                                                new_data=Shared_area()
                                                                new_data.property_id=prop_id
                                                                new_data.pvt_ofc_no=new_room_no1
                                                                new_data.capacity=new_shared_capacity
                                                                new_data.rate_monthly=new_shared_monthly
                                                                if(new_data.shared_images):
                                                                        new_img=new_data.shared_images+","+new_cur_pathlist11
                                                                        new_img1=new_img.split(",")
                                                                        new_i=list(set(new_img1))
                                                                        image=",".join(new_i)
                                                                        new_data.shared_images=image
                                                                else:
                                                                        new_data.shared_images=new_cur_pathlist11

                                                                new_data.save()
                                                        count=count+1

                                else:

                                        try:
                                                shared_capacity=request.POST["capacity1_pvt"]
                                                print "my capacity...",shared_capacity
                                                if(shared_capacity):
                                                        print"am here"
                                                else:
                                                        shared_capacity=0

                                        except:
                                                
                                                shared_capacity=0

                                        try:	
                                                shared_monthly=request.POST["rate_month_pvt"]
                                                book_type.append("Monthly")
                                                book_property_type="Plug & Play"
                                        except:
                                                shared_monthly=0

                                        sh_images=request.FILES.getlist('shared_img_pvt')
                                        print "shared.................",sh_images
                                        new_cur_pathlist=""
                                        if sh_images:
                                              print "in this code..............."
                                              cur_pathlist=[]
                                              path1=upload_image(sh_images,prop_id)

                                              print "path",path1
                                              print "\n\n path_of_image :",path1,type(path1)
                                              for link in path1:
                                                     tmp_path1 = link.split("/")
                                                     cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                                     print "temp path1 :",cur_path1
                                                     cur_pathlist.append(cur_path1)
                                              new_cur_pathlist=",".join(cur_pathlist)
                                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                                              print "aasd",new_cur_pathlist
                                        if(shared_capacity > 0):
                                                new_data1=Shared_area.objects.filter(property_id=prop_id)
                                                if(new_data1):
                                                        data=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=1)
                                                        data.capacity=shared_capacity
                                                        data.rate_monthly=shared_monthly
                                                        if(data.shared_images):
                                                                new_img=data.shared_images+","+new_cur_pathlist
                                                                new_img1=new_img.split(",")
                                                                new_i=list(set(new_img1))
                                                                image=",".join(new_i)
                                                                data.shared_images=image
                                                        else:
                                                                data.shared_images=new_cur_pathlist

                                                        data.save()
                                                else:
                                                        new_data=Shared_area()
                                                        new_data.property_id=prop_id
                                                        new_data.pvt_ofc_no=1
                                                        new_data.capacity=shared_capacity
                                                        new_data.rate_monthly=shared_monthly
                                                        if(new_data.shared_images):
                                                                new_img=new_data.shared_images+","+new_cur_pathlist
                                                                new_img1=new_img.split(",")
                                                                new_i=list(set(new_img1))
                                                                image=",".join(new_i)
                                                                new_data.shared_images=image
                                                        else:
                                                                new_data.shared_images=new_cur_pathlist

                                                        new_data.save()

                # Its for adding new plug and play in edit property.......................

                '''try:
                    shared_capacity_new=request.POST["capacity1_new"]
                    print "my capacity--->",shared_capacity_new
                    if(shared_capacity_new):
                        print"am here"
                    else:
                        shared_capacity_new=0

                except:
                    shared_capacity_new=0

                try:
                        shared_hr_new=request.POST["rate_hr_new"]
                except:
                        shared_hr_new=0
                try:
                        shared_daily_new=request.POST["rate_daily_new"]
                except:
                        shared_daily_new=0
                try:	
                        shared_weekly_new=request.POST["rate_week_new"]
                except:
                        shared_weekly_new=0
                try:	
                        shared_monthly_new=request.POST["rate_month_new"]
                except:
                        shared_monthly_new=0

                sh_images_new=request.FILES.getlist('shared_img_new')
                print "shared.................",sh_images_new

                
                if(shared_capacity_new or shared_hr_new or shared_daily_new or shared_weekly_new or shared_monthly_new or sh_images_new):
                        
                        new_cur_pathlist=""
                        if sh_images_new:
                              print "in this code..............."
                              cur_pathlist=[]
                              path1=upload_image(sh_images_new,prop_id)

                              print "path",path1
                              print "\n\n path_of_image :",path1,type(path1)
                              for link in path1:
                                     tmp_path1 = link.split("/")
                                     cur_path1 = tmp_path1[1]+'/'+tmp_path1[2]+'/'+tmp_path1[3]
                                     print "temp path1 :",cur_path1
                                     cur_pathlist.append(cur_path1)
                              new_cur_pathlist=",".join(cur_pathlist)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist,type(new_cur_pathlist)
                              print "aasd",new_cur_pathlist
                

                    
                        #print "this is try------------------------------------------------------------>",my_type_plug_n_play
##                        new_data1=Shared_area.objects.filter(property_id=prop_id)
##                        if(new_data1):
                        print "Iam innnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"
                        new_data=Shared_area()
                        new_data.property_id=prop_id
                        new_data.capacity=shared_capacity_new
                        new_data.rate_hr=shared_hr_new
                        new_data.rate_daily=shared_daily_new
                        new_data.rate_weekly=shared_weekly_new
                        new_data.rate_monthly=shared_monthly_new
                        if(new_data.shared_images):
                                new_img=new_data.shared_images+","+new_cur_pathlist
                                new_img1=new_img.split(",")
                                new_i=list(set(new_img1))
                                image=",".join(new_i)
                                new_data.shared_images=image
                        else:
                                new_data.shared_images=new_cur_pathlist

                        new_data.save()'''

		

        if(my_type_meeting) :

                try:
                        total_row=int(request.POST["val"])
                        print "total row...",total_row
                        tot_row=total_row
                        print "tot_row",tot_row
                except:
                        total_row=0

                '''try:
                        meeting_capacity_new=request.POST["capacity2"]
                        print "now capacity...",meeting_capacity_new
                        if(meeting_capacity_new):
                                print"am here"
                        else:
                                meeting_capacity_new=0
                        
                        room_no1=room_no+1
                        
                except:
                        
                        meeting_capacity=0
                        
                print "dxfyghdrfhdfghdgfh"
                try:
                        meeting_hr_new=request.POST["rate_hr20"]
                        book_type.append("Hourly")
                        book_property_type="Meeting_Room"
                        print "rate per hr is..",meeting_hr_new
                        
                except:
                        meeting_hr_new=0
                try:
                        meeting_daily_new=request.POST["rate_daily20"]
                        book_type.append("Daily")
                        book_property_type="Meeting_Room"
                        print "rate per daily is..",meeting_daily_new
                except:
                        meeting_daily_new=0
                        print "rate per daily is..",meeting_daily_new
                try:	
                        meeting_weekly_new=request.POST["rate_week20"]
                        book_type.append("Weekly")
                        book_property_type="Meeting_Room"
                        print "rate per weekly is..",meeting_weekly_new
                except:
                        meeting_weekly_new=0
                        print "rate per weekly is..",meeting_weekly_new
                print"am hererererererererer"
                #meeting_images=request.FILES.getlist('b2212')	
                try:
                        meeting_img_new=request.FILES.getlist('meeting_img_new')
                        print "image.........",meeting_img_new

                except:

                        meeting_img_new=0

                if(meeting_hr_new==""):
                        meeting_hr_new=0
                if(meeting_daily_new==""):
                        meeting_daily_new=0
                if(meeting_weekly_new==""):
                        meeting_weekly_new=0

                if(meeting_hr_new or meeting_daily_new or meeting_weekly_new or meeting_img_new):

                        if meeting_img_new:
                              print "in this code..............."
                              cur_pathlist1=[]
                              path2=upload_image(meeting_img_new,prop_id)

                              print "path",path2
                              print "\n\n path_of_image :",path2,type(path2)
                              for link in path2:
                                     tmp_path1 = link.split("/")
                                     cur_path1 = tmp_path1[1]+'/'+tmp_path1[2]+'/'+tmp_path1[3]
                                     print "temp path1 :",cur_path1
                                     cur_pathlist1.append(cur_path1)
                              new_cur_pathlist1=",".join(cur_pathlist1)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist1,type(new_cur_pathlist1)
                              print "aasd",new_cur_pathlist1
                        #print "meet data is..",meeting_hr,meeting_daily,meeting_weekly,new_cur_pathlist1,meeting_capacity
                        data1=Meeting_room(property_id=prop_id,room_no=1,capacity=meeting_capacity_new,rate_hr=meeting_hr_new,
                                           rate_daily=meeting_daily_new,
                                           rate_weekly=meeting_weekly_new,meeting_room_images=new_cur_pathlist1)

                        data1.save()'''
                count=1
                if(total_row):

                        
                        for i in range(1,int(tot_row+1)):
                                print "iam in range.."
                                new_room_no=int(i)
                                capacity_val="capacity_"+str(i)
                                hr_val="rate_hr_"+str(i)
                                daily_val="rate_daily_"+str(i)
                                weekly_val="rate_week_"+str(i)
                                image_val="meeting_img_"+str(i)
                        
                                try:
                                        new_capa=int(request.POST[capacity_val])
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hrly=request.POST[hr_val]
                                        print "new_hrly",new_hrly
                                except:
                                        new_hrly=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                try:
                                        new_weekly=request.POST[weekly_val]
                                        print "new_weekly",new_weekly
                                except:
                                        new_weekly=0

                                try:
                                        new_meet_img=request.FILES.getlist(image_val)
                                except:
                                        new_meet_img=0
                                if(new_hrly==""):
                                        new_hrly=0
                                if(new_daily==""):
                                        new_daily=0
                                if(new_weekly==""):
                                        new_weekly=0
                                        
                                new_cur_pathlist11=""
                                if new_meet_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_meet_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                print "meet data is..",new_hrly,new_daily,new_weekly,new_cur_pathlist11,new_capa,new_room_no

                                if(new_capa > 0):
                                        new_room_no=count 
                                        data11=Meeting_room.objects.filter(property_id=prop_id,room_no=new_room_no)
                                        if(data11):
                                                print "inside ifffffffff"
                                                data1=Meeting_room.objects.get(property_id=prop_id,room_no=new_room_no)
                                                #data1.room_no=room_no1
                                                print "save mado capacity",new_capa
                                                data1.capacity=new_capa
                                                data1.rate_hr=new_hrly
                                                data1.rate_daily=new_daily
                                                data1.rate_weekly=new_weekly
                                                data1.room_no=new_room_no
                                                if(data1.meeting_room_images):
                                                        new_img=data1.meeting_room_images+","+new_cur_pathlist11
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        data1.meeting_room_images=image
                                                else:
                                                        data1.meeting_room_images=new_cur_pathlist11
                                                
                                                data1.save()

                                        else:
                                                print " in else of meeting room.."
                                                new_data1=Meeting_room(property_id=prop_id,
                                                                       room_no=new_room_no,
                                                                       capacity=new_capa,
                                                                       rate_hr=new_hrly,
                                                                       rate_daily=new_daily,
                                                                       rate_weekly=new_weekly,
                                                                       meeting_room_images=new_cur_pathlist11)

                                                new_data1.save()
                                        count=count+1
                                        

        if(my_type_training):


                training_no=0
                try:
                        total_row=int(request.POST["val_train"])
                        print "total row...",total_row
                        tot_row=total_row
                        print "tot_row",tot_row
                except:
                        total_row=0

                

                '''try:
                        training_capacity_new=request.POST["capacity7"]
                        print "now capacity...",training_capacity_new
                        if(training_capacity_new):
                                print"am here"
                        else:
                                training_capacity_new=0
                        
                        training_no1=room_no+1
                        
                except:
                        
                        training_capacity_new=0
                        
                print "dxfyghdrfhdfghdgfh"
                try:
                        training_hr_new=request.POST["rate_half7"]
                        book_property_type="Training Room"
                        print "Iam in try of halfday..",training_hr_new
                        book_type.append("HalfDay")
                except:
                        training_hr_new=0
                        print "Iam in except of halfday..",training_hr_new

                try:
                        training_daily_new=request.POST["rate_daily7"]
                        book_property_type="Training Room"
                        print "Iam in try of fullday..",training_daily_new
                        book_type.append("FullDay")
                except:
                        training_daily_new=0
                        print "Iam in except of fullday..",training_daily_new
                try:	
                        training_weekly_new=request.POST["rate_week7"]
                        book_property_type="Training Room"
                        book_type.append("Weekly")
                except:
                        training_weekly_new=0
                
                try:
                        training_images_new=request.FILES.getlist('training_img_new')

                except:

                        training_images_new=0

                if(training_hr_new==""):
                        training_hr_new=0
                if(training_daily_new==""):
                        training_daily_new=0

                if(training_weekly_new==""):
                        training_weekly_new=0

                if(training_hr_new or training_daily_new or training_weekly_new or training_images_new):
                        print "training_hr_new  training_daily_new training_images_new",training_hr_new,training_daily_new,training_images_new
                        if training_images_new:
                              print "in this code..............."
                              cur_pathlist12=[]
                              path3=upload_image(training_images_new,prop_id)

                              print "path",path3
                              print "\n\n path_of_image :",path3,type(path3)
                              for link in path3:
                                     tmp_path1 = link.split("/")
                                     cur_path12 = tmp_path1[1]+'/'+tmp_path1[2]+'/'+tmp_path1[3]
                                     print "temp path1 :",cur_path12
                                     cur_pathlist12.append(cur_path12)
                              new_cur_pathlist12=",".join(cur_pathlist12)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist12,type(new_cur_pathlist12)
                              print "aasd",new_cur_pathlist12
                        if(Training_room.objects.filter(property_id=prop_id,training_room_no=1).exists()):
                                Training_room.objects.get(property_id=prop_id,training_room_no=1).delete()
                                
                                
                        data123=Training_room(property_id=prop_id,
                                              training_room_no=1,
                                              capacity=training_capacity_new,
                                              rate_half_day=training_hr_new,
                                              rate_full_day=training_daily_new,
                                              rate_weekly=training_weekly_new,
                                              training_room_images=new_cur_pathlist12)

                        data123.save()'''
                        
                count=1
                if(total_row):
                        for i in range(1,int(tot_row+1)):
                                print "iam in range.."
                                new_room_no=int(i)
                                capacity_val="train_capacity_"+str(i)
                                half_val="train_rate_half_"+str(i)
                                daily_val="train_rate_daily_"+str(i)
                                image_val="trainin_img_"+str(i)
                        
                                try:
                                        new_capa=request.POST[capacity_val]
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hralf=request.POST[half_val]
                                        print "new_hrly",new_hralf
                                except:
                                        new_hralf=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                

                                try:
                                        new_train_img=request.FILES.getlist(image_val)
                                except:
                                        new_train_img=0
                                if(new_hralf==""):
                                        new_hralf=0
                                if(new_daily==""):
                                        new_daily=0

                                
                                
                                        
                                new_cur_pathlist11=""
                                if new_train_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_train_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                #print "meet data is..",new_hralf,new_daily,new_weekly,new_cur_pathlist11,new_capa,new_room_no

                                if(new_capa > 0):
                                        new_room_no=count
                                        data123=Training_room.objects.filter(property_id=prop_id,training_room_no=new_room_no)
                                
                                        if(data123):
                                                print "In train if add"
                                                data1234=Training_room.objects.get(property_id=prop_id,training_room_no=new_room_no)
                                                data1234.capacity=new_capa
                                                data1234.rate_half_day=new_hralf
                                                data1234.rate_full_day=new_daily
                                                if(data1234.training_room_images):
                                                        new_img=data1234.training_room_images+","+new_cur_pathlist11
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        data1234.training_room_images=image
                                                else:
                                                        data1234.training_room_images=new_cur_pathlist11
                                                
                                                data1234.save()
                                        else:
                                                
                                                data123=Training_room(property_id=prop_id,
                                                              training_room_no=new_room_no,
                                                              capacity=new_capa,                                              
                                                              rate_half_day=new_hralf,
                                                              rate_full_day=new_daily,
                                                              training_room_images=new_cur_pathlist11)

                                                data123.save()
                                        count=count+1
                        

                
        if(my_type_event_hall):

                try:
                        total_row=int(request.POST["val_event"])
                        print "total row...",total_row
                        tot_row=total_row
                        print "tot_row",tot_row
                except:
                        total_row=0
                room_no=0

                '''try:
                        event_capacity_new=request.POST["capacity12"]
                        print "my capacity...",event_capacity_new
                        if(event_capacity_new):
                                print"am here"
                        else:
                                event_capacity_new=0

                except:
                        
                        event_capacity_new=0

                try:
                        event_hr_new=request.POST["rate_half12"]
                        book_type.append("HalfDay")
                        book_property_type="Event_Hall"
                except:
                        event_hr_new=0
                try:
                        event_daily_new=request.POST["rate_daily12"]
                        book_type.append("FullDay")
                        book_property_type="Event_Hall"
                except:
                        event_daily_new=0
                
                try:
                        event_images_new=request.FILES.getlist('event_img_new')

                except:

                        event_images_new=0
                        
                if(event_hr_new==""):
                        event_hr_new=0
                if(event_daily_new==""):
                        event_daily_new=0

                if(event_hr_new or event_daily_new or event_images_new):

                        if event_images_new:
                              print "in this code..............."
                              cur_pathlist123=[]
                              path4=upload_image(event_images_new,prop_id)

                              print "path",path4
                              print "\n\n path_of_image :",path4,type(path4)
                              for link in path4:
                                     tmp_path1 = link.split("/")
                                     cur_path123 = tmp_path1[1]+'/'+tmp_path1[2]+'/'+tmp_path1[3]
                                     print "temp path1 :",cur_path123
                                     cur_pathlist123.append(cur_path123)
                              new_cur_pathlist123=",".join(cur_pathlist123)
                              print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist123,type(new_cur_pathlist123)
                              print "aasd",new_cur_pathlist123

                        event_room_no=room_no+1
                        Event_Halls(property_id=prop_id,
                                           capacity=event_capacity_new,
                                           rate_halfday=event_hr_new,
                                           rate_daily=event_daily_new,room_no=event_room_no,
                                           shared_images=new_cur_pathlist123).save()
                        print "Event hall data added successfully"

                        #data01.save()'''
                count=1
                if(total_row):
                        
                        for i in range(1,int(tot_row+1)):
                                print "room nooooooooooooo",int(i)
                                del_e="del_val_"+str(i)
                                print "iam in range.."
                                new_room_no=int(i)
                                capacity_val="event_capacity_"+str(i)
                                half_val="event_rate_half_"+str(i)
                                daily_val="event_rate_daily_"+str(i)
                                image_val="event_img_"+str(i)
                                try:
                                        del_ele=int(request.POST[del_e])
                                        print "del element..",del_ele
                                except:
                                        del_ele=0
                                try:
                                        new_capa=int(request.POST[capacity_val])
                                        print "new_capa...",new_capa
                                except:
                                        new_capa=0
                                        print "new_capa...",new_capa
                                try:
                                        new_hralf=request.POST[half_val]
                                        print "new_hralf",new_hralf
                                except:
                                        new_hralf=0

                                try:
                                        new_daily=request.POST[daily_val]
                                        print "new_daily",new_daily
                                except:
                                        new_daily=0

                                try:
                                        new_event_img=request.FILES.getlist(image_val)
                                except:
                                        new_event_img=0
                                if(new_hralf==""):
                                        new_hralf=0
                                if(new_daily==""):
                                        new_daily=0
                                
                                        
                                new_cur_pathlist11=""
                                if new_event_img:
                                      print "in this code..............."
                                      cur_pathlist11=[]
                                      path2=upload_image(new_event_img,prop_id)

                                      print "path",path2
                                      print "\n\n path_of_image :",path2,type(path2)
                                      for link in path2:
                                             tmp_path1 = link.split("/")
                                             cur_path1 = tmp_path1[5]+'/'+tmp_path1[6]+'/'+tmp_path1[7]
                                             print "temp path1 :",cur_path1
                                             cur_pathlist11.append(cur_path1)
                                      new_cur_pathlist11=",".join(cur_pathlist11)
                                      print "new pathhhhhhhhhhhhhhhhhhhhhhhhhhhhhHHHHHHHHHHHHHHHHH",new_cur_pathlist11,type(new_cur_pathlist11)
                                      print "aasd",new_cur_pathlist11
                                print "meet data is..",new_hralf,new_daily,new_cur_pathlist11,new_capa,new_room_no

                                if(new_capa > 0):
                                        new_room_no=count
                                        data11=Event_Halls.objects.filter(property_id=prop_id,room_no=new_room_no)
                        

                                        if(data11):
                                                data1=Event_Halls.objects.get(property_id=int(prop_id),room_no=int(new_room_no))
                                                
                                                print "In else.."
                                                data1.capacity=new_capa
                                                data1.rate_halfday=new_hralf                                        
                                                data1.rate_daily=new_daily
                                                data1.room_no=new_room_no
                                        
                                                if(data1.shared_images):
                                                        new_img=data1.shared_images+","+new_cur_pathlist11
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        data1.shared_images=image
                                                else:
                                                        data1.shared_images=new_cur_pathlist11
                                                
                                                data1.save()
                                                
                                                        
                                        else:
                                                print "create newww"
                                                
                                                data01=Event_Halls(property_id=prop_id,
                                                                   room_no=new_room_no,
                                                                   capacity=new_capa,
                                                                   rate_halfday=new_hralf,
                                                                   rate_daily=new_daily,
                                                                   shared_images=new_cur_pathlist11)

                                                data01.save()

                                        count=count+1


        # Facilities.....................................                
	
        coffe="ND"
	
	wifi='ND'
        water='ND'
        printer='ND'
        charging="ND"
        changing='ND'
	library='ND'
	chair="ND"
	locker='ND'
 	ac='ND'
	projector="ND"
        screen='ND'
	pc="ND"
	seat_up='ND'
	stationary="ND"

	try:
		wifi=request.POST["full_deal"]
       	except:
              try:
                  wifi1=request.POST["full_deal1"]
   	          wifi=wifi1
	      except:
                  wifi="ND"

	try:
		coffe=request.POST["coffe"]
       	except:
               try:
                   coffe1=request.POST["coffe1"]
                   coffe=coffe1
	       except:
                   coffe="ND"
        
        

	try:
		water=request.POST["water"]
       	except:
	       try:
                   water1=request.POST["water1"]
                   water=water1
               except:
                   water='ND'


	try:
		printer=request.POST["printer"]
       	except:
               try:
                   printer1=request.POST["printer1"]
                   printer=printer1
               except:
                   printer='ND'

	try:
		charging=request.POST["charging"]
       	except:
               try:
                   charging1=request.POST["charging1"]
                   charging=charging1
               except:
                   charging="ND"

	try:
		changing=request.POST["changing"]
       	except:
               try:
                   changing1=request.POST["changing1"]
                   changing=changing1
               except:
                   changing="ND"

	try:
		library=request.POST["library"]
       	except:
               try:
                   library1=request.POST["library1"]
                   library=library1
               except:
                   library="ND"

	
	try:
		chair=request.POST["chair"]
       	except:
               try:
                   chair1=request.POST["chair1"]
                   chair=chair1
               except:
                   chair="ND"



	try:
		locker=request.POST["locker"]
       	except:
               try:
                   locker1=request.POST["locker1"]
                   locker=locker1
               except:
                   locker="ND"

	try:
		ac=request.POST["ac"]
       	except:
               try:
                   ac1=request.POST["ac1"]
                   ac=ac1
               except:
                   ac="ND"

	try:
		projector=request.POST["projector"]
       	except:
               try:
                   projector1=request.POST["projector1"]
                   projector=projector1
               except:
                   projector="ND"



	try:
		pc=request.POST["pc"]
       	except:
               try:
                   pc1=request.POST["pc1"]
                   pc=pc1
               except:
                   pc="ND"

	
	try:
		screen=request.POST["wifi"]
        except:
               try:
                   screen1=request.POST["wifi1"]
                   screen=screen1
               except:
                   screen="ND"



	try:
		seat_up=request.POST["hr_deal"]
        except:
               try:
                   seat_up1=request.POST["hr_deal1"]
                   seat_up=seat_up1
               except:
                   seat_up="ND"




	try:
		stationary=request.POST["half_deal"]
	except:
               try:
                   stationary1=request.POST["half_deal1"]
                   stationary=stationary1
               except:
                   stationary="ND"


        if(Property_Facility.objects.filter(property_id=prop_id).exists()):                              


                Property_Facility.objects.filter(property_id=prop_id).update(Wifi=wifi,Coffee_tea=coffe,Water_bottle=water,Printer=printer,Stationary=stationary,Seat_up=seat_up,Charging_Point=charging,Changing_room=changing,Library=library,Massage_chair=chair,
        Locker=locker,AC=ac,Projector=projector,Projection_screen=screen,PC_or_Laptop=pc)
        #********************code by aditya ****************************	

        else:
              Property_Facility(property_id=prop_id,Wifi=wifi,Coffee_tea=coffe,Water_bottle=water,Printer=printer,Stationary=stationary,Seat_up=seat_up,Charging_Point=charging,Changing_room=changing,Library=library,Massage_chair=chair,
        Locker=locker,AC=ac,Projector=projector,Projection_screen=screen,PC_or_Laptop=pc).save()
              
	
	email_id=[]
	
        username = request.POST["Username"]
        password = request.POST["Password"]

        data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})

			

@csrf_exempt
def delete_shared_img(request,file_name,prop_id,user_name,password):

        print "file_name",file_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative
##
        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        #file_path ='/home/brisa/BizPit/BizPit_Backend/'+pathRelative

        #path = '/home/brisa/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Shared_area.objects.get(property_id=prop_id).shared_images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        print "val",val
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Shared_area.objects.get(property_id=prop_id)
        update.shared_images=new_cur_pathlist
        update.save()

##        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})


@csrf_exempt
def mon_delete_shared_img(request,file_name,prop_id,user_name,password,room_no):

        print "file_name",file_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
##        file_path ='/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative
##
##        path = '/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative

        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=room_no).shared_images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        print "val",val
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=room_no)
        update.shared_images=new_cur_pathlist
        update.save()

##        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})


@csrf_exempt
def delete_meeting_img(request,file_name,prop_id,user_name,password,room_no):

        print "file_name",file_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
##        file_path ='/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative
##
##        path = '/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative

        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Meeting_room.objects.get(property_id=prop_id,room_no=room_no).meeting_room_images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Meeting_room.objects.get(property_id=prop_id,room_no=room_no)
        update.meeting_room_images=new_cur_pathlist
        update.save()

##        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})




@csrf_exempt
def delete_training_img(request,file_name,prop_id,user_name,password,room_no):

        print "file_name",file_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
##        file_path ='/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative
##
##        path = '/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative

        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Training_room.objects.get(property_id=prop_id,training_room_no=room_no).training_room_images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Training_room.objects.get(property_id=prop_id,training_room_no=room_no)
        update.training_room_images=new_cur_pathlist
        update.save()

##        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})




@csrf_exempt
def delete_event_img(request,file_name,prop_id,user_name,password,room_no):

        print "file_name",file_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
##        file_path ='/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative
##
##        path = '/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative

        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Event_Halls.objects.get(property_id=prop_id,room_no=int(room_no)).shared_images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Event_Halls.objects.get(property_id=prop_id,room_no=room_no)
        update.shared_images=new_cur_pathlist
        update.save()

##        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})




@csrf_exempt
def delete_img(request,file_name,prop_id,user_name,password):

        print "file_name",file_name
        print "user_name...",user_name
        tmp_img_name = file_name.split('.')
        pathRelative = str(file_name)
        print "pathRelative",pathRelative

        # server path:
        
##        file_path ='/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative
##
##        path = '/home/akshay/samith/BizPit/BizPit_Backend/'+pathRelative

        # Local path

        file_path ='/var/www/BizPit/BizPit_Backend/'+pathRelative

        path = '/var/www/BizPit/BizPit_Backend/'+pathRelative
        
        print"PATHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",path
##        os.remove(path)
        del_image=Property_Details.objects.get(property_id=prop_id).images
        print "img to remove",type(del_image),del_image
        b=del_image.split(",")
        print type(b),b
        for i in range(len(b)):
              if pathRelative == b[i]:
                     print "yes"
                     print b[i]
                     val=i

              else:
                     print b[i]
                     print "no"
        
        b.pop(val)
        print "ldlkdklsd",b

        new_cur_pathlist=",".join(b)
        print "aasd",new_cur_pathlist
        update=Property_Details.objects.get(property_id=prop_id)
        update.images=new_cur_pathlist
        update.save()

####        username = request.POST["Username"]
##        password = request.POST["Password"]
##
##        print "User name and password isssssssssssss",username,password
       	email_id=[]
	
        username = user_name
        password = password
        user = username
        data=Login.objects.all()
        for d in data:
               email_id.append(str(d.email_id))
        if(user in email_id):
                user_dt=Login.objects.filter(email_id=user)
                for u_d in user_dt:
                        user_type=str(u_d.user_type)
                if(user_type == "Owner"):
                        owner="Owner"
                elif(user_type == "super_user"):
                        owner="Super-Owner"
                else:
                        owner="User"
        else:
                owner="Super-Owner"
	
        if(owner=="Owner"):
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm
        else:
                print "User name and password isssssssssssss",username,password
                data=Property_Details.objects.all().order_by('property_id')
                

                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                print "am here"
                res="Ascending"
                res1="None"
                #print "sdafsdfdsfsdf",request.POST['desc']
                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                       
                        #print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",names
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        comm_data=Submit_Comment.objects.filter(property_id=int(i.property_id))
                        if(comm_data):
                                for c in comm_data:
                                        comment.append(c.comment)
                                        rate.append(c.rate)
                        else:
                                comment.append("No comments..")
                                rate.append(" ")
                        first.append(comment)
                        comm.append(comment)
                        count=0
                        new_rate=0
        ##                print "rate",rate
                        if(rate != [' ']):
                                for r in rate:
                                       print "i",r
                                       new_rate=new_rate+float(r)
                                       count=count+1
                                avg_rate=new_rate/float(count)
                                print "avg_rate...",avg_rate
                        else:
                                avg_rate=0
                        
                        first.append(avg_rate)
                        val=Booking_Master_Table.objects.filter(property_id=int(i.property_id)).count()
                        first.append(val)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                for cc in comm:
                       if(cc != "No comments.."):
                              comm=cc
                              break
                       else:
                              comm=" "
                print "comments...",comm

        #print"result adsfasdfadsfasdfasdf",result  
        return render_to_response('my_property.html',{"property":result,"owner":"Owner","comments":comm,"user":username,"password":password})




@csrf_exempt
def delete_event_data(request):
        print "Iam in delete_event_data"
        jasonresult = {}
        jasonresult.update({"msg":"ths is done"})
        if request.POST.has_key('prop_id1'):
		prop_id = int(request.POST['prop_id1'])
		room_no = int(request.POST['room_no1'])

                data1=Event_Halls.objects.filter(property_id=int(prop_id),room_no=int(room_no))
                if(data1):
                        print "delete this adfsdfsdf"
                        print "dataaa verfasdfsd",data1
##                                                data1.delete()
                        print "data1...",data1
                        Event_Halls.objects.get(property_id=prop_id,room_no=room_no).delete()
                        print "deleted..sdfsdfsdfsdfsd"

                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        else:
                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        

@csrf_exempt
def delete_meeting_data(request):
        print "Iam in delete_meeting_data"
        jasonresult = {}
        jasonresult.update({"msg":"ths is done"})
        if request.POST.has_key('prop_id1'):
		prop_id = int(request.POST['prop_id1'])
		room_no = int(request.POST['room_no1'])

                data1=Meeting_room.objects.filter(property_id=int(prop_id),room_no=int(room_no))
                if(data1):
                        print "delete this adfsdfsdf"
                        print "dataaa verfasdfsd",data1
##                                                data1.delete()
                        print "data1...",data1
                        Meeting_room.objects.get(property_id=prop_id,room_no=room_no).delete()
                        print "deleted..sdfsdfsdfsdfsd"

                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        else:
                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")

@csrf_exempt
def delete_training_data(request):
        print "Iam in delete_training_data"
        jasonresult = {}
        jasonresult.update({"msg":"ths is done"})
        if request.POST.has_key('prop_id1'):
		prop_id = int(request.POST['prop_id1'])
		room_no = int(request.POST['room_no1'])

                data1=Training_room.objects.filter(property_id=int(prop_id),training_room_no=int(room_no))
                if(data1):
                        print "delete this adfsdfsdf"
                        print "dataaa verfasdfsd",data1
##                                                data1.delete()
                        print "data1...",data1
                        Training_room.objects.get(property_id=prop_id,training_room_no=room_no).delete()
                        print "deleted..sdfsdfsdfsdfsd"

                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        else:
                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")

@csrf_exempt
def delete_shared_data(request):

        print "Iam in delete_shared_data"
        jasonresult = {}
        jasonresult.update({"msg":"ths is done"})
        if request.POST.has_key('prop_id1'):
		prop_id = int(request.POST['prop_id1'])
		room_no = int(request.POST['room_no1'])

                data1=Shared_area.objects.filter(property_id=int(prop_id),pvt_ofc_no=int(room_no))
                if(data1):
                        print "delete this adfsdfsdf"
                        print "dataaa verfasdfsd",data1
##                                                data1.delete()
                        print "data1...",data1
                        Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=room_no).delete()
                        print "deleted..sdfsdfsdfsdfsd"

                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        else:
                return HttpResponse(json.dump(jasonresult),content_type="application/javascript")
        
