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
import string
import random
import smtplib
from django.http.response import HttpResponseRedirect, HttpResponse, \
    HttpResponseBadRequest, Http404
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
import json
from django.core.mail import send_mail
from django.core.mail.message import EmailMessage
from django.contrib.messages import constants as message_constants
from django.contrib import messages
from django.conf import settings
# Create your views here.

@csrf_exempt
def mainpage(request):

	return render_to_response('login.html')


@csrf_exempt
def reset_password(request):
    print "sucessful ********************"
    #return render(request,'reset_password.html')
    print "Hello im here!!!!!!!!!!!!!!!!!"
    return render_to_response("reset_password.html")
    

def reset_pas_mail(request):
    email_id = str(request.POST["email_id"])
    print "email**********",email_id

    if Login.objects.filter(email_id=email_id).exists():
        #print "email is present@@@@@@@@@@@@@@@@@@@@@@@@@@@@"

        
        print "mail done"
        TO = []
        send_email = []
        TO.append(str(email_id))
        send_email.append("sales@bizpit.in")
        N=10
        rand_string =''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
        password = rand_string
        obj = Login.objects.get(email_id=email_id,user_type="Owner")
        obj.password = password
        obj.save()
        
        message= "your new password is "+rand_string+" "
        emai = EmailMessage('Reset password mail',message,settings.EMAIL_HOST_USER,TO,cc=send_email)
        emai.send()

        print "email sent"
        #obj = login(email=email,password=password)
        #obj.save()
        msg = "Forgot Password successfull. \n Please check your mail.\n Please login with new Password!"
        return render(request,'login.html',{'flag':msg})

        


    else:
        msg = " Please Sign Up!\n Email id doesn't exist"
        return render_to_response('signup.html',{'flag':msg})



@csrf_exempt
def change_password(request,user1):
    #new changes here
    user=str(user1)
    print "user id is",user1
    email_id=user1
    print "email_id^^^^^^^^^^^^^^^^^^^^^^^^^^^",email_id
    
    return render(request,'change_password.html',{"user_email":email_id})

@csrf_exempt
def new_password(request,user1):
    email_id = request.POST['user_email']
    #changes heremax_capacity
    user1=str(user1)
    print user1
    #email_id=user1
    #email_id = "divyadevadu@gmail.com"
    #print "my mail",email_id
    current_password=request.POST["current_password"]
    print current_password
    new_password=request.POST["new_password"]
    print new_password
    confirm_new_password=request.POST["confirm_new_password"]
    print confirm_new_password
    try:

        obj_l= Login.objects.get(email_id=email_id,user_type="Owner")
    except:
        msg=str("Password don't match with" +email_id)
        return render(request,'change_password.html',{'flag':msg})
    cur_password=obj_l.password

    print "cur_password",cur_password



    
    if cur_password != current_password:
        msg="Password don't match!Please re-enter your current Password"
        return render(request,'change_password.html',{'flag':msg})

    elif (cur_password == current_password and new_password == confirm_new_password):


        password = new_password
        obj = Login.objects.get(email_id=email_id,user_type="Owner")
        obj.password = password
        obj.save()
        msg="Change Password Successfull!"
        return render(request,'login.html',{'flag':msg})
    elif new_password != confirm_new_password:
        msg= "Password doesnt match! Please re enter new Password"
        messages.add_message(self.request, messages.SUCCESS, 'Logged in Successfully')
        return render(request,'change_password.html',{'flag':msg})

    else:
        messages.add_message(
               self.request, messages.SUCCESS, 'Logged in Successfully')
        return render(request,'change_password.html')


import xlrd
import MySQLdb

@csrf_exempt
def bizpit_calender(property_id):
##    property_id=int(bundle.data['property_id'])
##    No_days=int(bundle.data['No_days'])
##    No_days1=No_days+1
    No_days1 = 8
##    curent_dt = str(bundle.data['Date'])
##    curent_dt1=datetime.datetime.strptime(curent_dt,("%d/%m/%Y")).strftime("%Y-%m-%d")
##    curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
    print property_id
    curent_date = datetime.date.today()
    e = datetime.timedelta(days=1)
    new_dt1 = curent_date+e
    result = []
    Booking_data = []
    room_data=[]
    booking=""
    book_capacity=0
    booked_by=""
##    for i in range(1,No_days1):
    sh=[]
    max_cap=0
    tr_room=[]
    temp_val=[]
    temp_data=[]
    result_data=[]
    prop_data = Property_Details.objects.filter(property_id=property_id)
    for p_d in prop_data:
        property_super_subtype=str(p_d.property_super_subtype)
        property_type=str(p_d.property_type)
        print "property_super_subtype,,,\t",property_super_subtype
        print "property_type...\t",property_type
        

        if("Training Room" in property_type):
            max_cap=0
            count=0
            value_Training=Training_room.objects.filter(property_id=property_id)
            for shared in value_Training :
                sh.append(shared.capacity)
                tr_room.append(shared.training_room_no)
            max_cap=sh[0]
            for sh1 in sh:
                if(sh1>max_cap):
                    max_cap=sh1
            train_data=Training_room.objects.filter(property_id=property_id)
            for pvt_data in train_data:
                count=count+1
                data_name=str(pvt_data.room_name)
                data_capacity=pvt_data.capacity
                payment_data = Payment.objects.filter(property_id=property_id)
                for p_data in payment_data:
                    print "payment object count...",payment_data.count()
##                    curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
                    curent_date = datetime.date.today()
                    booked_by_id=int(p_data.User_id)
                    log_data = Login.objects.filter(user_id=booked_by_id)
                    for l_d in log_data:
                        user_type=str(l_d.user_type)
                    if(p_data.Booking_type == "Daily" or p_data.Booking_type == "FullDay" ):
                        print "In dailyyyyyy..."
                        booking_id=p_data.Booking_id
                        daily_data=DWM_Booking.objects.filter(property_id=property_id,booking_id=booking_id,room_no=count)
                        print "dwm table object count...",daily_data.count()
                        if(daily_data):
                            for i in range(1,No_days1):
                                print "iiiiiiiiiii",i
                                for h_data in daily_data:
                                    book_date=h_data.date
                                    book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                    book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                    if(curent_date == book_date11): 
                                        book_capacity=h_data.head_count
                                        booking_date=h_data.date
                                        booking="FULL"
                                        booked_by=str(user_type)
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by}) 
                                        
                                    else:
                                        book_capacity=0
                                        booking_date=""
                                        booking=""
                                        booked_by=""
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by})

                                    #temp_data.append(Booking_data)
                                    #Booking_data=[] 
                                e = datetime.timedelta(days=1)
                                print "eeeee \t",e
                                curent_date = curent_date+e
                                print "curent_date \t",curent_date

                            Booking_data1=map(lambda x: str(x),Booking_data)
                            Booking_data11=list(set(Booking_data1))
                            Booking_data111=map(lambda x: eval(x),Booking_data11)
                            temp_val.append(Booking_data111)
                            Booking_data=[]

                    if(p_data.Booking_type == "HalfDay"):
                        print "In halfday..."
                        booking_id=p_data.Booking_id
                        daily_data=Hourly_Halfday_Booking.objects.filter(property_id=property_id,booking_type="HalfDay",booking_id=booking_id,room_no=count)
                        print "halfday table object count...",daily_data.count()
                        if(daily_data):
                            for i in range(1,No_days1):
                                print "iiiiiiiiiii",i
                                for h_data in daily_data:
                                    book_date=h_data.date
                                    book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                    book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                    if(curent_date == book_date11): 
                                        book_capacity=h_data.head_count
                                        booking_date=h_data.date
                                        booking=str(h_data.duration)
                                        booked_by=str(user_type)
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by}) 
                                        
                                    else:
                                        book_capacity=0
                                        booking_date=""
                                        booking=""
                                        booked_by=""
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by})

                                    #temp_data.append(Booking_data)
                                    #Booking_data=[]
                                e = datetime.timedelta(days=1)
                                print "eeeee \t",e
                                curent_date = curent_date+e
                                print "curent_date \t",curent_date
                                
                            Booking_data1=map(lambda x: str(x),Booking_data)
                            Booking_data11=list(set(Booking_data1))
                            Booking_data111=map(lambda x: eval(x),Booking_data11)
                            temp_val.append(Booking_data111)
                            Booking_data=[]
                room_val=str(count)
                room_data={}
                room_data.update({"Room_no":room_val,
                                  "Name":data_name,
                                  "Type":"Training Room",
                                  "Max_capacity":data_capacity,
                                  "booking_data":temp_val})
                result_data.append(room_data)
                temp_val=[]
                room_data={}

        if("Event_Hall" in property_type):
            max_cap=0
            count=0
            value_Training=Event_Halls.objects.filter(property_id=property_id)
            for shared in value_Training :
                sh.append(shared.capacity)
                tr_room.append(shared.room_no)
            max_cap=sh[0]
            for sh1 in sh:
                if(sh1>max_cap):
                    max_cap=sh1
            train_data=Event_Halls.objects.filter(property_id=property_id)
            for pvt_data in train_data:
                count=count+1
                data_name=str(pvt_data.room_name)
                data_capacity=pvt_data.capacity
                payment_data = Payment.objects.filter(property_id=property_id)
                for p_data in payment_data:
                    print "payment object count...",payment_data.count()
