def update_shopping_policy_on_shop(username, policy_id, field_name, new_value, shop_name): if policy_id is not None and field_name is not None and new_value is not None: if int(policy_id) < 0: return "FAILED: Invalid id of Policy" if field_name not in ['shop_name', 'conditions', 'restriction', 'quantity']: return "FAILED: Invalid field name" if Owners.get_owner(username, shop_name) is not False: if field_name in ['conditions']: status = checkConditionsSyntax(new_value) if new_value == "": new_value = "1=1" if status is not True: return status if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY") return True manager = StoreManagers.get_store_manager(username, shop_name) if manager is not False: if manager.permission_set_policy > 0: if field_name in ['conditions']: status = checkConditionsSyntax(new_value) if new_value == "": new_value = "1=1" if status is not True: return status if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY") return True return 'FAILED: no permissions!' return 'FAILED: you are not a the Owner of the shop' return "FAILED: One (or more) of the parameters is None"
def remove_shopping_policy_on_category(username, policy_id): if policy_id is not None and policy_id > 0: if SystemManagers.is_system_manager(username) is not False: if not ShoppingPolicies.remove_shopping_policy_on_category(policy_id): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: REMOVE CATEGORY SHOPPING POLICY") return True return 'FAILED: you are not a System Manager' return "FAILED: Invalid id of Policy"
def remove_shopping_policy_on_shop(username, policy_id, shop_name): if policy_id is not None and policy_id > 0: if Owners.get_owner(username, shop_name) is not False: if not ShoppingPolicies.remove_shopping_policy_on_shop(policy_id): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: REMOVE SHOP SHOPPING POLICY") return True return 'FAILED: you are not a the Owner of the shop' return "FAILED: Invalid id of Policy"
def add_shopping_policy_on_identity(username, conditions, restriction, quantity): if conditions is not None and restriction is not None and quantity is not None: if restriction not in ['N', 'AL', 'E', 'UT']: return "FAILED: Invalid value of restriction." if int(quantity) < 0: return "FAILED: Negative quantity is invalid." if SystemManagers.is_system_manager(username) is not False: if not ShoppingPolicies.add_shopping_policy_on_identity(conditions, restriction, quantity): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: ADD IDENTITY SHOPPING POLICY") return True return 'FAILED: you are not a System Manager' return "FAILED: One (or more) of the parameters is None"
def add_shopping_policy_on_shop(username, shop_name, conditions, restriction, quantity): if shop_name is not None and conditions is not None: if restriction is not None and quantity is not None: if restriction not in ['N', 'AL', 'E', 'UT']: return "FAILED: Invalid value of restriction." if int(quantity) < 0: return "FAILED: Negative quantity is invalid." if Owners.get_owner(username, shop_name) is not False: if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY") return True manager = StoreManagers.get_store_manager(username,shop_name) if manager is not False: if manager.permission_set_policy > 0: if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY") return True return 'FAILED: no permissions!' return 'FAILED: you are not a the Owner of the shop' return "FAILED: One (or more) of the parameters is None" return "FAILED: One (or more) of the parameters is None"
def update_shopping_policy_on_category(username, policy_id, field_name, new_value): if policy_id is not None and field_name is not None and new_value is not None: if int(policy_id) < 0: return "FAILED: Invalid id of Policy" if field_name not in ['category', 'conditions', 'restriction', 'quantity']: return "FAILED: Invalid field name" if SystemManagers.is_system_manager(username) is not False: if field_name in ['conditions']: status = checkConditionsSyntax(new_value) if new_value == "": new_value = "1=1" if status is not True: return status if not ShoppingPolicies.update_shopping_policy_on_category(policy_id, field_name, new_value): return "FAILED: DB error." LoggerLogic.add_event_log(username, "POLICY: UPDATE CATEGORY SHOPPING POLICY") return True return 'FAILED: you are not a System Manager' return "FAILED: One (or more) of the parameters is None"
def get_all_shopping_policy_on_shop(shop_name): return ShoppingPolicies.get_all_shopping_policy_on_shop(shop_name)
def get_all_shopping_policy_on_identity(): return ShoppingPolicies.get_all_shopping_policy_on_identity()
def get_all_shopping_policy_on_category(): return ShoppingPolicies.get_all_shopping_policy_on_category()
def get_all_shopping_policy_on_items(): return ShoppingPolicies.get_all_shopping_policy_on_items()
def get_all_shops_shopping_policies(): return ShoppingPolicies.get_all_shops_shopping_policies()