Ejemplo n.º 1
0
def post_project(data):
    try:
        request_data = json.loads(data) if isinstance(data, unicode) else data
        user_email = putil.validate_for_user_id_exists(
            request_data.get("user_id"))
        user_data = frappe.db.get_value("User", {"email": user_email},
                                        "user_type",
                                        as_dict=True)
        if user_data.get("user_type") == "System User":
            project_data = putil.validate_property_posting_data(
                request_data, "property_json/project_post_mapper.json")
            property_details = putil.validate_project_posting_data(
                project_data.get("property_details"),
                "property_json/project_child_table.json")
            project_data["property_details"] = property_details
            project_id = init_for_project_posting(project_data, user_email,
                                                  request_data.get("user_id"))
            init_for_project_photo_upload(request_data, project_data)
            response_dict = {
                "operation": "Create",
                "user_id": request_data.get("user_id")
            }

            es = ElasticSearchController()
            response_data = es.index_document("project", project_data,
                                              project_data["project_id"])
            try:
                init_for_property_posting(project_data)
                response_dict["message"] = "Project Posted Successfully"
            except Exception, e:
                response_dict[
                    "message"] = "Project Posted Successfully but Property Posting Failed"
            response_dict["project_id"] = project_id
            return response_dict
        else:
Ejemplo n.º 2
0
def search_project(request_data):
	if request_data:
		project_data = json.loads(request_data)
		project_data = putil.validate_property_posting_data(project_data,"property_json/project_search.json")
		putil.isolate_city_from_location(project_data)
		search_query = putil.generate_project_search_query(project_data)
		try:
			es = ElasticSearchController()
			response_data, total_records = es.search_document(["project"], search_query, project_data.get("page_number",1), project_data.get("records_per_page",40))
			request_id = store_request_in_elastic_search(project_data, search_query, "Project Search")
			response_data = putil.get_date_diff_from_posting(response_data)
			response_msg = "Project found for specfied criteria" if len(response_data) else "Project not found"
			from_record = (project_data.get("page_number",1) - 1) * cint(project_data.get("records_per_page",40)) + 1
			no_of_pages = math.ceil(flt(total_records)/project_data.get("records_per_page",40))
			return {	
						"operation":"Search",
						 "message":response_msg ,
						 "total_records":total_records, 
						 "request_id":request_id, 
						 "records_per_page":project_data.get("records_per_page",40),
						 "from_record":from_record ,
						 "to_record":from_record +  len(response_data) - 1 if response_data else from_record + project_data.get("records_per_page",40) - 1,
						 "data":response_data, 
						 "user_id":project_data.get("user_id"), 
						 "no_of_pages":no_of_pages
					 }
		except elasticsearch.RequestError,e:
			raise ElasticInvalidInputFormatError(e.error)
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
Ejemplo n.º 3
0
def update_project(request_data):
    user_email = putil.validate_for_user_id_exists(
        request_data.get("fields").get("user_id"))
    try:
        field_dict = putil.validate_property_posting_data(
            request_data.get("fields"),
            "property_json/project_post_mapper.json")
        get_modified_datetime(field_dict, user_email)

        es = ElasticSearchController()
        update_project_photos(field_dict, request_data.get("fields"),
                              request_data.get("project_id"), es)
        field_dict["possession_status"] = "Immediate" if field_dict.get(
            "possession") else field_dict.get("possession_date")
        search_query = {"doc": field_dict}
        update_response = es.update_docuemnt("project",
                                             request_data.get("project_id"),
                                             search_query)
        percent_script = get_percent_completion_script(
            project_mandatory_fields)
        per_response = es.update_docuemnt("project",
                                          request_data.get("project_id"),
                                          percent_script)
        return {"opeartion": "Update", "message": "Project details Updated"}
    except elasticsearch.TransportError:
        raise DoesNotExistError("Project Id does not exists")
    except elasticsearch.ElasticsearchException, e:
        raise ElasticSearchException(e.error)
Ejemplo n.º 4
0
def validate_data_before_property_posting(request_data):
	
	"""
		Validate property posting data, convert area to sqft
		& other validatory tasks.
	"""

	email = putil.validate_for_user_id_exists(request_data.get("user_id"))
	subs_doc = putil.validate_for_postings_available(email)
	putil.convert_area_to_sqft_for_posting(request_data)
	putil.validate_property_status(request_data.get("status"))
	property_data = putil.validate_property_posting_data(request_data,"property_json/property_mapper.json")
	return property_data, email, subs_doc