##                    curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
                    curent_date = datetime.date.today()
                    booked_by_id=int(p_data.User_id)
                    log_data = Login.objects.filter(user_id=booked_by_id)
                    for l_d in log_data:
                        user_type=str(l_d.user_type)
                    if(p_data.Booking_type == "Daily" or p_data.Booking_type == "FullDay" ):
                        print "In dailyyyyyy..."
                        booking_id=p_data.Booking_id
                        daily_data=DWM_Booking.objects.filter(property_id=property_id,booking_id=booking_id,room_no=count)
                        print "dwm table object count...",daily_data.count()
                        if(daily_data):
                            for i in range(1,No_days1):
                                print "iiiiiiiiiii",i
                                for h_data in daily_data:
                                    book_date=h_data.date
                                    book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                    book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                    if(curent_date == book_date11): 
                                        book_capacity=h_data.head_count
                                        booking_date=h_data.date
                                        booking="FULL"
                                        booked_by=str(user_type)
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by}) 
                                        
                                    else:
                                        book_capacity=0
                                        booking_date=""
                                        booking=""
                                        booked_by=""
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by})

                                    #temp_data.append(Booking_data)
                                    #Booking_data=[]
                                e = datetime.timedelta(days=1)
                                print "eeeee \t",e
                                curent_date = curent_date+e
                                print "curent_date \t",curent_date

                            Booking_data1=map(lambda x: str(x),Booking_data)
                            Booking_data11=list(set(Booking_data1))
                            Booking_data111=map(lambda x: eval(x),Booking_data11)
                            temp_val.append(Booking_data111)
                            Booking_data=[]

                    if(p_data.Booking_type == "HalfDay"):
                        print "In halfday..."
                        booking_id=p_data.Booking_id
                        daily_data=Hourly_Halfday_Booking.objects.filter(property_id=property_id,booking_type="HalfDay",booking_id=booking_id,room_no=count)
                        print "halfday table object count...",daily_data.count()
                        if(daily_data):
                            for i in range(1,No_days1):
                                print "iiiiiiiiiii",i
                                for h_data in daily_data:
                                    book_date=h_data.date
                                    book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                    book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                    if(curent_date == book_date11): 
                                        book_capacity=h_data.head_count
                                        booking_date=h_data.date
                                        booking=str(h_data.duration)
                                        booked_by=str(user_type)
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by}) 
                                        
                                    else:
                                        book_capacity=0
                                        booking_date=""
                                        booking=""
                                        booked_by=""
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by})

                                    #temp_data.append(Booking_data)
                                    #Booking_data=[]
                                e = datetime.timedelta(days=1)
                                print "eeeee \t",e
                                curent_date = curent_date+e
                                print "curent_date \t",curent_date
                                
                            Booking_data1=map(lambda x: str(x),Booking_data)
                            Booking_data11=list(set(Booking_data1))
                            Booking_data111=map(lambda x: eval(x),Booking_data11)
                            temp_val.append(Booking_data111)
                            Booking_data=[]
                room_val=str(count)
                room_data={}
                room_data.update({"Room_no":room_val,
                                  "Name":data_name,
                                  "Type":"Event_Hall",
                                  "Max_capacity":data_capacity,
                                  "booking_data":temp_val})
                result_data.append(room_data)
                temp_val=[]
                room_data={}

        if("Meeting_Room" in property_type):
            max_cap=0
            count=0
            value_Training=Meeting_room.objects.filter(property_id=property_id)
            for shared in value_Training :
                sh.append(shared.capacity)
                tr_room.append(shared.room_no)
            max_cap=sh[0]
            for sh1 in sh:
                if(sh1>max_cap):
                    max_cap=sh1
            train_data=Meeting_room.objects.filter(property_id=property_id)
            for pvt_data in train_data:
                count=count+1
                data_name=str(pvt_data.room_name)
                data_capacity=pvt_data.capacity
                payment_data = Payment.objects.filter(property_id=property_id)
                for p_data in payment_data:
                    print "payment object count...",payment_data.count()
##                    curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
                    curent_date = datetime.date.today()
                    booked_by_id=int(p_data.User_id)
                    log_data = Login.objects.filter(user_id=booked_by_id)
                    for l_d in log_data:
                        user_type=str(l_d.user_type)
                    if(p_data.Booking_type == "Daily" or p_data.Booking_type == "FullDay" or p_data.Booking_type == "Weekly" or p_data.Booking_type == "Monthly" ):
                        print "In dailyyyyyy..."
                        booking_id=p_data.Booking_id
                        daily_data=DWM_Booking.objects.filter(property_id=property_id,booking_id=booking_id,room_no=count)
                        print "dwm table object count...",daily_data.count()
                        if(daily_data):
                            for i in range(1,No_days1):
                                print "iiiiiiiiiii",i
                                for h_data in daily_data:
                                    book_date=h_data.date
                                    book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                    book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                    if(curent_date == book_date11): 
                                        book_capacity=h_data.head_count
                                        booking_date=h_data.date
                                        booking="FULL"
                                        booked_by=str(user_type)
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by}) 
                                        
                                    else:
                                        book_capacity=0
                                        booking_date=""
                                        booking=""
                                        booked_by=""
                                        Booking_data.append({"booking_id":booking_id,
                                                             "date":str(curent_date),
                                                             "booking":booking,
                                                             "book_capacity":book_capacity,
                                                             "booked_by":booked_by})

                                    #temp_data.append(Booking_data)
                                    #Booking_data=[]
                                e = datetime.timedelta(days=1)
                                print "eeeee \t",e
                                curent_date = curent_date+e
                                print "curent_date \t",curent_date

                            Booking_data1=map(lambda x: str(x),Booking_data)
                            Booking_data11=list(set(Booking_data1))
                            Booking_data111=map(lambda x: eval(x),Booking_data11)
                            temp_val.append(Booking_data111)
                            Booking_data=[]

                    
                room_val=str(count)
                room_data={}
                room_data.update({"Room_no":room_val,
                                  "Name":data_name,
                                  "Type":"Meeting_Room",
                                  "Max_capacity":data_capacity,
                                  "booking_data":temp_val})
                result_data.append(room_data)
                temp_val=[]
                room_data={}

        if("Plug & Play" in property_type):
            max_cap=0
            count=0
            value_Training=Shared_area.objects.filter(property_id=property_id)
            for shared in value_Training :
                sh.append(shared.capacity)
                tr_room.append(shared.pvt_ofc_no)
            max_cap=sh[0]
            for sh1 in sh:
                if(sh1>max_cap):
                    max_cap=sh1
            if(property_super_subtype == "Pvt_Ofc"):
                train_data=Shared_area.objects.filter(property_id=property_id)
                for pvt_data in train_data:
                    count=count+1
                    data_name=str(pvt_data.room_name)
                    data_capacity=pvt_data.capacity
                    payment_data = Payment.objects.filter(property_id=property_id)
                    for p_data in payment_data:
                        print "payment object count...",payment_data.count()
##                        curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
                        curent_date = datetime.date.today()
                        booked_by_id=int(p_data.User_id)
                        log_data = Login.objects.filter(user_id=booked_by_id)
                        for l_d in log_data:
                            user_type=str(l_d.user_type)
                        if(p_data.Booking_type == "Daily" or p_data.Booking_type == "FullDay" or p_data.Booking_type == "Weekly" or p_data.Booking_type == "Monthly" ):
                            print "In dailyyyyyy..."
                            booking_id=p_data.Booking_id
                            daily_data=DWM_Booking.objects.filter(property_id=property_id,booking_id=booking_id,room_no=count)
                            print "dwm table object count...",daily_data.count()
                            if(daily_data):
                                for i in range(1,No_days1):
                                    print "iiiiiiiiiii",i
                                    for h_data in daily_data:
                                        book_date=h_data.date
                                        book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                        book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                        if(curent_date == book_date11): 
                                            book_capacity=h_data.head_count
                                            booking_date=h_data.date
                                            booking="FULL"
                                            booked_by=str(user_type)
                                            Booking_data.append({"booking_id":booking_id,
                                                                 "date":str(curent_date),
                                                                 "booking":booking,
                                                                 "book_capacity":book_capacity,
                                                                 "booked_by":booked_by}) 
                                            
                                        else:
                                            book_capacity=0
                                            booking_date=""
                                            booking=""
                                            booked_by=""
                                            Booking_data.append({"booking_id":booking_id,
                                                                 "date":str(curent_date),
                                                                 "booking":booking,
                                                                 "book_capacity":book_capacity,
                                                                 "booked_by":booked_by})

                                        #temp_data.append(Booking_data)
                                        #Booking_data=[]
                                    e = datetime.timedelta(days=1)
                                    print "eeeee \t",e
                                    curent_date = curent_date+e
                                    print "curent_date \t",curent_date

                                Booking_data1=map(lambda x: str(x),Booking_data)
                                Booking_data11=list(set(Booking_data1))
                                Booking_data111=map(lambda x: eval(x),Booking_data11)
                                temp_val.append(Booking_data111)
                                Booking_data=[]

                        
                    room_val=str(count)
                    room_data={}
                    room_data.update({"Room_no":room_val,
                                      "Name":data_name,
                                      "Type":"Pvt_Ofc",
                                      "Max_capacity":data_capacity,
                                      "booking_data":temp_val})
                    result_data.append(room_data)
                    temp_val=[]
                    room_data={}
                    
            else:

                print "In elseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
                train_data=Shared_area.objects.filter(property_id=property_id)
                for pvt_data in train_data:
                    count=count+1
                    data_name=str(pvt_data.room_name)
                    data_capacity=pvt_data.capacity
                    payment_data = Payment.objects.filter(property_id=property_id)
                    for p_data in payment_data:
                        print "payment object count...",payment_data.count()
