def process_property_data_before_posting(property_data, request_data, email):
	
	"""
		Add necessary fields to property dictionary
		before indexing property data, 
		store image in full size & thumbnails format. 

	"""

	custom_id = "PROP-"  + cstr(int(time.time())) + '-' +  cstr(random.randint(10000,99999))
	property_data["property_id"] = custom_id
	meta_dict = add_meta_fields_before_posting(request_data)
	property_data.update(meta_dict)
	property_photo_url_dict = store_property_photos_in_propshikari(request_data.get("property_photos"),custom_id)
	property_data["full_size_images"] = property_photo_url_dict.get("full_size",[])
	property_data["thumbnails"] = property_photo_url_dict.get("thumbnails",[])
	property_data["property_photo"] = property_photo_url_dict.get("thumbnails")[0] if len(property_photo_url_dict.get("thumbnails")) else ""
	property_data["posted_by"] = request_data.get("user_id")
	property_data["user_email"] = email
	property_data["posting_date"] = property_data.get("posting_date") if property_data.get("posting_date") else property_data.get("creation_date")
	property_data["amenities"] = putil.prepare_amenities_data(property_data.get("amenities",""), property_data.get("property_type"))
	property_data["flat_facilities"] = putil.prepare_flat_facilities_data(property_data.get("flat_facilities",""), property_data.get("property_type"))
	property_data["possession_status"] = "Immediate" if property_data.get("possession") else property_data.get("possession_date")
	property_data["discounted_price"] = putil.get_discounted_price(property_data) if property_data.get("discount_percentage") else 0.0
	mandatory_list = property_mandatory_fields.get(property_data.get("property_type"))
	property_data["percent_completion"] = putil.calculate_percent_completion(property_data, mandatory_list)
	if not property_data.get("possession_date"):
		property_data.pop("possession_date", None)
	return custom_id	
def prepare_property_posting_data(project_data):
    property_data = []
    new_project_data = get_property_specific_keys(project_data)

    for prop in project_data.get("property_details"):
        prop_dict = {}
        prop_list = []
        prop_dict["property_title"] = project_data.get("project_name")
        prop_dict["property_type"] = prop.get("property_type")
        prop_dict["property_subtype"] = prop.get("property_subtype")
        prop_dict["property_subtype_option"] = prop.get(
            "property_subtype_option", "")
        prop_dict["operation"] = project_data.get("operation")
        prop_dict["carpet_area"] = prop.get("max_area")
        prop_dict["price"] = prop.get("max_price")
        prop_dict["unit_of_area"] = prop.get("unit_of_area")
        prop_dict["published_status"] = "Unpublished"
        prop_dict["property_photo"] = project_data.get("project_photo", "")
        prop_dict["flat_facilities"] = putil.prepare_flat_facilities_data(
            [], prop.get("property_type"))
        prop_dict.update(new_project_data)
        mandatory_list = property_mandatory_fields.get(
            prop.get("property_type"))
        prop_dict["status"] = "Deactivated"
        prop_dict["tag"] = []
        prop_dict["percent_completion"] = putil.calculate_percent_completion(
            prop_dict, mandatory_list)
        prop_list = [prop_dict] * cint(prop.get("count"))
        property_data.extend(prop_list)
    return property_data
def prepare_property_posting_data(project_data):
	property_data = []
	new_project_data = get_property_specific_keys(project_data)

	for prop in project_data.get("property_details"):
		prop_dict = {}
		prop_list = []
		prop_dict["property_title"] =  project_data.get("project_name")
		prop_dict["property_type"] = prop.get("property_type")
		prop_dict["property_subtype"] = prop.get("property_subtype")
		prop_dict["property_subtype_option"] = prop.get("property_subtype_option", "")
		prop_dict["operation"] = project_data.get("operation")
		prop_dict["carpet_area"] = prop.get("max_area")
		prop_dict["price"] = prop.get("max_price")
		prop_dict["unit_of_area"] = prop.get("unit_of_area")
		prop_dict["published_status"] = "Unpublished"
		prop_dict["property_photo"] = project_data.get("project_photo","")
		prop_dict["flat_facilities"] = putil.prepare_flat_facilities_data([], prop.get("property_type"))
		prop_dict.update(new_project_data)
		mandatory_list = property_mandatory_fields.get(prop.get("property_type"))
		prop_dict["status"] = "Deactivated"
		prop_dict["tag"] = []
		prop_dict["percent_completion"] = putil.calculate_percent_completion(prop_dict, mandatory_list)
		prop_list = [prop_dict] * cint(prop.get("count"))
		property_data.extend(prop_list)
	return property_data	