Ejemplo n.º 5
0
def validate_data_before_property_posting(request_data):
	
	"""
		Validate property posting data, convert area to sqft
		& other validatory tasks.
	"""

	email = putil.validate_for_user_id_exists(request_data.get("user_id"))
	subs_doc = putil.validate_for_postings_available(email)
	putil.convert_area_to_sqft_for_posting(request_data)
	putil.validate_property_status(request_data.get("status"))
	property_data = putil.validate_property_posting_data(request_data,"property_json/property_mapper.json")
	return property_data, email, subs_doc
def update_project(request_data):
	user_email = putil.validate_for_user_id_exists(request_data.get("fields").get("user_id"))
	try:
		field_dict = putil.validate_property_posting_data(request_data.get("fields"), "property_json/project_post_mapper.json")
		get_modified_datetime(field_dict, user_email)
		
		es = ElasticSearchController()
		update_project_photos(field_dict, request_data.get("fields"), request_data.get("project_id"), es)
		field_dict["possession_status"] = "Immediate" if field_dict.get("possession") else field_dict.get("possession_date")
		search_query = {"doc": field_dict }
		update_response = es.update_docuemnt("project", request_data.get("project_id"), search_query)
		percent_script = get_percent_completion_script(project_mandatory_fields)
		per_response = es.update_docuemnt("project", request_data.get("project_id"), percent_script)
		return {"opeartion":"Update", "message":"Project details Updated"}
	except elasticsearch.TransportError:
		raise DoesNotExistError("Project Id does not exists")
	except elasticsearch.ElasticsearchException,e:
		raise ElasticSearchException(e.error)
Ejemplo n.º 7
0
def search_property(data):
	
	property_data = json.loads(data)
	property_data = putil.validate_property_posting_data(property_data, "property_json/property_search.json")
	putil.init_for_location_or_city_creation(property_data)
	putil.convert_area_to_sqft_for_search(property_data)
	try:	
		
		# generate search query & result generation & list of fields which should be excluded.

		exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", ""))

		search_query = putil.generate_search_query(property_data)
		adv_search_query = search_query
		search_query = cstr(search_query)
		putil.generate_advance_search_query(adv_search_query, property_data)

		es = ElasticSearchController()
		response_data, total_records = es.search_document(["property"], adv_search_query, property_data.get("page_number",1), 
										property_data.get("records_per_page",40), exclude_list)
		
		# post property-search operation

		if not property_data.get("request_id"):	
			request_id = store_request_in_elastic_search(property_data, search_query, "Property Search", adv_search_query)
		if property_data.get("user_id") != "Guest":				
			response_data = check_for_shortlisted_property(response_data,property_data.get("user_id"))
		response_data = putil.get_date_diff_and_count_from_posting(response_data)
		putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft."))
		putil.show_amenities_with_yes_status(response_data)
		
		# response data & pagination logic

		msg = "Property found for specfied criteria" if len(response_data) else "Property not found"
		response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records)
		response_dict["request_id"] = property_data.get("request_id") if property_data.get("request_id") else request_id 
		return response_dict

	except elasticsearch.RequestError,e:
		raise ElasticInvalidInputFormatError(e.error)