##                        curent_date=datetime.datetime.strptime(curent_dt1,("%Y-%m-%d"))
                        curent_date = datetime.date.today()
                        booked_by_id=int(p_data.User_id)
                        log_data = Login.objects.filter(user_id=booked_by_id)
                        for l_d in log_data:
                            user_type=str(l_d.user_type)
                        if(p_data.Booking_type == "Daily" or p_data.Booking_type == "FullDay" or p_data.Booking_type == "Weekly" ):
                            print "In dailyyyyyy..."
                            booking_id=p_data.Booking_id
                            daily_data=DWM_Booking.objects.filter(property_id=property_id,booking_id=booking_id)
                            print "dwm table object count...",daily_data.count()
                            if(daily_data):
                                for i in range(1,No_days1):
                                    print "iiiiiiiiiii",i
                                    for h_data in daily_data:
                                        book_date=h_data.date
                                        book_date1=datetime.datetime.strptime(book_date,("%d/%m/%Y")).strftime("%Y-%m-%d")
                                        book_date11=datetime.datetime.strptime(book_date1,("%Y-%m-%d"))
                                        if(curent_date == book_date11): 
                                            book_capacity=h_data.head_count
                                            booking_date=h_data.date
                                            booking="FULL"
                                            booked_by=str(user_type)
                                            Booking_data.append({"booking_id":booking_id,
                                                                 "date":str(curent_date),
                                                                 "booking":booking,
                                                                 "book_capacity":book_capacity,
                                                                 "booked_by":booked_by}) 
                                            
                                        else:
                                            book_capacity=0
                                            booking_date=""
                                            booking=""
                                            booked_by=""
                                            Booking_data.append({"booking_id":booking_id,
                                                                 "date":str(curent_date),
                                                                 "booking":booking,
                                                                 "book_capacity":book_capacity,
                                                                 "booked_by":booked_by})

                                        #temp_data.append(Booking_data)
                                        #Booking_data=[]
                                    e = datetime.timedelta(days=1)
                                    print "eeeee \t",e
                                    curent_date = curent_date+e
                                    print "curent_date \t",curent_date

                                Booking_data1=map(lambda x: str(x),Booking_data)
                                Booking_data11=list(set(Booking_data1))
                                Booking_data111=map(lambda x: eval(x),Booking_data11)
                                
                                temp_val.append(Booking_data111)                                
                                Booking_data=[]

                        
                    room_val="room_"+str(count)
                    room_data={}
                    room_data.update({"Room_no":room_val,
                                      "Name":data_name,
                                      "Type":"Hot_Seat",
                                      "Max_capacity":data_capacity,
                                      "booking_data":temp_val})
                    result_data.append(room_data)
                    temp_val=[]
                    room_data={}
        return result_data 

@csrf_exempt
def calendar_page(request,user1,password):
        print "username is",user1,type(user1)
        user=str(user1)
        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 = str(request.POST.get('id_of_ownerr',False))
##        username_new = str(request.POST.get('user_1',False))
##        username=username_new.lower()
##        password = request.POST.get('password',False)             
##	email_id=[]
##	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"	
	if(owner=="Owner"):
                
                
                data=Property_Details.objects.filter(submitted_by=user).order_by('property_id')
                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                pro_result = []
                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)
                        prop_typ_list=str(i.property_type)
                        address=i.address
##                        print "prop_typ_list.......",prop_typ_list
                        typ_list=prop_typ_list.split(",")
                        prop_subtype=str(i.property_super_subtype)
##                        print "type_list--->",typ_list		
                        for pt in typ_list:
##                                print "pt in p_type1---->",pt

                                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
##                        print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",i.property_name			
                        first.append(i.property_name)                        
                        first.append(i.address)
                        first.append(my_val_plug)
                        first.append(my_val_Training)
                        first.append(my_val_meeting)
                        first.append(my_val_event)
##                        first.append(prop_subtype)
                        result.append(first)                        
                        first=[]
                        comment=[]
                        rate=[]
                pro_result.append(result[0])
                book_data = []
                book_data = bizpit_calender(pro_result[0][0])
                print "book_data",book_data
                dates = []
                ct = datetime.date.today()                
                dates.append(str(ct))
                for i in range(6):
                        e = datetime.timedelta(days=1)
                        ct = ct+e
                        dates.append(str(ct))
                a = []
                b = []
                c = []
                d = []
                e = []
                f = []
                g = []
                for i in range(len(book_data)):
                        a.append(book_data[i]['Type'])                       
                        a.append(book_data[i]['Max_capacity'])                        
                        try:
                                a.append(book_data[i]['booking_data'][0][0]['book_capacity'])
                                a.append(book_data[i]['booking_data'][0][0]['date'])
                                a.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                a.append('0')
                                a.append('0')
                                a.append('0')
                        b.append(book_data[i]['Type'])
                        b.append(book_data[i]['Max_capacity'])                        
                        try:
                                b.append(book_data[i]['booking_data'][0][1]['book_capacity'])
                                b.append(book_data[i]['booking_data'][0][1]['date'])
                                b.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                b.append('0')
                                b.append('0')
                                b.append('0')
                        c.append(book_data[i]['Type'])
                        c.append(book_data[i]['Max_capacity'])                        
                        try:
                                c.append(book_data[i]['booking_data'][0][2]['book_capacity'])
                                c.append(book_data[i]['booking_data'][0][2]['date'])
                                c.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                c.append('0')
                                c.append('0')
                                c.append('0')
                        d.append(book_data[i]['Type'])
                        d.append(book_data[i]['Max_capacity'])                        
                        try:
                                d.append(book_data[i]['booking_data'][0][3]['book_capacity'])
                                d.append(book_data[i]['booking_data'][0][3]['date'])
                                d.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                d.append('0')
                                d.append('0')
                                d.append('0')
                        e.append(book_data[i]['Type'])
                        e.append(book_data[i]['Max_capacity'])                        
                        try:
                                e.append(book_data[i]['booking_data'][0][4]['book_capacity'])
                                e.append(book_data[i]['booking_data'][0][4]['date'])
                                e.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                e.append('0')
                                e.append('0')
                                e.append('0')
                        f.append(book_data[i]['Type'])
                        f.append(book_data[i]['Max_capacity'])                        
                        try:
                                f.append(book_data[i]['booking_data'][0][5]['book_capacity'])
                                f.append(book_data[i]['booking_data'][0][5]['date'])
                                f.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                f.append('0')
                                f.append('0')
                                f.append('0')
                        g.append(book_data[i]['Type'])
                        g.append(book_data[i]['Max_capacity'])                       
                        try:
                                g.append(book_data[i]['booking_data'][0][6]['book_capacity'])
                                g.append(book_data[i]['booking_data'][0][6]['date'])
                                g.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                g.append('0')
                                g.append('0')
                                g.append('0')
                        
                final_data=[]
                final_data.append(a)
                final_data.append(b)
                final_data.append(c)
                final_data.append(d)
                final_data.append(e)
                final_data.append(f)
                final_data.append(g)
                print "book_data",book_data

                dates = []
                ct = datetime.date.today()                
                dates.append(str(ct))
                for i in range(6):
                    e = datetime.timedelta(days=1)
                    ct = ct+e
                    dates.append(str(ct))
                
                print "Bookings_data************************************\n",final_data
                print "pro_result########################################\n",pro_result
                print "a valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",a
                print "b valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",b
                print "c valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",c
                print "d valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",d
                print "e valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",e
                print "f valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",f
                print "g valueee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n",g
                print "dates...............................................\n",dates
##                print "result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",result

                tr_room = []
                ev_room = []
                meet_room = []
                po_room = []
                hs_room = []
                tr_room1 = []
                ev_room1 = []
                meet_room1 = []
                po_room1 = []
                hs_room1 = []
                tr_room2 = []
                ev_room2 = []
                meet_room2 = []
                po_room2 = []
                hs_room2 = []
                k = 0
                i = 0
                p = 0
                for k in range(len(book_data)):
                    print type(book_data[0]['Type'])
                    if (book_data[k]['Type'] == "Training Room"):
                        print "in training room"        
                ##        if fl_tr:
                        tr_room1.append(book_data[k]['Type'])            
                ##            fl_tr = 0        
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                tr_room1.append(book_data[k]['Room_no'])
                                tr_room1.append(dates[i])
                                tr_room1.append('0')
                                tr_room1.append('0')
                                tr_room1.append('0')
                        else:
                            for i in range(7):
                ##                tr_room1.append(book_data[k]['Room_no'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['date'])
                ##                tr_room1.append(book_data[k]['Max_capacity'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            tr_room1.append(book_data[k]['Room_no'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            tr_room1.append(book_data[k]['Max_capacity'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        tr_room.append(tr_room1)
                        tr_room1 = []

                    elif(book_data[k]['Type'] is "Event_Hall"):        
                        print "in event hall"
                ##        if fl_ev:
                        ev_room1.append(book_data[k]['Type'])
                ##            fl_ev = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                ev_room1.append(book_data[k]['Room_no'])
                                ev_room1.append(dates[i])
                                ev_room1.append('0')
                                ev_room1.append('0')
                                ev_room1.append('0')
                        else:
                            for i in range(7):
                ##                ev_room.append(book_data[k]['Room_no'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                ev_room.append(book_data[k]['Max_capacity'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            ev_room1.append(book_data[k]['Room_no'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            ev_room1.append(book_data[k]['Max_capacity'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        ev_room.append(ev_room1)
                        meet_room1 = []
                                

                    elif(book_data[k]['Type'] is "Meeting_Room"):        
                        print "in meeting room"
                ##        if fl_mt:
                        meet_room1.append(book_data[k]['Type'])
                ##            fl_mt = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                meet_room1.append(book_data[k]['Room_no'])
                                meet_room1.append(dates[i])
                                meet_room1.append('0')
                                meet_room1.append('0')
                                meet_room1.append('0')
                        else:
                            for i in range(7):
                ##                meet_room.append(book_data[k]['Room_no'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                meet_room.append(book_data[k]['Max_capacity'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            meet_room1.append(book_data[k]['Room_no'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            meet_room1.append(book_data[k]['Max_capacity'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        meet_room.append(meet_room1)
                        meet_room1 = []
                          

                    elif(book_data[k]['Type'] is "Hot_Seat"):        
                        print "in hot seat"
                ##        if fl_hs:
                        hs_room1.append(book_data[k]['Type'])
                ##            fl_hs = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                hs_room1.append(book_data[k]['Room_no'])
                                hs_room1.append(dates[i])
                                hs_room1.append(book_data[k]['Max_capacity'])
                                hs_room1.append('0')
                                hs_room1.append('0')
                        else:
                            for i in range(7):
                ##                hs_room.append(book_data[k]['Room_no'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                hs_room.append(book_data[k]['Max_capacity'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            hs_room1.append(book_data[k]['Room_no'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            hs_room1.append(book_data[k]['Max_capacity'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        hs_room.append(hs_room1)
                        hs_room1 = []

                    elif(book_data[k]['Type'] is "Pvt_Ofc"):        
                        print "in pvt ofc"
                ##        if fl_po:
                        po_room1.append(book_data[k]['Type'])
                ##            fl_po = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                po_room1.append(book_data[k]['Room_no'])
                                po_room1.append(dates[i])
                                po_room1.append('0')
                                po_room1.append('0')
                                po_room1.append('0')
                        else:
                            for i in range(7):
                ##                po_room.append(book_data[k]['Room_no'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                po_room.append(book_data[k]['Max_capacity'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            po_room1.append(book_data[k]['Room_no'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            po_room1.append(book_data[k]['Max_capacity'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        po_room.append(po_room1)
                        po_room1 = []
                            

                    else:
                        print "in else"
                        print book_data[k]['Type']
                        print type(book_data[k]['Type'])
                        pass
                if not hs_room:
                        pass
                else:
                        pro_result[0].append('Hot_Seat')
                if not po_room:
                        pass
                else:
                        pro_result[0].append('Pvt_Ofc')
                print tr_room
                print ev_room
                print meet_room
                print hs_room
                print po_room

                return render_to_response('Calendar.html',{"proresult":pro_result,"property":result,"dates":dates,"booking_data":final_data,"my_val_plug":my_val_plug,
                                                           "my_val_Training":my_val_Training,"my_val_event":my_val_event,
                                                           "my_val_meeting":my_val_meeting,"tr_room":tr_room,
                                                           "ev_room":ev_room,"meet_room":meet_room,"hs_room":hs_room,"po_room":po_room,
                                                           "owner":owner,"user":user,"a":a,"b":b,"c":c,"d":d,"e":e,"f":f,"g":g,"password":password})

