def get_similar_properties(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_type", "id"]) search_dict = {"property_id":get_search_query_of_property_id ,"request_id":get_search_query_of_request_id} if request_data.get("request_type") not in ["property_id", "request_id"]: raise InvalidDataError("Request type contains Invalid Data") search_query, uom = search_dict.get(request_data.get("request_type"))(request_data) try: sp_include_fields = ["property_photo", "property_id", "location", "address", "city", "carpet_area", "price","property_title"] es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",4), [], sp_include_fields) uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom putil.convert_area_according_to_uom(response_data, uom) response_msg = "Similar Property Found" if response_data else "Similar property not found" return { "operation":"Search", "message":response_msg , "total_records":len(response_data), "data":response_data, "user_id":request_data.get("user_id") } except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Similar property Operation Failed")
def share_property(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) user_name = frappe.db.get_value("User", {"user_id":request_data.get("user_id")}, ["first_name", "last_name"],as_dict=True) putil.validate_property_data(request_data, ["comments", "email_id"]) try: property_ids_list = { comment.get("property_id"):comment.get("comment","") for comment in request_data.get("comments") if comment.get("property_id")} search_query = { "query":{ "ids":{ "values":property_ids_list.keys() } }} es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",40)) if response_data: for response in response_data: response["comments"] = property_ids_list.get(response.get("property_id"),"") args = { "title":"Property Shared by {0}".format(email) , "property_data":response_data ,"first_name":user_name.get("first_name"), "last_name":user_name.get("last_name")} send_email(request_data.get("email_id"), "Propshikari properties shared with you", "/templates/share_property_template.html", args) return { "operation":"Share", "message":"Property Shared"} else: raise DoesNotExistError("Property Id does not exists in elastic search") except frappe.OutgoingEmailError: raise OutgoingEmailError("Email can not be sent,Outgoing email error") except elasticsearch.TransportError: raise DoesNotExistError("Property Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Share Property Operation Failed")
def join_user_with_group_id(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["user_id", "group_id"]) if not frappe.db.get_value( "Group", {"name": request_data.get("group_id")}, "name"): raise DoesNotExistError("Group ID {0} does not exists".format( request_data.get("group_id"))) if frappe.db.get_value( "Group User", { "group_id": request_data.get("group_id"), "user_id": request_data.get("user_id") }, "name"): raise DuplicateEntryError("Group {0} already joined".format( request_data.get("group_id"))) try: grusr = frappe.new_doc("Group User") grusr.user_id = request_data.get("user_id") grusr.group_id = request_data.get("group_id") grusr.user = email grusr.save() return {"operation": "Search", "message": "Group joined"} except frappe.MandatoryError, e: raise MandatoryError("Mandatory Field {0} missing".format( e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def get_location_details_for_map(request_data): request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_id"]) try: es = ElasticSearchController() response = es.search_document_for_given_id("request",request_data.get("request_id"),[], ["search_query", "unit_of_area", "adv_search_query"]) search_query = ast.literal_eval(response.get("adv_search_query").encode("utf8")) uom = response.get("unit_of_area") include_fields = ["property_title", "property_id", "location", "property_subtype_option", "operation", "carpet_area", "price", "geo_location_lat", "geo_location_lon" ] size = get_count_of_property_records(es) response_data, total_records = es.search_document(["property"], search_query, 1, size, [], include_fields) uom = "Sq.Ft." if uom not in ["Sq.Ft.", "Acres", "Hectares"] else uom putil.convert_area_according_to_uom(response_data, uom) response_msg = "User Property Found" if response_data else "User property not found" return { "operation":"Search", "user_id":request_data.get("user_id"), "message":response_msg, "data":response_data } except elasticsearch.TransportError: raise DoesNotExistError("Request Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
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.init_for_location_or_city_creation(request_data) request_data["property_subtype_option"] = ','.join(request_data.get("property_subtype_option")) if request_data.get("property_subtype_option") else " " alert_search_conditions = make_conditions_for_duplicate_group(request_data, "Alerts") 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))
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.init_for_location_or_city_creation(request_data) request_data["property_subtype_option"] = ','.join(request_data.get("property_subtype_option")) if request_data.get("property_subtype_option") else " " group_search_conditions = make_conditions_for_duplicate_group(request_data, "Group") 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)
def update_password(data): user_data = json.loads(data) putil.validate_property_data(user_data, ["old_password", "new_password"]) user_email = putil.validate_for_user_id_exists(user_data.get("user_id")) check_password = frappe.db.sql( """select `user` from __Auth where `user`=%s and `password`=password(%s)""", (user_email, user_data.get("old_password"))) if not check_password: raise InvalidPasswordError("Invalid Old Password") else: try: new_password = user_data.get("new_password") _update_password(user_email, new_password) user_info = frappe.db.get("User", {"email": user_email}) args = { "first_name": user_info.get("first_name"), "new_password": new_password, "last_name": user_info.get("last_name") } send_email(user_email, "Password Update Notification", "/templates/password_update.html", args) return { "operation": "Password Update", "message": "Password updated successfully", "user_id": user_data.get("user_id") } except frappe.OutgoingEmailError: raise OutgoingEmailError( "Password Updated successfully but email not sent.") except Exception, e: raise ForgotPasswordOperationFailed( "Update password operation failed")
def register_user(data): user_data = json.loads(data) user = frappe.db.get("User", {"email": user_data.get("email")}) putil.validate_property_data( user_data, ["email", "first_name", "mobile_number", "password", "access_type"]) if user: if user.disabled: raise UserRegisteredButDisabledError( "User {0} Registered but disabled".format( user_data.get("email"))) else: raise UserAlreadyRegisteredError( "User {0} already Registered".format(user_data.get("email"))) else: try: user_id = "USR-" + cstr(int(time.time())) + '-' + cstr( random.randint(1000, 9999)) user = frappe.get_doc({ "doctype": "User", "email": user_data.get("email"), "first_name": user_data.get("first_name"), "enabled": 1, "last_name": user_data.get("last_name"), "new_password": user_data.get("password"), "user_id": user_id, "mobile_no": user_data.get("mobile_number"), "access_type": user_data.get("access_type"), "user_type": "Website User", "user_image": "assets/propshikari/default_user.gif", "send_welcome_email": 0 }) user.flags.ignore_permissions = True user.insert() args = { "title": "Welcome to Propshikari", "first_name": user_data.get("first_name"), "last_name": user_data.get("last_name"), "user": user_data.get("email"), "password": user_data.get("password") } manage_subscription(user) create_mascot_status_for_user(user_id) send_email(user_data.get("email"), "Welcome to Propshikari", "/templates/new_user_template.html", args) login(data) frappe.response["message"] = "User Registeration done Successfully" return {"data": frappe.response.get("data")} except frappe.OutgoingEmailError: frappe.response["user_id"] = user_id raise OutgoingEmailError( "User registered successfully but email not sent.") except frappe.MandatoryError, e: raise MandatoryError("Mandatory Field {0} missing".format( e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def create_property_seen_entry(data): request_data = json.loads(data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["property_id"]) try: pa = frappe.new_doc("Property Alerts") pa.user_id =request_data.get("user_id") pa.property_id = request_data.get("property_id") pa.save(ignore_permissions=True) return {"operation":"Create", "message":"Alert property {0} registered successfully.".format(request_data.get("property_id"))} except Exception,e: raise OperationFailed("Make Property alerts operation failed")
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.init_for_location_or_city_creation(request_data) request_data["property_subtype_option"] = ','.join( request_data.get("property_subtype_option")) if request_data.get( "property_subtype_option") else " " group_search_conditions = make_conditions_for_duplicate_group( request_data, "Group") 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)
def upadate_project_status(request_data): email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["project_id"]) try: search_query = {"doc":{ "status":request_data.get("project_status") }} es = ElasticSearchController() response = es.update_docuemnt("project", request_data.get("project_id"), search_query) return { "operation":"Update" , "message":"Project status changed" if response else "Project Status not changed", "user_id":request_data.get("user_id") } except elasticsearch.TransportError: raise DoesNotExistError("Project Id does not exists") except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error)
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.init_for_location_or_city_creation(request_data) request_data["property_subtype_option"] = ','.join( request_data.get("property_subtype_option")) if request_data.get( "property_subtype_option") else " " alert_search_conditions = make_conditions_for_duplicate_group( request_data, "Alerts") 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))
def create_feedback(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_type", "feedback"]) try: fdbk = frappe.new_doc("Feedback") fdbk.property_id = request_data.get("property_id") fdbk.request_type = request_data.get("request_type") fdbk.user_feedback = request_data.get("feedback") fdbk.user_ratings = request_data.get("ratings") fdbk.user_id = request_data.get("user_id") fdbk.save() return {"operation":"Create", "message":"Feedback Submitted"} except frappe.MandatoryError,e: raise MandatoryError("Mandatory Field {0} missing".format(e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def create_property_seen_entry(data): request_data = json.loads(data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["property_id"]) try: pa = frappe.new_doc("Property Alerts") pa.user_id = request_data.get("user_id") pa.property_id = request_data.get("property_id") pa.save(ignore_permissions=True) return { "operation": "Create", "message": "Alert property {0} registered successfully.".format( request_data.get("property_id")) } except Exception, e: raise OperationFailed("Make Property alerts operation failed")
def register_user(data): user_data = json.loads(data) user = frappe.db.get("User", {"email": user_data.get("email")}) putil.validate_property_data(user_data,["email","first_name","mobile_number","password","access_type"]) if user: if user.disabled: raise UserRegisteredButDisabledError("User {0} Registered but disabled".format(user_data.get("email"))) else: raise UserAlreadyRegisteredError("User {0} already Registered".format(user_data.get("email"))) else: try: user_id = "USR-" + cstr(int(time.time())) + '-' + cstr(random.randint(1000,9999)) user = frappe.get_doc({ "doctype":"User", "email":user_data.get("email"), "first_name": user_data.get("first_name"), "enabled": 1, "last_name": user_data.get("last_name"), "new_password": user_data.get("password"), "user_id": user_id, "mobile_no": user_data.get("mobile_number"), "access_type" :user_data.get("access_type"), "user_type": "Website User", "user_image":"assets/propshikari/default_user.gif", "send_welcome_email":0 }) user.flags.ignore_permissions = True user.insert() args = { "title":"Welcome to Propshikari", "first_name":user_data.get("first_name"), "last_name":user_data.get("last_name"), "user":user_data.get("email"), "password":user_data.get("password") } manage_subscription(user) create_mascot_status_for_user(user_id) send_email(user_data.get("email"), "Welcome to Propshikari", "/templates/new_user_template.html", args) login(data) frappe.response["message"] = "User Registeration done Successfully" return {"data":frappe.response.get("data")} except frappe.OutgoingEmailError: frappe.response["user_id"] = user_id raise OutgoingEmailError("User registered successfully but email not sent.") except frappe.MandatoryError,e: raise MandatoryError("Mandatory Field {0} missing".format(e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def get_similar_properties(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_type", "id"]) search_dict = {"property_id":get_search_query_of_property_id ,"request_id":get_search_query_of_request_id} if request_data.get("request_type") not in ["property_id", "request_id"]: raise InvalidDataError("Request type contains Invalid Data") search_query = search_dict.get(request_data.get("request_type"))(request_data) try: es = ElasticSearchController() response_data, total_records = es.search_document(["property"], search_query, request_data.get("page_number",1), request_data.get("records_per_page",3)) from_record = ((request_data.get("page_number",1) - 1) * cint(request_data.get("records_per_page",3)) + 1 ) response_msg = "Similar Property Found" if response_data else "Similar property not found" no_of_pages = math.ceil(flt(total_records)/request_data.get("records_per_page",3)) return {"operation":"Search", "message":response_msg ,"total_records":total_records,"records_per_page":request_data.get("records_per_page",3),"from_record":from_record ,"to_record": from_record + len(response_data) - 1 if response_data else from_record + request_data.get("records_per_page",3) - 1 ,"data":response_data, "user_id":request_data.get("user_id"), "no_of_pages":no_of_pages} except elasticsearch.ElasticsearchException,e: raise ElasticSearchException(e.error) except Exception,e: raise OperationFailed("Get Similar property Operation Failed")
def join_user_with_group_id(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data,["user_id","group_id"]) if not frappe.db.get_value("Group",{"name":request_data.get("group_id")},"name"): raise DoesNotExistError("Group ID {0} does not exists".format(request_data.get("group_id"))) if frappe.db.get_value("Group User",{"group_id":request_data.get("group_id"), "user_id":request_data.get("user_id")},"name"): raise DuplicateEntryError("Group {0} already joined".format(request_data.get("group_id"))) try: grusr = frappe.new_doc("Group User") grusr.user_id = request_data.get("user_id") grusr.group_id = request_data.get("group_id") grusr.user = email grusr.save() return {"operation":"Search", "message":"Group joined"} except frappe.MandatoryError,e: raise MandatoryError("Mandatory Field {0} missing".format(e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def create_feedback(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_type", "feedback"]) try: fdbk = frappe.new_doc("Feedback") fdbk.property_id = request_data.get("property_id") fdbk.request_type = request_data.get("request_type") fdbk.user_feedback = request_data.get("feedback") fdbk.user_ratings = request_data.get("ratings") fdbk.user_id = request_data.get("user_id") fdbk.save() return {"operation": "Create", "message": "Feedback Submitted"} except frappe.MandatoryError, e: raise MandatoryError("Mandatory Field {0} missing".format( e.message)) except (frappe.LinkValidationError, frappe.ValidationError) as e: raise InvalidDataError(e.message)
def store_image_to_propshikari(request_data): request_data = json.loads(request_data) putil.validate_property_data(request_data,["profile_photo"]) if not request_data.get("profile_photo").get("file_ext"): raise MandatoryError("Image Extension not found") user_email = putil.validate_for_user_id_exists(request_data.get("user_id")) if not os.path.exists(frappe.get_site_path("public","files",request_data.get("user_id"))): os.mkdir(frappe.get_site_path("public","files",request_data.get("user_id"))) try: base64_data = request_data.get("profile_photo").get("file_data").encode("utf8") base64_data = base64_data.split(',')[1] imgdata = base64.b64decode(base64_data) file_name = "PSUI-" + cstr(time.time()) + '.' + request_data.get("profile_photo").get("file_ext") with open(frappe.get_site_path("public","files",request_data.get("user_id"),file_name),"wb+") as fi_nm: fi_nm.write(imgdata) file_name = "files/"+request_data.get("user_id")+'/'+file_name frappe.db.set_value(dt="User",dn=user_email, field="user_image", val=file_name) return {"operation":"Update", "message":"Profile Image updated Successfully", "profile_image_url":frappe.request.host_url + file_name, "user_id":request_data.get("user_id")} except Exception,e: raise ImageUploadError("Profile Image Updation Failed")
def update_password(data): user_data = json.loads(data) putil.validate_property_data(user_data,["old_password","new_password"]) user_email = putil.validate_for_user_id_exists(user_data.get("user_id")) check_password = frappe.db.sql("""select `user` from __Auth where `user`=%s and `password`=password(%s)""", (user_email, user_data.get("old_password") )) if not check_password: raise InvalidPasswordError("Invalid Old Password") else: try: new_password = user_data.get("new_password") _update_password(user_email, new_password) user_info = frappe.db.get("User", {"email": user_email}) args = {"first_name":user_info.get("first_name"), "new_password":new_password, "last_name":user_info.get("last_name")} send_email(user_email, "Password Update Notification", "/templates/password_update.html", args) return {"operation":"Password Update", "message":"Password updated successfully", "user_id":user_data.get("user_id")} except frappe.OutgoingEmailError: raise OutgoingEmailError("Password Updated successfully but email not sent.") except Exception,e: raise ForgotPasswordOperationFailed("Update password operation failed")
def search_group_with_given_criteria(request_data): if request_data: request_data = json.loads(request_data) email = putil.validate_for_user_id_exists(request_data.get("user_id")) putil.validate_property_data(request_data, ["request_id"]) try: es = ElasticSearchController() response = es.search_document_for_given_id("request",request_data.get("request_id")) group_search_conditions = make_conditions_for_duplicate_group(response, "Group") group_result = frappe.db.sql(""" SELECT name AS group_id, operation, property_type, property_subtype, group_title, ifnull(property_subtype_option, "") AS property_subtype_option, ifnull(location, "") AS location, ifnull(city, "") AS city, ifnull(min_budget, "") AS min_budget, ifnull(max_budget, "") AS max_budget, ifnull(min_area, "") AS min_area, ifnull(max_area, "") AS max_area FROM `tabGroup` {0} """.format(group_search_conditions),as_dict=True) for group in group_result: join_flag = frappe.db.get_value("Group User" , {"group_id":group.get("group_id"), "user_id":request_data.get("user_id")},"name") group["user_joined"] = 1 if join_flag else 0 group_result = group_result[0] if group_result else {} return { "operation":"Search", "request_id":request_data.get("request_id"), "data":group_result, "message":"Matching Group Found" if len(group_result) else "Group Not Found" } except elasticsearch.TransportError: raise DoesNotExistError("Request Id does not exists") except Exception,e: raise SearchGroupOperationFailed("Search Group Operation Failed")
def store_image_to_propshikari(request_data): request_data = json.loads(request_data) putil.validate_property_data(request_data, ["profile_photo"]) if not request_data.get("profile_photo").get("file_ext"): raise MandatoryError("Image Extension not found") user_email = putil.validate_for_user_id_exists(request_data.get("user_id")) if not os.path.exists( frappe.get_site_path("public", "files", request_data.get("user_id"))): os.mkdir( frappe.get_site_path("public", "files", request_data.get("user_id"))) try: base64_data = request_data.get("profile_photo").get( "file_data").encode("utf8") base64_data = base64_data.split(',')[1] imgdata = base64.b64decode(base64_data) file_name = "PSUI-" + cstr(time.time()) + '.' + request_data.get( "profile_photo").get("file_ext") with open( frappe.get_site_path("public", "files", request_data.get("user_id"), file_name), "wb+") as fi_nm: fi_nm.write(imgdata) file_name = "files/" + request_data.get("user_id") + '/' + file_name frappe.db.set_value(dt="User", dn=user_email, field="user_image", val=file_name) return { "operation": "Update", "message": "Profile Image updated Successfully", "profile_image_url": frappe.request.host_url + file_name, "user_id": request_data.get("user_id") } except Exception, e: raise ImageUploadError("Profile Image Updation Failed")