Ejemplo n.º 8
0
def search_project(request_data):
	if request_data:
		project_data = json.loads(request_data)
		project_data = putil.validate_property_posting_data(project_data,"property_json/project_search.json")
		putil.init_for_location_or_city_creation(project_data)
		search_query = putil.generate_project_search_query(project_data)
		try:
			project_fields = get_project_include_fields(project_data.get("request_source", ""))
			exclude_list = putil.get_exclude_list_for_search(project_data.get("request_source", ""))

			es = ElasticSearchController()
			response_data, total_records = es.search_document(["project"], search_query, project_data.get("page_number",1), project_data.get("records_per_page",40), exclude_list, project_fields)
			if not project_data.get("request_id"):	
				request_id = store_request_in_elastic_search(project_data, search_query, "Project Search")
			response_data = putil.get_date_diff_and_count_from_posting(response_data)
			putil.show_amenities_with_yes_status(response_data)
			# property_subtype_option = project_data.get("property_subtype_option","") 
			# get_valid_property_subtype_option(response_data, property_subtype_option) if property_subtype_option else ""


			response_msg = "Project found for specfied criteria" if len(response_data) else "Project not found"
			from_record = (project_data.get("page_number",1) - 1) * cint(project_data.get("records_per_page",40)) + 1
			no_of_pages = math.ceil(flt(total_records)/project_data.get("records_per_page",40))
			to_record = from_record +  len(response_data) - 1 if response_data else from_record + project_data.get("records_per_page",40) - 1
			return {	
						"operation":"Search",
						 "message":response_msg ,
						 "total_records":total_records, 
						 "request_id":project_data.get("request_id") if project_data.get("request_id") else request_id, 
						 "records_per_page":project_data.get("records_per_page",40),
						 "from_record":from_record ,
						 "to_record":to_record,
						 "data":response_data, 
						 "user_id":project_data.get("user_id"), 
						 "no_of_pages":no_of_pages
					 }
		except elasticsearch.RequestError,e:
			raise ElasticInvalidInputFormatError(e.error)
		except elasticsearch.ElasticsearchException,e:
			raise ElasticSearchException(e.error)
Ejemplo n.º 9
0
def search_property(data):
	
	property_data = json.loads(data)
	property_data = putil.validate_property_posting_data(property_data, "property_json/property_search.json")
	putil.init_for_location_or_city_creation(property_data)
	putil.convert_area_to_sqft_for_search(property_data)
	try:	
		
		# generate search query & result generation & list of fields which should be excluded.

		exclude_list = putil.get_exclude_list_for_search(property_data.get("request_source", ""))

		search_query = putil.generate_search_query(property_data)
		adv_search_query = search_query
		search_query = cstr(search_query)
		putil.generate_advance_search_query(adv_search_query, property_data)

		es = ElasticSearchController()
		response_data, total_records = es.search_document(["property"], adv_search_query, property_data.get("page_number",1), 
										property_data.get("records_per_page",40), exclude_list)
		
		# post property-search operation

		if not property_data.get("request_id"):	
			request_id = store_request_in_elastic_search(property_data, search_query, "Property Search", adv_search_query)
		if property_data.get("user_id") != "Guest":				
			response_data = check_for_shortlisted_property(response_data,property_data.get("user_id"))
		response_data = putil.get_date_diff_and_count_from_posting(response_data)
		putil.convert_area_according_to_uom(response_data, property_data.get("unit_of_area", "Sq.Ft."))
		putil.show_amenities_with_yes_status(response_data)
		
		# response data & pagination logic

		msg = "Property found for specfied criteria" if len(response_data) else "Property not found"
		response_dict = putil.init_pagination_and_response_generatrion(property_data, response_data, msg, total_records)
		response_dict["request_id"] = property_data.get("request_id") if property_data.get("request_id") else request_id 
		return response_dict

	except elasticsearch.RequestError,e:
		raise ElasticInvalidInputFormatError(e.error)
Ejemplo n.º 10
0
def post_project(data):
	try:
		request_data = json.loads(data) if isinstance(data,unicode) else data
		user_email = putil.validate_for_user_id_exists(request_data.get("user_id"))
		user_data = frappe.db.get_value("User",{"email":user_email}, "user_type", as_dict=True)
		if user_data.get("user_type") == "System User":
			project_data = putil.validate_property_posting_data(request_data,"property_json/project_post_mapper.json")
			property_details = putil.validate_project_posting_data(project_data.get("property_details"),"property_json/project_child_table.json")
			project_data["property_details"] = property_details
			project_id= init_for_project_posting(project_data, user_email, request_data.get("user_id"))
			init_for_project_photo_upload(request_data, project_data)
			response_dict= {"operation":"Create", "user_id":request_data.get("user_id")}
			
			es = ElasticSearchController()
			response_data = es.index_document("project", project_data, project_data["project_id"])
			try:
				init_for_property_posting(project_data)
				response_dict["message"] = "Project Posted Successfully"
			except Exception,e:
				response_dict["message"] ="Project Posted Successfully but Property Posting Failed"
			response_dict["project_id"] = project_id
			return response_dict				
		else:
Ejemplo n.º 11
0
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)