@csrf_exempt
def calendar_filter(request):        
        owner = str(request.POST.get('id_of_ownerr',False))
        username_new = str(request.POST.get('user_1',False))
        username=username_new.lower()
        password = request.POST.get('password',False)
        prop_id_flt = request.POST.get('prop_id',False)
        prop_id_flt = int(prop_id_flt)        
##	email_id=[]
##	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"	
	if(owner=="Owner"):
                
                
                data=Property_Details.objects.filter(submitted_by=username).order_by('property_id')
                result=[]
                result1=[]
                first=[]
                names=[]
                comment=[]
                comm=[]
                rate=[]
                pro_result1 = []
                res="Ascending"
                res1="None"


                for i in data:
                        first.append(i.property_id)
                        
                        temp = int(i.property_id)
                        names.append(i.property_name)
                        prop_typ_list=str(i.property_type)
                        prop_subtype=str(i.property_super_subtype)
                        address=i.address

                        typ_list=prop_typ_list.split(",")
                        for pt in typ_list:
                                if 'Plug & Play' in typ_list:
                                         my_val_plug = "Plug & Play"
                                else:
                                         my_val_plug = "none"
                                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"
                                else:
                                         my_val_meeting = "none"
                        first.append(i.property_name)                        
                        first.append(i.address)
                        first.append(my_val_plug)
                        first.append(my_val_Training)
                        first.append(my_val_meeting)
                        first.append(my_val_event)
##                        first.append(prop_subtype)
                        result.append(first)                        
                        first=[]
                        comment=[]
                        rate=[]
                for prop_id1 in result:                    
                    if (prop_id_flt == int(prop_id1[0])):
                        pro_result1.append(prop_id1)
                        pr_ID = prop_id1[0]
                book_data = []
                book_data = bizpit_calender(pr_ID)
                print "book_data",book_data
                dates = []
                ct = datetime.date.today()                
                dates.append(str(ct))
                for i in range(6):                        
                        e = datetime.timedelta(days=1)
                        ct = ct+e
                        dates.append(str(ct))
##                print "dates",dates
##                type1 = []
##                book_capacity = []
##                date = []
##                max_capacity = []
##                for i in range(7):
##                        type1.append(book_data[0]['Type'])
##                        max_capacity.append(book_data[0]['Max_capacity'])
##                        book_capacity.append(book_data[0]['booking_data'][0][i]['book_capacity'])
##                        date.append(book_data[0]['booking_data'][0][i]['date'])
##                final_data=[]
##                final_data.append(date)
##                final_data.append(book_capacity)
##                final_data.append(max_capacity)
##                final_data.append(type1)
##                print "book_data",final_data

                a = []
                b = []
                c = []
                d = []
                e = []
                f = []
                g = []
                for i in range(len(book_data)):
                        a.append(book_data[i]['Type'])                 
                        a.append(book_data[i]['Max_capacity'])                        
                        try:
                                a.append(book_data[i]['booking_data'][0][0]['book_capacity'])
                                a.append(book_data[i]['booking_data'][0][0]['date'])
                                a.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                a.append('0')
                                a.append('0')
                                a.append('0')
                        b.append(book_data[i]['Type'])
                        b.append(book_data[i]['Max_capacity'])                        
                        try:
                                b.append(book_data[i]['booking_data'][0][1]['book_capacity'])
                                b.append(book_data[i]['booking_data'][0][1]['date'])
                                b.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                b.append('0')
                                b.append('0')
                                b.append('0')
                        c.append(book_data[i]['Type'])
                        c.append(book_data[i]['Max_capacity'])                        
                        try:
                                c.append(book_data[i]['booking_data'][0][2]['book_capacity'])
                                c.append(book_data[i]['booking_data'][0][2]['date'])
                                c.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                c.append('0')
                                c.append('0')
                                c.append('0')
                        d.append(book_data[i]['Type'])
                        d.append(book_data[i]['Max_capacity'])                        
                        try:
                                d.append(book_data[i]['booking_data'][0][3]['book_capacity'])
                                d.append(book_data[i]['booking_data'][0][3]['date'])
                                d.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                d.append('0')
                                d.append('0')
                                d.append('0')
                        e.append(book_data[i]['Type'])
                        e.append(book_data[i]['Max_capacity'])                        
                        try:
                                e.append(book_data[i]['booking_data'][0][4]['book_capacity'])
                                e.append(book_data[i]['booking_data'][0][4]['date'])
                                e.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                e.append('0')
                                e.append('0')
                                e.append('0')
                        f.append(book_data[i]['Type'])
                        f.append(book_data[i]['Max_capacity'])                        
                        try:
                                f.append(book_data[i]['booking_data'][0][5]['book_capacity'])
                                f.append(book_data[i]['booking_data'][0][5]['date'])
                                f.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                f.append('0')
                                f.append('0')
                                f.append('0')
                        g.append(book_data[i]['Type'])
                        g.append(book_data[i]['Max_capacity'])                       
                        try:
                                g.append(book_data[i]['booking_data'][0][6]['book_capacity'])
                                g.append(book_data[i]['booking_data'][0][6]['date'])
                                g.append(book_data[i]['booking_data'][0][6]['booking'])
                        except:
                                g.append('0')
                                g.append('0')
                                g.append('0')
                final_data=[]
                final_data.append(a)
                final_data.append(b)
                final_data.append(c)
                final_data.append(d)
                final_data.append(e)
                final_data.append(f)
                final_data.append(g)
