Пример #1
0
def create_group_in_hunterscamp(request_data):
	if request_data:
		request_data = json.loads(request_data)
		putil.validate_for_user_id_exists(request_data.get("user_id"))
		putil.validate_property_data(request_data, ["operation", "property_type", "property_subtype"])
		putil.isolate_city_from_location(request_data)
		group_search_conditions = make_conditions_for_duplicate_group(request_data)
		group_result = frappe.db.sql(""" select  name from `tabGroup` {0} """.format(group_search_conditions),as_dict=True)
		if group_result:
			group_result = [ group.get("name") for group in group_result if group ]
			raise DuplicateEntryError("Group {0} with same configuration already exists".format(','.join(group_result)))
		try:
			gr_doc = frappe.new_doc("Group")
			gr_doc.group_title = request_data.get("group_title")
			gr_doc.operation = request_data.get("operation")
			gr_doc.property_type =  request_data.get("property_type")
			gr_doc.property_subtype = request_data.get("property_subtype")
			gr_doc.location = request_data.get("location")
			gr_doc.property_subtype_option = request_data.get("property_subtype_option")
			gr_doc.creation_via  = "Website"
			gr_doc.min_area = request_data.get("min_area")
			gr_doc.max_area = request_data.get("max_area")
			gr_doc.min_budget = request_data.get("min_budget")
			gr_doc.max_budget = request_data.get("max_budget")
			gr_doc.unit_of_area = request_data.get("unit_of_area")
			gr_doc.city =request_data.get("city")
			gr_doc.status = "Active"
			gr_doc.save()
			return {"operation":"Create", "group_id":gr_doc.name, "message":"Group Created"}
		except frappe.MandatoryError,e:
			raise MandatoryError("Mandatory Field {0} missing".format(e.message))
		except (frappe.LinkValidationError, frappe.ValidationError)  as e:
			raise InvalidDataError(e.message)
Пример #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)
Пример #3
0
def create_alerts(request_data):
	request_data = json.loads(request_data)
	putil.validate_for_user_id_exists(request_data.get("user_id"))
	putil.validate_property_data(request_data, ["operation", "property_type", "property_subtype"])
	putil.isolate_city_from_location(request_data)
	alert_search_conditions = make_conditions_for_duplicate_group(request_data)
	alert_result = frappe.db.sql(""" select  name from `tabAlerts` {0} """.format(alert_search_conditions),as_dict=True)
	if alert_result:
		alert_result = [ alert.get("name") for alert in alert_result if alert ]
		raise DuplicateEntryError("Alert {0} with same configuration already exists".format(','.join(alert_result)))
	try:
		alrt = frappe.new_doc("Alerts")
		alrt.alert_title = request_data.get("alert_title")
		alrt.operation = request_data.get("operation")
		alrt.property_type =  request_data.get("property_type")
		alrt.property_subtype = request_data.get("property_subtype")
		alrt.location = request_data.get("location")
		alrt.property_subtype_option = request_data.get("property_subtype_option")
		alrt.creation_via  = "Website"
		alrt.min_area = request_data.get("min_area")
		alrt.max_area = request_data.get("max_area")
		alrt.min_budget = request_data.get("min_budget")
		alrt.max_budget = request_data.get("max_budget")
		alrt.unit_of_area = request_data.get("unit_of_area")
		alrt.user_id = request_data.get("user_id")
		alrt.city = request_data.get("city")
		alrt.status = "Active"
		alrt.save()
		return {"operation":"Create", "alert_id":alrt.name, "message":"Alert Created"}
	except frappe.MandatoryError,e:
		raise MandatoryError("Mandatory Field {0} missing".format(e.message))