def insertPropertyBasicDetails():
    if session['loginRole']!= 'user':
        return redirect(url_for('login'))

    propertyBasicDetailsDAO = PropertyBasicDetailsDAO()
    propertyBasicDetailsVO = PropertyBasicDetailsVO()
    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryVO = PropertySubcategoryVO()

    propertyBasicDetailsVO.property_LoginId = session['loginId']
    propertyBasicDetailsVO.propertyOwnerType = request.form['propertyOwnerType']
    propertyBasicDetailsVO.propertyListFor = request.form['propertyListFor']

    propertyBasicDetailsVO.property_PropertySubcategoryId = request.form['property_PropertySubcategoryId']
    propertyBasicDetailsVO.propertyAtStep = '2'
    propertyBasicDetailsVO.propertyStatus = 'pending'
    propertyBasicDetailsVO.propertyActiveStatus = 'active'

    propertySubcategoryVO.propertySubcategoryId = propertyBasicDetailsVO.property_PropertySubcategoryId
    propertySubcategoryDict = propertySubcategoryDAO.editPropertySubcategory(propertySubcategoryVO)
    propertyBasicDetailsVO.propertyDate,propertyBasicDetailsVO.propertyTime = str(datetime.now()).split(' ')
    propertyBasicDetailsVO.property_PropertyCategoryId = propertySubcategoryDict[0]['propertySubcategory_PropertyCategoryId']


    propertyBasicDetailsDAO.insertPropertyBasicDetails(propertyBasicDetailsVO)

    return redirect(url_for('loadPropertyAddress'))
def viewPropertySubcategory():

    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryDict = propertySubcategoryDAO.searchPropertySubcategory(
    )

    return render_template('admin/viewPropertySubcategory.html',
                           propertySubcategoryDict=propertySubcategoryDict)
def deletePropertySubcategory():
    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryVO = PropertySubcategoryVO()
    propertySubcategoryVO.propertySubcategoryId = request.args.get(
        'propertySubcategoryId')
    propertySubcategoryVO.propertySubcategoryActiveStatus = 'deactive'
    propertySubcategoryDAO.deletePropertySubcategory(propertySubcategoryVO)

    return redirect(url_for('viewPropertySubcategory'))
def loadPostProperty():
    if session['loginRole']!= 'user':
        return redirect(url_for('login'))

    propertyCategoryDAO = PropertyCategoryDAO()
    propertySubcategoryDAO = PropertySubcategoryDAO()

    propertyCategoryDict = propertyCategoryDAO.searchPropertyCategory()
    propertySubcategoryDict = propertySubcategoryDAO.searchPropertySubcategory()

    return render_template('user/propertyBasicDetails.html',propertyCategoryDict=propertyCategoryDict,propertySubcategoryDict=propertySubcategoryDict)
def insertPropertyAddress():
    if session['loginRole']!= 'user':
        return redirect(url_for('login'))

    propertyAddressDAO = PropertyAddressDAO()
    propertyBasicDetailsDAO = PropertyBasicDetailsDAO()
    propertySubcategoryDAO = PropertySubcategoryDAO()

    propertySubcategoryVO = PropertySubcategoryVO()

    propertyAddressVO = PropertyAddressVO()
    propertyBasicDetailsVO = PropertyBasicDetailsVO()

    propertyDict = {}

    propertyAddressVO.propertyAddress_PropertyId = request.form['propertyId']
    propertyAddressVO.propertyStreet = request.form['propertyStreet']
    propertyAddressVO.propertyLocality = request.form['propertyLocality']
    propertyAddressVO.propertyCityId = request.form['propertyCityId']
    propertyAddressVO.propertyStateId = request.form['propertyStateId']
    propertyAddressVO.propertyPincode = request.form['propertyPincode']

    propertyAddressVO.propertyAddressDate, propertyAddressVO.propertyAddressTime = str(datetime.now()).split(' ')
    propertyAddressVO.propertyAddressActiveStatus = 'active'

    propertyDict['propertyId'] = request.form['propertyId']
    propertyBasicDetailsVO.propertyId = propertyDict['propertyId']
    propertyDict = propertyBasicDetailsDAO.searchPropertyById(propertyBasicDetailsVO)

    propertyAddressDAO.insertPropertyAddress(propertyAddressVO)
    # print "pDict",propertyDict

    propertySubcategoryVO.propertySubcategoryId = propertyDict[0]['property_PropertySubcategoryId']

    propertySubcategoryDict = propertySubcategoryDAO.editPropertySubcategory(propertySubcategoryVO)
    # print "propertySubcategoryDict", propertySubcategoryDict

    setStep('3',request.form['propertyId'])

    if(propertySubcategoryDict[0]['propertyCategoryName']=='land'):
        return render_template('user/propertyDetailsLand.html', propertyDict=propertyDict)
    elif (propertySubcategoryDict[0]['propertyCategoryName'] == 'commercial'):
        if (propertySubcategoryDict[0]['propertySubcategoryName']=='hotel' or propertySubcategoryDict[0]['propertySubcategoryName']=='resort'):
            return render_template('user/propertyDetailsHotel.html', propertyDict=propertyDict)
        else:
            return render_template('user/propertyDetailsCommercial.html', propertyDict=propertyDict)
    else:
        return render_template('user/propertyDetailsResidential.html', propertyDict=propertyDict)
def editPropertySubcategory():

    propertyCategoryDAO = PropertyCategoryDAO()
    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryVO = PropertySubcategoryVO()
    propertySubcategoryVO.propertySubcategoryId = request.args.get(
        'propertySubcategoryId')
    propertySubcategoryDict = propertySubcategoryDAO.editPropertySubcategory(
        propertySubcategoryVO)
    propertyCategoryDict = propertyCategoryDAO.searchPropertyCategory()

    return render_template(
        'admin/editPropertySubcategory.html',
        propertySubcategoryDict=propertySubcategoryDict,
        propertyCategoryDict=propertyCategoryDict,
        propertySubcategoryId=propertySubcategoryVO.propertySubcategoryId)
def insertPropertySubcategory():

    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryVO = PropertySubcategoryVO()

    propertySubcategoryVO.propertySubcategoryName = request.form[
        'propertySubcategoryName']
    propertySubcategoryVO.propertySubcategoryDescription = request.form[
        'propertySubcategoryDescription']
    propertySubcategoryVO.propertySubcategory_PropertyCategoryId = request.form[
        'propertyCategoryId']
    propertySubcategoryVO.propertySubcategoryActiveStatus = 'active'

    propertySubcategoryDAO.insertPropertySubcategory(propertySubcategoryVO)

    return redirect(url_for('loadPropertySubcategory'))
def updatePropertySubcategory():

    propertySubcategoryDAO = PropertySubcategoryDAO()
    propertySubcategoryVO = PropertySubcategoryVO()

    propertySubcategoryVO.propertySubcategoryName = request.form[
        'propertySubcategoryName']
    propertySubcategoryVO.propertySubcategoryDescription = request.form[
        'propertySubcategoryDescription']
    propertySubcategoryVO.propertySubcategory_PropertyCategoryId = request.form[
        'propertyCategoryId']
    propertySubcategoryVO.propertySubcategoryId = request.form[
        'propertySubcategoryId']

    propertySubcategoryDAO.updatePropertySubcategory(propertySubcategoryVO)

    return redirect(url_for('viewPropertySubcategory'))