##                print "book_data",final_data
                tr_room = []
                ev_room = []
                meet_room = []
                po_room = []
                hs_room = []
                tr_room1 = []
                ev_room1 = []
                meet_room1 = []
                po_room1 = []
                hs_room1 = []
                tr_room2 = []
                ev_room2 = []
                meet_room2 = []
                po_room2 = []
                hs_room2 = []
                k = 0
                i = 0
                p = 0
                for k in range(len(book_data)):
                    if (book_data[k]['Type'] == "Training Room"):
                        print "in training room"        
                ##        if fl_tr:
                        tr_room1.append(book_data[k]['Type'])            
                ##            fl_tr = 0        
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                tr_room1.append(book_data[k]['Room_no'])
                                tr_room1.append(dates[i])
                                tr_room1.append('0')
                                tr_room1.append('0')
                                tr_room1.append('0')
                        else:
                            for i in range(7):
                ##                tr_room1.append(book_data[k]['Room_no'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['date'])
                ##                tr_room1.append(book_data[k]['Max_capacity'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                tr_room1.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            tr_room1.append(book_data[k]['Room_no'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            tr_room1.append(book_data[k]['Max_capacity'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            tr_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        tr_room.append(tr_room1)
                        tr_room1 = []

                    elif(book_data[k]['Type'] is "Event_Hall"):        
                        print "in event hall"
                ##        if fl_ev:
                        ev_room1.append(book_data[k]['Type'])
                ##            fl_ev = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                ev_room1.append(book_data[k]['Room_no'])
                                ev_room1.append(dates[i])
                                ev_room1.append('0')
                                ev_room1.append('0')
                                ev_room1.append('0')
                        else:
                            for i in range(7):
                ##                ev_room.append(book_data[k]['Room_no'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                ev_room.append(book_data[k]['Max_capacity'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                ev_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            ev_room1.append(book_data[k]['Room_no'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            ev_room1.append(book_data[k]['Max_capacity'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            ev_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        ev_room.append(ev_room1)
                        meet_room1 = []
                                

                    elif(book_data[k]['Type'] is "Meeting_Room"):        
                        print "in meeting room"
                ##        if fl_mt:
                        meet_room1.append(book_data[k]['Type'])
                ##            fl_mt = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                meet_room1.append(book_data[k]['Room_no'])
                                meet_room1.append(dates[i])
                                meet_room1.append('0')
                                meet_room1.append('0')
                                meet_room1.append('0')
                        else:
                            for i in range(7):
                ##                meet_room.append(book_data[k]['Room_no'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                meet_room.append(book_data[k]['Max_capacity'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                meet_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            meet_room1.append(book_data[k]['Room_no'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            meet_room1.append(book_data[k]['Max_capacity'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            meet_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        meet_room.append(meet_room1)
                        meet_room1 = []
                          

                    elif(book_data[k]['Type'] is "Hot_Seat"):        
                        print "in hot seat"
                ##        if fl_hs:
                        hs_room1.append(book_data[k]['Type'])
                ##            fl_hs = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                hs_room1.append(book_data[k]['Room_no'])
                                hs_room1.append(dates[i])
                                hs_room1.append(book_data[k]['Max_capacity'])
                                hs_room1.append('0')
                                hs_room1.append('0')
                        else:
                            for i in range(7):
                ##                hs_room.append(book_data[k]['Room_no'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                hs_room.append(book_data[k]['Max_capacity'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                hs_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            hs_room1.append(book_data[k]['Room_no'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            hs_room1.append(book_data[k]['Max_capacity'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            hs_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        hs_room.append(hs_room1)
                        hs_room1 = []

                    elif(book_data[k]['Type'] is "Pvt_Ofc"):        
                        print "in pvt ofc"
                ##        if fl_po:
                        po_room1.append(book_data[k]['Type'])
                ##            fl_po = 0
                        if not book_data[k]['booking_data']:
                            for i in range(7):
                                po_room1.append(book_data[k]['Room_no'])
                                po_room1.append(dates[i])
                                po_room1.append('0')
                                po_room1.append('0')
                                po_room1.append('0')
                        else:
                            for i in range(7):
                ##                po_room.append(book_data[k]['Room_no'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['date'])
                ##                po_room.append(book_data[k]['Max_capacity'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['book_capacity'])
                ##                po_room.append(book_data[k]['booking_data'][0][i]['booking'])
                                for p in range(7):
                                    if (dates[i] == book_data[k]['booking_data'][0][p]['date']):
                                        if dates[i] in tr_room1:
                                            pass
                                        else:                            
                                            po_room1.append(book_data[k]['Room_no'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['date'])
                                            po_room1.append(book_data[k]['Max_capacity'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['book_capacity'])
                                            po_room1.append(book_data[k]['booking_data'][0][p]['booking'])
                                    else:
                                        pass
                        po_room.append(po_room1)
                        po_room1 = []
                            

                    else:
                        print "in else"
                        print book_data[k]['Type']
                        print type(book_data[k]['Type'])
                        pass
                if not hs_room:
                        pass
                else:
                        pro_result1[0].append('Hot_Seat')
                if not po_room:
                        pass
                else:
                        pro_result1[0].append('Pvt_Ofc')
                
                print tr_room
                print ev_room
                print meet_room
                print hs_room
                print po_room

                html = render_to_string("cal_flt.html",{"proresult":pro_result1,"dates":dates,
                                                        "a":a,"b":b,"c":c,"d":d,"e":e,"f":f,"g":g,
                                                        "tr_room":tr_room,"ev_room":ev_room,
                                                        "meet_room":meet_room,"hs_room":hs_room,"po_room":po_room})
                return HttpResponse(html)
       
@csrf_exempt
def calendar_popup(request):

        p_id = request.POST["Property_Id"]
        print"valuerererererer",p_id
        return render_to_response('mainpage.html',{})


@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["user1"]
	password=request.POST["password1"]
	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"]
        print "non_week_day............",non_week_day
        return render_to_response('add_property2.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["user1"]
        password=request.POST["Password1"]
	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
        my_val_plug=""
        my_val_Training=""
        my_val_event=""
        my_val_meeting=""
	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"]
	try:
                sub_type=request.POST["sub_type"]
        except:
                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"]
        prop_url=request.POST["prop_url"]
	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,prop_url=str(prop_url),
                              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()

        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
	
	
                
        prop_id=myid
	print "property id.........",prop_id

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

                print "In Plug and Play sectionnnnnnnnnnnnn"

                try:
                        super_sub_type=request.POST["super_sub_type"]
                except:
                        super_sub_type=""
                print "super_sub_type...............\n",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=int(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

                                try:
                                        shared_name=request.POST["name1_pvt"]
                                except:
                                        shared_name="Private Office 1"

                                try:
                                        shared_description=request.POST["description1_pvt"]
                                except:
                                        shared_description=""

                                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,
                                                         room_name=shared_name,
                                                         shared_description=shared_description,
                                                         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)
                                        name_val="name_pvt_"+str(i)
                                        description_val="description_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

                                        try:
                                                new_name=request.POST[name_val]
                                        except:
                                                new_name="Private Office "+str(i+1)

                                        try:
                                                new_desc=request.POST[description_val]
                                        except:
                                                new_desc=""
                                        
                                        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,
                                                                      room_name=new_name,
                                                                      shared_description=new_desc,
                                                                      rate_monthly=new_shared_monthly,
                                                                      shared_images=new_cur_pathlist11)

                                                new_data1.save()
                                                count=count+1

                        else:
                                print "In else of pvt ofc"

                                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

                                try:
                                        shared_name=request.POST["name1_pvt"]
                                except:
                                        shared_name="Private Office 1"

                                try:
                                        shared_description=request.POST["description1_pvt"]
                                except:
                                        shared_description=""

                                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,
                                                         room_name=shared_name,
                                                         shared_description=shared_description,
                                                         rate_monthly=shared_monthly,shared_images=new_cur_pathlist)

                                        data.save()

                        

                else:

                        try:
                                shared_capacity=request.POST["capacity"]
                                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):

                print "In Meeting Rooom Sectionnnnnnnnnnnnnnnnn"
                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

                        try:
                                name_meet=request.POST["name1_meet"]
                        except:
                                name_meet="Meeting Room 1"

                        try:
                                desc_meet=request.POST["description1_meet"]
                        except:
                                desc_meet=""
                        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,
                                                   room_name=name_meet,
                                                   meeting_description=desc_meet,
                                                   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)
                                name_val="name_meet_"+str(i)
                                desc_val="description_meet_"+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

                                try:
                                        new_name=request.POST[name_val]
                                except:
                                        new_name="Meeting Room "+str(i+1)

                                try:
                                        new_desc=request.POST[desc_val]
                                except:
                                        new_desc=""
                                        
                                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,
                                                               room_name=new_name,
                                                               meeting_description=new_desc,
                                                               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

                        try:
                                name_meet=request.POST["name1_meet"]
                        except:
                                name_meet="Meeting Room 1"

                        try:
                                desc_meet=request.POST["description1_meet"]
                        except:
                                desc_meet=""

                        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,
                                                   room_name=name_meet,
                                                   meeting_description=desc_meet,
                                                   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):

                print"In Training Roooommmmmmmmmmmmmmmm"

                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):

                        print "In if of training room"
                        
                        try:
                                training_capacity=request.POST["capacity7"]
                                print "now capacity...",training_capacity
                                if(training_capacity):
                                        print"am here"
                                else:
                                        training_capacity=0
                                
                                training_no1=room_no+1
                                
                        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
                        try:
                                name_train=request.POST["name1_train"]
                        except:
                                name_train="Training Room 1"

                        try:
                                train_desc=request.POST["description1_train"]

                        except:
                                train_desc=""
                                

                        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,
                                                      room_name=name_train,
                                                      training_description=train_desc,
                                                      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)
                                name_val="name_train_"+str(i)
                                desc_val="description_train_"+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

                                try:
                                        new_name=request.POST[name_val]
                                except:
                                        new_name="Training Room "+str(i+1)

                                try:
                                        new_description=request.POST[desc_val]
                                except:
                                        new_description=""
                                        
                                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,
                                                              room_name=new_name,
                                                              training_description=new_description,
                                                              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:
                        print "In else of tr room"

                        try:
                                training_capacity=int(request.POST["capacity7"])
                                print "now capacity...",training_capacity,type(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

                        try:
                                name_train=request.POST["name1_train"]
                        except:
                                name_train="Training Room 1"

                        try:
                                train_desc=request.POST["description1_train"]

                        except:
                                train_desc=""

                        
                        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

                        print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",training_capacity,type(training_capacity)
                        if(training_capacity > 0):
                                print "Iam in saving data"
                                data123=Training_room(property_id=prop_id,
                                                      training_room_no=1,
                                                      capacity=training_capacity,
                                                      room_name=name_train,
                                                      training_description=train_desc,
                                                      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):

                print "In Event Halllllllllllllllllllllllllllll"

                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

                        try:
                                name_event=request.POST["name1_event"]
                        except:
                                name_event="Event Hall 1"

                        try:
                                desc_event=request.POST["description1_event"]
                        except:
                                desc_event=""
                                
                        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=1
                                data01=Event_Halls(property_id=prop_id,
                                                   capacity=event_capacity,
                                                   room_name=name_event,
                                                   event_description=desc_event,
                                                   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)
                                name_val="name_event_"+str(i)
                                desc_val="description_event_"+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

                                try:
                                        new_name=request.POST[name_val]
                                except:
                                        new_name="Event Hall "+str(i+1)

                                try:
                                        new_desc=request.POST[desc_val]
                                except:
                                        new_desc=""
                                        
                                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,
                                                           room_name=new_name,
                                                           event_description=new_desc,
                                                           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

                        try:
                                name_event=request.POST["name1_event"]
                        except:
                                name_event="Event Hall 1"

                        try:
                                desc_event=request.POST["description1_event"]
                        except:
                                desc_event=""

                        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,
                                                   room_name=name_event,
                                                   event_description=desc_event,
                                                   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=[]

        try:

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

	print "wifiiiiiiiiiiiiiiii",wifi

	try:

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

	try:

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

	try:

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


	try:

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


	try:

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

	try:

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

	try:

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


	try:
                locker=request.POST["lc"]
                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:

                seatup=request.POST["se"]
        
       	except:
                seatup=0
##	
	try:

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

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

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

	try:

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

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

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

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

			  coffe1=request.POST["cofee_tea1"]
			  print "coffeeeeeeeeeeeeee paidddddddddddd",coffe1
	except:
			  coffe1=0
	try:

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

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

			  printer1=0
	try:

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

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

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

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

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

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

			  seatup1=request.POST["se1"]
	except:
			  seatup1=0
	try:

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

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

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

			  screen1=request.POST["pro1"]
	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=myid)


#********************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(seatup!=0 and seatup1==0):
              data.Seat_up=0
    	elif(seatup==0 and seatup1!=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})
