def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = SupplierDeleteProductRequest.pre_deserialize(json_dict) res = self.is_session_valid() if not res: return False, Result.language.SESSION_KEY_IS_NOT_VALID if result[0]: self.phone_number = SessionManager.retrieve_session_value_by_key( key=Keys.PHONE_NUMBER) self.supplier_id = SessionManager.retrieve_session_value_by_key( key=Keys.USER_ID) # check_supplier = Supplier.check_supplier(self.phone_number) # if check_supplier[0]: # self.supplier_id = check_supplier[1] result = SupplierDeleteProductRequest.pre_deserialize(json_dict) if result[0]: self.product_id = json_dict[Keys.PRODUCT_ID] result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def deserialize(self): res = self.is_session_valid() if not res: return False, Result.language.SESSION_KEY_IS_NOT_VALID self.phone_number = SessionManager.retrieve_session_value_by_key( key=Keys.PHONE_NUMBER) self.business_owner_id = SessionManager.retrieve_session_value_by_key( key=Keys.USER_ID) return True, self
def deserialize(self): result = SupplierDailyPurchaseListRequest.pre_deserialize() if result[0]: self.phone_number = SessionManager.retrieve_session_value_by_key(key=Keys.PHONE_NUMBER) self.user_id = SessionManager.retrieve_session_value_by_key(key=Keys.USER_ID) result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def login_required_wrapper(*args, **kwds): if not SessionManager.is_key_exist( Keys.USER_ID) or SessionManager.retrieve_session_value_by_key( Keys.USER_ID) is None: dct = { "type": "failure", "message": "you should login first", "status": HttpStatus.BAD_REQUEST } return make_response(jsonify(dct), dct["status"]) return controller(*args, **kwds)
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = SupplierManageProductInfoRequest.pre_deserialize(json_dict) res = self.is_session_valid() if not res: return False, Result.language.SESSION_KEY_IS_NOT_VALID if result[0]: self.phone_number = SessionManager.retrieve_session_value_by_key( key=Keys.PHONE_NUMBER) self.supplier_id = SessionManager.retrieve_session_value_by_key( key=Keys.USER_ID) code = json_dict[Keys.CODE] company_id = json_dict[Keys.COMPANY_ID] sub_category_id = json_dict[Keys.SUB_CATEGORY_ID] brand_id = json_dict[Keys.BRAND_ID] price = json_dict[Keys.PRICE] minimum_order = json_dict[Keys.MINIMUM_ORDER] check_id_existence = self.check_optional_item_is_in_dict( json_dict, Keys.ID) if check_id_existence[0]: id = json_dict[Keys.ID] description_result = self.check_optional_item_is_in_dict( json_dict, Keys.DESCRIPTION) if description_result[0]: description = json_dict[Keys.DESCRIPTION] product = Product(minimum_order=minimum_order, company_id=company_id, code=code, sub_category_id=sub_category_id, price=price, supplier_id=self.supplier_id, brand_id=brand_id, description=description) else: product = Product(minimum_order=minimum_order, company_id=company_id, code=code, sub_category_id=sub_category_id, price=price, supplier_id=self.supplier_id, brand_id=brand_id) self.product = product result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = SearchOnProductsRequest.pre_deserialize(json_dict) res = self.is_session_valid() if not res: return False, Result.language.SESSION_KEY_IS_NOT_VALID if result[0]: self.options = json_dict[Keys.OPTIONS] self.phone_number = SessionManager.retrieve_session_value_by_key(key=Keys.PHONE_NUMBER) self.supplier_id = SessionManager.retrieve_session_value_by_key(key=Keys.USER_ID) self.options[Keys.SUPPLIER_ID] = self.supplier_id result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, result_pattern[1] return result
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = ListJobsByStatusRequest.pre_deserialize(json_dict) if not result[0]: return result self.business_owner = BusinessOwner(id=SessionManager.retrieve_session_value_by_key(Keys.USER_ID)) self.status = json_dict[Keys.STATUS] result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = CancellationByCarOwnerRequest.pre_deserialize(json_dict) if result[0]: self.job = Job(json_dict[Keys.JOB_ID]) self.car_owner = CarOwner( id=SessionManager.retrieve_session_value_by_key(Keys.USER_ID)) result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self.job return result
def pre_deserialize(json_dict): """ before deserializing, run this method. It help to check json and confirm it's schema. :param json_dict: :return: """ missed_params = [] if not SessionManager.is_key_exist(Keys.USER_ID): missed_params.append(Result.language.MISSING_BUSINESS_OWNER_ID_IN_JSON) if Keys.STATUS not in json_dict: missed_params.append(Result.language.MISSING_STATUS_IN_JSON) if len(missed_params) > 0: return False, missed_params return True,
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = ChangePasswordRequest.pre_deserialize(json_dict) if result[0]: self.phone_number = SessionManager.retrieve_session_value_by_key( Keys.PHONE_NUMBER) self.old_password = json_dict[Keys.OLD_PASSWORD] self.new_password = json_dict[Keys.NEW_PASSWORD] self.type_user = json_dict[Keys.TYPE_USER] result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = RateJobRequest.pre_deserialize(json_dict) res = self.is_session_valid() if not res: return False, Result.language.SESSION_KEY_IS_NOT_VALID if result: self.phone_number = SessionManager.retrieve_session_value_by_key( key=Keys.PHONE_NUMBER) self.rate = json_dict[Keys.RATE] self.job_id = json_dict[Keys.JOB_ID] result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def deserialize(self): if not type(self.json_obj) is dict: json_dict = Serializable.convert_input_to_dict(self.json_obj) else: json_dict = self.json_obj result = UpdateCarRequest.pre_deserialize(json_dict) if result[0]: vin_number = json_dict['car_info']['vin_number'] plate_number = json_dict['car_info']['plate_number'] auto_type = json_dict['car_info']['auto_type'] car_id = json_dict['car_id'] car = Car( id=car_id, vin_number=vin_number, plate_number=plate_number, auto_type_id=auto_type, car_owner_id=SessionManager.retrieve_session_value_by_key( Keys.USER_ID)) self.car = car result_pattern = self.post_deserialize() if not result_pattern[0]: return result_pattern return True, self return result
def is_session_valid(): return SessionManager.is_key_exist(key=Keys.PHONE_NUMBER)
def _finished_job(self): car_owner_id = SessionManager.retrieve_session_value_by_key( Keys.USER_ID) return Job.find_all_finished_job(car_owner_id=car_owner_id)
def logout(): SessionManager.pop(Keys.USER_ID) dct = {"type": "success", "message": "Logout", "status": HttpStatus.OK} return make_response(jsonify(dct), dct["status"])
def add_new_key_to_session(self, key, value): SessionManager.add_new_key(key=key, value=value)