def process_property_data_before_posting(property_data, request_data, email):
	
	"""
		Add necessary fields to property dictionary
		before indexing property data, 
		store image in full size & thumbnails format. 

	"""
	custom_id = "PROP-"  + cstr(int(time.time())) + '-' +  cstr(random.randint(10000,99999))
	property_data["property_id"] = custom_id
	meta_dict = add_meta_fields_before_posting(request_data)
	property_data.update(meta_dict)
	property_photo_url_dict = store_property_photos_in_propshikari(request_data.get("property_photos"),custom_id)
	property_data["full_size_images"] = property_photo_url_dict.get("full_size",[])
	property_data["thumbnails"] = property_photo_url_dict.get("thumbnails",[])
	property_data["property_photo"] = property_photo_url_dict.get("thumbnails")[0] if len(property_photo_url_dict.get("thumbnails")) else ""
	property_data["posted_by"] = request_data.get("user_id")
	property_data["user_email"] = email
	property_data["posting_date"] = property_data.get("posting_date") if property_data.get("posting_date") else property_data.get("creation_date")
	property_data["amenities"] = putil.prepare_amenities_data(property_data.get("amenities",""), property_data.get("property_type"))
	property_data["flat_facilities"] = putil.prepare_flat_facilities_data(property_data.get("flat_facilities",""), property_data.get("property_type"))
	property_data["possession_status"] = "Immediate" if property_data.get("possession") else property_data.get("possession_date")
	property_data["discounted_price"] = putil.get_discounted_price(property_data) if property_data.get("discount_percentage") else 0.0
	mandatory_list = property_mandatory_fields.get(property_data.get("property_type"))
	property_data["percent_completion"] = putil.calculate_percent_completion(property_data, mandatory_list)
	# added by arpit for  published_status
	if request_data.get("request_source") == "bulk_upload":
		property_data["published_status"] = "published"
		property_data["status"] = "Active"
	else:
		property_data["published_status"] = "Unpublished"
		property_data["status"] = "Deactivated"
			
	property_data["tag"] = property_data.get("tag") if property_data.get("tag") else []
	# end of code
	if not property_data.get("possession_date"):
		property_data.pop("possession_date", None)
	return custom_id	
def post_property(data):
	if data:
		try:
			old_data = json.loads(data)
			email = putil.validate_for_user_id_exists(old_data.get("user_id"))
			subs_doc = putil.validate_for_postings_available(email)
			data = putil.validate_property_posting_data(old_data,"property_json/property_mapper.json")
			putil.validate_property_status(data.get("status"))
			custom_id = "PROP-"  + cstr(int(time.time())) + '-' +  cstr(random.randint(10000,99999))
			data["property_id"] = custom_id
			meta_dict = add_meta_fields_before_posting(old_data)
			data.update(meta_dict)
			# return store_property_photos_in_propshikari(old_data.get("property_photos"),custom_id)
			property_photo_url_dict = store_property_photos_in_propshikari(old_data.get("property_photos"),custom_id)
			data["full_size_images"] = property_photo_url_dict.get("full_size",[])
			data["thumbnails"] = property_photo_url_dict.get("thumbnails",[])
			data["property_photo"] = property_photo_url_dict.get("thumbnails")[0] if len(property_photo_url_dict.get("thumbnails")) else ""
			data["posted_by"] = old_data.get("user_id")
			data["user_email"] = email
			data["posting_date"] = data.get("posting_date") if data.get("posting_date") else data["creation_date"]
			data["amenities"] = putil.prepare_amenities_data(data.get("amenities",""), data.get("property_type"))
			data["flat_facilities"] = putil.prepare_flat_facilities_data(data.get("flat_facilities",""), data.get("property_type"))
			data["possession_status"] = "Immediate" if data.get("possession") else data.get("possession_date")
			data.pop("possession_date", None)
			es = ElasticSearchController()
			response_data = es.index_document("property",data, custom_id)
			if subs_doc and response_data.get("created"):
				subs_doc.posted = cint(subs_doc.posted) + 1
				subs_doc.save(ignore_permissions=True)
			subscription = putil.get_subscriptions(email)
			response_msg = "Property posted successfully" if response_data.get("created",False) else "Property posting failed" 
			return {"operation":"Create", "message":response_msg, "property_id":response_data.get("_id"), "user_id":old_data.get("user_id"),"data":{"subscriptions":subscription}}	
		except elasticsearch.RequestError,e:
			raise ElasticInvalidInputFormatError(e.error)
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)