##	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..."
	
	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

@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 Calendar(request,user1,password):
        print "user.....",user1,type(user1)
        user=str(user1)
        print "user.....",user,type(user)
	email_id=[]
	data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(str(user) in email_id):
                owner="Owner"
        else:
                owner="Super_owner"

        if(owner=="Owner"):
                
                
                data=Property_Details.objects.filter(submitted_by=user).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)
                        prop_typ_list=str(i.property_type)
                        
                        print "prop_typ_list.......",prop_typ_list
                        typ_list=prop_typ_list.split(",")
                        print "type_list--->",typ_list		
                        for pt in typ_list:
                                print "pt in p_type1---->",pt

                                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
                        print "namesEERRRRERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",i.property_name
                        first.append(i.property_name)
                        address=i.address
                        first.append(i.address)
                        first.append(my_val_plug)
                        first.append(my_val_Training)
                        first.append(my_val_meeting)
                        first.append(my_val_event)
                        result.append(first)
                        first=[]
                        comment=[]
                        rate=[]
                #print "final result...........",result
                return render_to_response('Calendar.html',{"property":result,"my_val_plug":my_val_plug,
                                                           "my_val_Training":my_val_Training,"my_val_event":my_val_event,
                                                           "my_val_meeting":my_val_meeting,
                                                           "owner":owner,"user":user,"password":password})
        return render_to_response('Calendar.html',{"owner":owner,"user":user,"password":password})


        
@csrf_exempt
def business_space(request,user1,password):

        print "user.....",user1,type(user1)
        user=str(user1)
        print "user.....",user,type(user)
	email_id=[]
	data=Login.objects.all()
	for d in data:
               email_id.append(str(d.email_id))
        if(str(user) in email_id):
                owner="Owner"
        else:
                owner="Super_owner"
        if(owner=="Owner"):
                print "Iam in owner"
                data=Property_Details.objects.filter(submitted_by=user).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":user,"comments":comm,"password":password})


    
	else:
            print "in else "
	    
            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))
               
                
                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":user,"comments":comm,"password":password})



@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()
                print "Iam in try"
                instance = Login.objects.get(email_id = username,user_type = "Owner")
                print "instace.......",instance
                if(instance):
                        password1=instance.password
                        print "passweord..........",password1
                        if password == password1:
                               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 "username.........................................\t",username
                               #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})
                else:
                    msg = "Username not found.Please Sign Up!"
                    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=""
        default_val="None"
        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
        hot_seat=0
        pvt_ofc=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=""
        display_pnp="none"
        display_tr="none"
        display_eh="none"
        display_mr="none"
        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)
                        print "*********************************************price*********************",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
                        prop_url=d.prop_url
                        description=d.description
                        default=str(d.default_type)
                        print "default....................................",default
                        
                        if(default == "Plug & Play"):
                                default_selected1="selected"
                                default_val="block"
                                
                        if(default == "Training Room"):
                                default_selected2="selected"
                                default_val="block"
                                
                        if(default == "Event_Hall"):
                                default_selected3="selected"
                                default_val="block"
                                
                        if(default == "Meeting_Room"):
                                default_selected4="selected"
                                default_val="block"
                                
##                        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"
                                        display_pnp="block"
                                if "Training Room" in pt:
                                        p_type_t="checked"
                                        display_tr="block"
                                if "Meeting_Room" in pt:
                                        p_type_m="checked"
                                        display_mr="block"
                                if "Event_Hall" in pt:
                                        p_type_e="checked"
                                        display_eh="block"
                                        

                        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)
                                holiii=",".join(holi1)
                        holi=str(holiii)
                        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"):
                                                hot_seat="checked"
                                                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"):
                                                 pvt_ofc="checked"
                                                 plug_name=""
                                                 plug_desc=""
                                                 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
                                                                        if(pg.room_name != "ND"):
                                                                                plug_name=(str(pg.room_name))
                                                                                print "nameeeeeeeeeeeee",plug_name
                                                                        if(pg.shared_description != "ND"):
                                                                                plug_desc=(str(pg.shared_description))
                                                                                print "desccccccccccc",plug_desc
                                                                        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)
                                                                        first.append(plug_name)
                                                                        first.append(plug_desc)
                                                                        result_month_pp.append(first)
                                                                        first=[]
                                                                        p_i=[]
                                                                        plug_img=""
                                                                        

                                                                        
                                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"
                                                train_name=""
                                                train_desc=""
                                                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=" "
                                                        if(tr.training_room_images):
                                                                tr_img=str(tr.training_room_images)
                                                                tr_img1=str(tr_img)
                                                                t_i=tr_img.split(",")
                                                        if(tr.room_name != "ND"):
                                                                train_name=(str(tr.room_name))

                                                        if(tr.training_description != "ND"):
                                                                train_desc=(str(tr.training_description))
                                                        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)
                                                        first.append(t_i)
                                                        first.append(train_name)
                                                        first.append(train_desc)
                                                        result_train.append(first)
                                                        first=[]
                                                        tr_img=""
                                                        t_i=[]

                                                        
                                                        

                        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"
                                                meet_name=""
                                                meet_desc=""
                                                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=" "
                                                        if(meet.meeting_room_images):
                                                                meet_img=str(meet.meeting_room_images)
                                                                meet_img1=str(meet_img)
                                                                m_i=meet_img.split(",")
                                                        if(meet.room_name != "ND"):
                                                                meet_name=str(meet.room_name)
                                                        if(meet.meeting_description != "ND"):
                                                                meet_desc=str(meet.meeting_description)
                                                        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)
                                                        first.append(m_i)
                                                        first.append(meet_name)
                                                        first.append(meet_desc)
                                                        result_meet.append(first)
                                                        first=[]
                                                        m_i=[]
                                                        meet_img=""

                                                        
                                                        


                        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"
                                                event_name=""
                                                event_desc=""
                                                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=" "
                                                        if(event.shared_images):
                                                                event_img=(str(event.shared_images))
                                                                event_img1=str(event_img)
                                                                e_i=event_img.split(",")
                                                        if(event.room_name != "ND"):
                                                                event_name=str(event.room_name)
                                                        if(event.event_description != "ND"):
                                                                event_desc=str(event.event_description)
                                                        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)
                                                        first.append(e_i)
                                                        first.append(event_name)
                                                        first.append(event_desc)
                                                        result_event.append(first)
                                                        first=[]
                                                        e_i=[]
                                                        event_img=""

                                                        
                        
			                        
                        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_proper.html',{"owner_id":owner,"active_selected":active_selected,"inactive_selected":inactive_selected,
                                                            "pvt_ofc":pvt_ofc,"hot_seat":hot_seat,"prop_url":prop_url,
                                                            "default_val":default_val,"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,
                                                            "display_pnp":display_pnp,"display_tr":display_tr,"display_mr":display_mr,
                                                            "display_eh":display_eh,
                                                            "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})


@csrf_exempt
def owner_booking(request,user1,password):
    print "username is",user1,type(user1)
    user=str(user1)
    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"
        
    login_data=Login.objects.filter(email_id=user)
    for l_d in login_data:
      owner_id=int(l_d.user_id)
    #owner_id = 6
    current_user = request.user
    print current_user
    duration = []
    result_data = []
    result_data1 = []
    list1 = []
    list2 = []
    list3 = []
    list4 = []
    mainlist = []
    mainlist_today = []
    mainlist_tom = []
    mainlist_later = []
    sortdate = []
    durations = []
    data=Login.objects.get(user_id=owner_id)
    if(data):
        owner_email_id=str(data.email_id)
        prop_details = Property_Details.objects.filter(submitted_by=owner_email_id)
        for prop in prop_details:
          prop_id=int(prop.property_id)
          payment_det = Payment.objects.filter(property_id=prop_id).order_by('Booking_date')
          for pay_det in payment_det:
            User_id=int(pay_det.User_id)
            log_det = Login.objects.filter(user_id=User_id)
            if(log_det):
              for l_d in log_det:
                user_name=str(l_d.user_name)
                user_phone=l_d.user_password
                email_id=str(l_d.email_id)
                list1.append(email_id)
                property_type=str(pay_det.Property_type)
                property_name=str(pay_det.Property_name)
                payment_status=str(pay_det.Payment_status)
                booking_type=str(pay_det.Booking_type)
                booking_type=str(pay_det.Booking_type)
                booking_date=pay_det.Booking_date
                booking_time=pay_det.Booking_time
                payment_mode=pay_det.Payment_status
                if(booking_time):
                  lastt = booking_time[0:23]
                  durations = booking_time[17:32]
                  lastt = lastt.split("  :   ")
                  date = lastt[0]
                  time = lastt[1]

                  lastt = date + '' + time
                  nextdate = datetime.datetime.strptime(lastt,'%d/%m/%Y%H:%M%p')
                  nextdate1 = nextdate
                else:
                  list_date=booking_date.split(", ")
                  lastt = []
                  duration = []
                  for dt in list_date:
                    if(dt != ""):
                      last_dt=dt
                      length = len(last_dt)
                      if("|" in last_dt):
                        splt_dt=last_dt.split("|")
                        for s_dt in splt_dt:
                          lastt=str(splt_dt[0])
                          time = str(splt_dt[1])
                          lastt = lastt + '' + time
                          nextdate = datetime.datetime.strptime(lastt,'%d/%m/%Y%H:%M%p')
                          nextdate1 = nextdate

                      elif("-" in last_dt):
                        splt_dt=last_dt.split("-")
                        for s_dt in splt_dt:
                          lastt=str(splt_dt[0])
                          lastt = lastt + '' + '10:00AM'
                          nextdate = datetime.datetime.strptime(lastt,'%d/%m/%Y%H:%M%p')#.strftime('%d-%m-%Y')
                          nextdate1 = nextdate
                      
                      elif(", " in last_dt):
                        splt_dt=last_dt.split(" - ")
                        for s_dt in splt_dt:
                          lastt=str(splt_dt[0])
                          lastttt = str(splt_dt[1])

                from time import gmtime, strftime
                today = strftime("%Y-%m-%d %H:%M:%S", gmtime())
                print type(today)
                print today
                today = today[0:10]
                today_start = today + '' + '00:00AM'
                today_end = today + '' + '23:59PM'
                today_start = datetime.datetime.strptime(today_start,'%Y-%m-%d%H:%M%p')
                today_end = datetime.datetime.strptime(today_end,'%Y-%m-%d%H:%M%p')
                #print "******************",today_start,today_end
                #print type(today_end)
                #print "xxxxxxxxxxx",nextdate1
                tomorrow_end = today_end + datetime.timedelta(days=1)
                later_date = tomorrow_end + datetime.timedelta(days=1800)
                print "...................................",later_date
                if(nextdate1 > today_start and nextdate1 < today_end ):
                  print "_______________________________________________________________________"
                  #today bookings
                  from operator import itemgetter
                  #list1.append(email_id)
                  list1.append(property_name)
                  list1.append(property_type)
                  #list1.append(payment_mode)
                  #list1.append(sorted)
                  #duration.append(booking_date)
                  try:
                    list1.append(nextdate1)
                  except:
                    list1.append(nextdate)
                  list1.append(payment_mode)
                  if(booking_time):
                    list1.append(durations)
                  else:
                    start_date = booking_date[0:14]
                    durations = start_date
                    list1.append(durations)
                    list1.append(start_date)
                  list1.append(user_phone)
                  list1.append(user_name)
                  if(booking_time):
                    booking_time = booking_time
                  else:
                    if(" , " in booking_date):
                      booking_date=booking_date.split(" , ")
                      print "#######################",booking_date[0]
                    booking_time = booking_date
                  print "((((((((((((((((",booking_time
                  list1.append(booking_time)
                  mainlist_today.append(list1)
                  list1=[]



                elif(nextdate1 > today_end and nextdate1 < tomorrow_end ):
                  print "booking not available"
                  #tomorrow bookings
                  from operator import itemgetter
                  #list1.append(email_id)
                  list1.append(property_name)
                  list1.append(property_type)
                  #list1.append(sorted)
                  #duration.append(booking_date)
                  try:
                    list1.append(nextdate1)
                  except:
                    list1.append(nextdate)
                  list1.append(payment_mode)
                  list1.append(durations)
                  start_date = booking_date[0:14]
                  list1.append(start_date)
                  list1.append(user_phone)
                  list1.append(user_name)
                  if(booking_time):
                    booking_time = booking_time
                  else:
                    booking_time = booking_date

                  #print "((((((((((((((((",booking_time
                  list1.append(booking_time)
                  mainlist_tom.append(list1)
                  list1=[]


                elif(nextdate1 > tomorrow_end and nextdate1 < later_date ):
                  from operator import itemgetter
                  #later bookings
                  #list1.append(email_id)
                  list1.append(property_name)
                  list1.append(property_type)
                  #list1.append(sorted)
                  #duration.append(booking_date)
                  try:
                    list1.append(nextdate1)
                  except:
                    list1.append(nextdate)
                  list1.append(payment_mode)
                  list1.append(durations)
                  start_date = booking_date[0:14]
                  list1.append(start_date)
                  list1.append(user_phone)
                  list1.append(user_name)
                  if(booking_time):
                    booking_time = booking_time
                  else:
                    booking_time = booking_date
                  list1.append(booking_time)
                  mainlist_later.append(list1)
                  list1=[]
                #else:
                #  print "nothing"
                else:
                  from operator import itemgetter
                  #list1.append(email_id)
                  list1.append(property_name)
                  list1.append(property_type)
                  list1.append(payment_mode)
                  #list1.append(sorted)
                  #duration.append(booking_date)
                  try:
                    list1.append(nextdate1)
                  except:
                    list1.append(nextdate)
                  mainlist.append(list1)
                  list1=[]


        if(result_data):
            result_data_new = map(lambda x: str(x),result_data)
            result_data11=list(set(result_data_new))
            result_data1 = map(lambda x: eval(x),result_data11)
        list4.append(duration)
        mainlist.append(list1)
        mainlist.append(list2)
        mainlist.append(list3)

        mainlist2 = [x for x in mainlist if x != []]
        try:
          key=itemgetter(3)
        except:
          return HttpResponseRedirect('/no_bookings/')
        print type(mainlist2)
        mainlist2 = sorted(mainlist2, key=itemgetter(3))
    
        return render_to_response('booking.html',{"user":user,"password":password,"owner_id":owner,"mainlist_later":mainlist_later,"mainlist_tom":mainlist_tom,"mainlist_today":mainlist_today,"mainlist2":mainlist2,"list1":list1,"list2":list2,"list3":list3,"list4":list4})



@csrf_exempt
def no_bookings(request):
  return render_to_response('no_bookings.html')
  #messages.error(request, 'Average Retailer History upload failed')
  #return HttpResponseRedirect('/display_homepage/')

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[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
##                
##
##                    
##                        #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[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
##                        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 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"])
        password=request.POST["Password"]
        
        new_cur_pathlist=[]
	prop_name=request.POST["name_proj"]
	address=request.POST["searchTextField"]
	#phone=request.POST["phone"]
	price=request.POST["price"]
	
	lat=request.POST['cityLat']
	lon=request.POST['cityLng']
	loc=request.POST['city2']

	
	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()

        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
        my_val_plug=""
        my_val_Training=""
        my_val_event=""
        my_val_meeting=""
	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"]
##	try:
##                default=request.POST["default"]
##        except:
##                default=""
	try:
                sub_type=request.POST["sub_type"]
        except:
                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"]
        prop_url=request.POST["prop_url"]
	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=""
        
        img_data=Property_Details.objects.get(property_id=prop_id)
        images=img_data.images
        img_vall=images.split(", ")
        img_vall=images.split(",")
        for img_v in img_vall:
                print "img_vvvvvvvvvvvvvvv",img_v
                img_v_i=img_v.replace(",","")
                print "img_v_iiiiiiiii",img_v_i
                try:
                        in_val="delete_img_val_"+str(img_v_i)
                        my_new_img=str(request.POST[in_val])
                        print "image vaaaaaaaaaaaaaaaaaallll",my_new_img
                        result=delete_img1(my_new_img,prop_id)
                        print "images deleted...,",result
                except:
                        print "nothing to delete"
                        
                        

        try:
                upimages=request.FILES.getlist('new_images')
        except:
                upimages=""             
        
        new_cur_pathlist0=""
	if upimages:
	      print "in this code..............."
	      cur_pathlist=[]
              path1=upload_image(upimages,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
	
	

	new_data=Property_Details.objects.get(property_id=prop_id)
	new_data.property_name=prop_name
	new_data.property_super_subtype=super_sub_type
	new_data.property_subtype=str(sub_type)
	new_data.property_type=new_cur_typlist
	new_data.address=address
	new_data.status=prop_status
	new_data.prop_url=prop_url
	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=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()	

	
	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)
	
                
	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)

	#####################################################################################
        new_cur_pathlist=[]
	new_cur_pathlist1=[]
	new_cur_pathlist12=[]
	new_cur_pathlist123=[]
##        book=Booking_Type()
##        book.property_id=prop_id
##        book_type=[]
	book_property_type=""
        book_type=[]
	
        if(my_val_plug):

                print "In Plug and Play sectionnnnnnnnnnnnn"

                try:
                        super_sub_type=request.POST["super_sub_type"]
                except:
                        super_sub_type=""
                print "super_sub_type...............\n",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):

                                
                                count=1
                                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)
                                        name_val="name_pvt_"+str(i)
                                        desc_val="description_pvt_"+str(i)

                                        try:
                                                img_data=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=i)
                                                images=img_data.shared_images
                                                img_vall=images.split(", ")
                                                img_vall=images.split(",")
                                                for img_v in img_vall:
                                                        print "img_vvvvvvvvvvvvvvv",img_v
                                                        img_v_i=img_v.replace(",","")
                                                        print "img_v_iiiiiiiii",img_v_i
                                                        try:
                                                                in_val="delete_mon_val_"+str(img_v_i)+"_"+str(i)
                                                                my_new_img=str(request.POST[in_val])
                                                                print "image vaaaaaaaaaaaaaaaaaallll",my_new_img
                                                                result=delete_mon_img1(my_new_img,i,prop_id)
                                                                print "images deleted...,",result
                                                        except:
                                                                print "nothing to delete"
                                        except:
                                                print "No field like that"
                                
                                        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

                                        try:
                                                new_name=request.POST[name_val]
                                        except:
                                                new_name="Private Office "+str(i)

                                        try:
                                                new_desc=request.POST[desc_val]
                                        except:
                                                new_desc=""
                                        
                                        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
                                                data=Shared_area.objects.filter(property_id=prop_id,pvt_ofc_no=new_room_no1)
                                                if(data):
                                                        new_data1=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=new_room_no1)
                                                        new_data1.capacity=new_shared_capacity
                                                        new_data1.rate_monthly=new_shared_monthly
                                                        new_data1.room_name=new_name
                                                        new_data1.shared_description=new_desc
                                                        if(new_data1.shared_images):
                                                                new_img=new_data1.shared_images+","+new_cur_pathlist11
                                                                new_img1=new_img.split(",")
                                                                new_i=list(set(new_img1))
                                                                image=",".join(new_i)
                                                                new_data1.shared_images=image
                                                        else:
                                                                new_data1.shared_images=new_cur_pathlist11                                                                
                                                        new_data1.save()
                                                else:
                                                        new_data1=Shared_area(property_id=prop_id,
                                                                              pvt_ofc_no=new_room_no1,
                                                                              capacity=new_shared_capacity,
                                                                              rate_monthly=new_shared_monthly,
                                                                              room_name=new_name,
                                                                              shared_description=new_desc,
                                                                              shared_images=new_cur_pathlist11)

                                                        new_data1.save()
                                                count=count+1

                        else:
                                print "In else of pvt ofc"

                                try:
                                        shared_capacity=request.POST["capacity_monthly_1"]
                                        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_monthly_1"]
                                        book_type.append("Monthly")
                                        book_property_type="Plug & Play"
                                except:
                                        shared_monthly=0

                                try:
                                        sh_images=request.FILES.getlist('shared_img_pvt_1')
                                except:
                                        sh_images=0

                                try:
                                        new_name=request.POST["name_pvt_1"]
                                except:
                                        new_name="Private Office 1"

                                try:
                                        new_desc=request.POST["description_pvt_1"]
                                except:
                                        new_desc=""
                                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):
                                        data=Shared_area.objects.filter(property_id=prop_id)
                                        if(data):
                                                new_data=Shared_area.objects.get(property_id=prop_id,pvt_ofc_no=1)
                                                new_data.capacity=shared_capacity
                                                new_data.rate_monthly=shared_monthly
                                                new_data.room_name=new_name
                                                new_data.shared_description=new_desc
                                                
                                                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(property_id=prop_id,pvt_ofc_no=1,
                                                                     capacity=shared_capacity,
                                                                     room_name=new_name,
                                                                     shared_description=new_desc,
                                                                     rate_monthly=shared_monthly,
                                                                     shared_images=new_cur_pathlist)
                                                new_data.save()

                                       

                        

                else:

                        try:
                                shared_capacity=request.POST["capacity"]
                                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"
                                print "hr valueeeeeeeeeeee",shared_hr
                        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'''
                        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):
                                data=Shared_area.objects.filter(property_id=prop_id)
                                if(data):
                                        print "Iam in hot seat save data"
                                        for d in data:
                                                if(d.shared_images):
                                                        new_img=d.shared_images+","+new_cur_pathlist
                                                        new_img1=new_img.split(",")
                                                        new_i=list(set(new_img1))
                                                        image=",".join(new_i)
                                                        
                                                else:
                                                        image=new_cur_pathlist
                                        new_data=Shared_area.objects.filter(property_id=prop_id).delete()
                                        print "Objects of table...",new_data
                                        
                                        new_data1=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=image)
##                                        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
##                                        new_data.shared_images=new_cur_pathlist

                                        new_data1.save()
                                        print "Objects of table...",new_data1

                                else:
                                        new_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)

                                        new_data.save()

		

        if(my_val_meeting):
                print "meeting room save edit.............."
                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

                        
                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)
                                name_val="name_meet_"+str(i)
                                desc_val="description_meet_"+str(i)

                                try:
                                        img_data=Meeting_room.objects.get(property_id=prop_id,room_no=i)
                                        images=img_data.meeting_room_images
                                        img_vall=images.split(", ")
                                        img_vall=images.split(",")
                                        for img_v in img_vall:
                                                print "img_vvvvvvvvvvvvvvvmeeting",img_v
                                                img_v_i=img_v.replace(",","")
                                                print "img_v_iiiiiiiiimeeting",img_v_i
                                                try:
                                                        in_val="delete_meet_val_"+str(img_v_i)+"_"+str(i)
                                                        my_new_img=str(request.POST[in_val])
                                                        print "image vaaaaaaaaaaaaaaaaaallll",my_new_img
                                                        result=delete_meet_img1(my_new_img,i,prop_id)
                                                        print "images deleted...,",result
                                                except:
                                                        print "nothing to delete"
                                except:
                                        print "No field like that"
                        
                                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

                                try:
                                        new_meet_name=request.POST[name_val]
                                except:
                                        new_meet_name="Meeting Room "+str(i)

                                try:
                                        new_desc=request.POST[desc_val]
                                except:
                                        new_desc=""
                                        
                                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
                                                data1.room_name=new_meet_name
                                                data1.meeting_description=new_desc
                                                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,
                                                                       room_name=new_meet_name,
                                                                       meeting_description=new_desc,
                                                                       meeting_room_images=new_cur_pathlist11)

                                                new_data1.save()
                                        count=count+1
##                                        
##
        if(my_val_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

                        
                        
                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)
                                name_val="name_train_"+str(i)
                                desc_val="description_train_"+str(i)
                                try:
                                        img_data=Training_room.objects.get(property_id=prop_id,training_room_no=i)
                                        images=img_data.training_room_images
                                        img_vall=images.split(", ")
                                        img_vall=images.split(",")
                                        for img_v in img_vall:
                                                print "img_vvvvvvvvvvvvvvvtrain",img_v
                                                img_v_i=img_v.replace(",","")
                                                print "img_v_iiiiiiiiitrain",img_v_i
                                                try:
                                                        in_val="delete_train_val_"+str(img_v_i)+"_"+str(i)
                                                        my_new_img=str(request.POST[in_val])
                                                        print "image vaaaaaaaaaaaaaaaaaallll",my_new_img
                                                        result=delete_train_img1(my_new_img,i,prop_id)
                                                        print "images deleted...,",result
                                                except:
                                                        print "nothing to delete"
                                except:
                                        print "No field like that"
                        
                                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_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

                                try:
                                        new_name=request.POST[name_val]
                                except:
                                        new_name="Training Room "+str(i)
                                try:
                                        new_desc=request.POST[desc_val]
                                except:
                                        new_desc=""
                                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
                                                data1234.room_name=new_name
                                                data1234.training_description=new_desc
                                                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,
                                                                      room_name=new_name,
                                                                      training_description=new_desc,
                                                                      rate_half_day=new_hralf,
                                                                      rate_full_day=new_daily,
                                                                      training_room_images=new_cur_pathlist11)

                                                data123.save()
                                        count=count+1
##                        
##
##                
        if(my_val_event):

                print "Iam in event halll save edit function"

                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

                
                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)
                                name_val="name_event_"+str(i)
                                desc_val="description_event_"+str(i)
                                try:
                                        img_data=Event_Halls.objects.get(property_id=prop_id,room_no=i)
                                        images=img_data.shared_images
                                        img_vall=images.split(", ")
                                        img_vall=images.split(",")
                                        for img_v in img_vall:
                                                print "img_vvvvvvvvvvvvvvvevent",img_v
                                                img_v_i=img_v.replace(",","")
                                                print "img_v_iiiiiiiiievent",img_v_i
                                                try:
                                                        in_val="delete_event_val_"+str(img_v_i)+"_"+str(i)
                                                        my_new_img=str(request.POST[in_val])
                                                        print "image vaaaaaaaaaaaaaaaaaallll",my_new_img
                                                        result=delete_event_img1(my_new_img,i,prop_id)
                                                        print "images deleted...,",result
                                                except:
                                                        print "nothing to delete"
                                except:
                                        print "No field like that"
                                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
                                try:
                                        new_name=request.POST[name_val]
                                except:
                                        new_name="Event Hall "+str(i)

                                try:
                                        new_desc=request.POST[desc_val]
                                except:
                                        new_desc=""
                                        
                                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
                                                data1.room_name=new_name
                                                data1.event_description=new_desc
                                        
                                                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,
                                                                   room_name=new_name,
                                                                   event_description=new_desc,
                                                                   rate_halfday=new_hralf,
                                                                   rate_daily=new_daily,
                                                                   shared_images=new_cur_pathlist11)

                                                data01.save()

                                        count=count+1


        # Facilities.....................................                
	
        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=[]

        try:

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

	print "wifiiiiiiiiiiiiiiii",wifi

	try:

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

	try:

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

	try:

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


	try:

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


	try:

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

	try:

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

	try:

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


	try:
                locker=request.POST["lc"]
                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:

                seatup=request.POST["se"]
        
       	except:
                seatup=0
##	
	try:

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

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

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

	try:

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

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

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

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

			  coffe1=request.POST["cofee_tea1"]
			  print "coffeeeeeeeeeeeeee paidddddddddddd",coffe1
	except:
			  coffe1=0
	try:

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

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

			  printer1=0
	try:

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

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

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

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

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

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

			  seatup1=request.POST["se1"]
	except:
			  seatup1=0
	try:

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

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

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

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

        


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


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

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

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


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

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

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


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

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



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


	if(seatup!=0 and seatup1==0):
              Seat_up=0
    	elif(seatup==0 and seatup1!=0):
      	      Seat_up=1
    	else:
    		  Seat_up="ND"

	if(half_deal!=0 and half_deal1==0):
              Stationary=0
    	elif(half_deal==0 and half_deal1!=0):
      	      Stationary=1
    	else:
    		  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):
              Projector=0
    	elif(projector==0 and projector1!=0):
      	      Projector=1
    	else:
    		  Projector="ND"

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


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

	

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

                Property_Facility.objects.filter(property_id=prop_id).update(Wifi=Wifi,Coffee_tea=Coffee_tea,Water_bottle=Water_bottle,Printer=Printer,Stationary=Stationary,Seat_up=Seat_up,Charging_Point=Charging_Point,Changing_room=Changing_room,Library=Library,Massage_chair=Massage_chair,
        Locker=Locker,AC=AC,Projector=Projector,Projection_screen=Projection_screen,PC_or_Laptop=PC_or_Laptop)
        #********************code by aditya ****************************	

        else:
              Property_Facility(property_id=prop_id,Wifi=Wifi,Coffee_tea=Coffee_tea,Water_bottle=Water_bottle,Printer=Printer,Stationary=Stationary,Seat_up=Seat_up,Charging_Point=Charging_Point,Changing_room=Changing_room,Library=Library,Massage_chair=Massage_chair,
        Locker=Locker,AC=AC,Projector=Projector,Projection_screen=Projection_screen,PC_or_Laptop=PC_or_Laptop).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(username in email_id):
                owner="Owner"
        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})

def delete_shared1(file_name,prop_id):

        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).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()
        return 1

@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})

def delete_mon_img1(file_name,room_no,prop_id):

        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()
        return 1

@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})

def delete_meet_img1(file_name,room_no,prop_id):

        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()
        return 1

@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})

def delete_train_img1(file_name,room_no,prop_id):
        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()

        return 1


@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})


def delete_event_img1(file_name,room_no,prop_id):

        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=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()
        return 1

@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})


def delete_img1(file_name,prop_id):

        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=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()
        return 1

@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")
        
