def check_category_shopping_policies(username, cart_items): category_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_category( ) for category_policy in category_policies: if username is not "guest": if is_meet_conditions(username, category_policy.conditions) is False: continue if category_policy.restriction is 'N': continue num_of_items = 0 cart_item_category = None for cart_item in cart_items: cart_item_category = ItemsLogic.get_item( cart_item.item_id).category if category_policy.category == cart_item_category: num_of_items = num_of_items + cart_item.item_quantity if category_policy.restriction is 'AL': if num_of_items < category_policy.quantity: return "FAILED: Not enough " + cart_item_category + " items in cart; You allowed at least " + category_policy.quantity elif category_policy.restriction is 'E': if num_of_items != category_policy.quantity: return "FAILED: Not exact num of " + cart_item_category + " items in cart; You allowed exactly " + category_policy.quantity elif category_policy.restriction is 'UT': if num_of_items > category_policy.quantity: return "FAILED: Too much " + cart_item_category + " items in cart; You allowed at most " + category_policy.quantity return True
def check_shop_shopping_policies(username, cart_items): shop_policies = ShoppingPolicyLogic.get_all_shops_shopping_policies() for shop_policy in shop_policies: if not (username == "guest"): if is_meet_conditions(username, shop_policy.conditions) is False: continue if shop_policy.restriction == 'N': continue num_of_items = 0 relevant = False cart_item_shop = None for cart_item in cart_items: cart_item_shop = ItemsLogic.get_item(cart_item.item_id).shop_name if shop_policy.shop_name == cart_item_shop: num_of_items = num_of_items + cart_item.item_quantity relevant = True if shop_policy.restriction == 'AL': if relevant and num_of_items < shop_policy.quantity: return "FAILED: Not enough " + cart_item_shop + " items in cart; You allowed at least " + str( shop_policy.quantity) elif shop_policy.restriction == 'E': if relevant and num_of_items != shop_policy.quantity: return "FAILED: Not exact num of " + cart_item_shop + " items in cart; You allowed exactly " + str( shop_policy.quantity) elif shop_policy.restriction == 'UT': if relevant and num_of_items > shop_policy.quantity: return "FAILED: Too much " + cart_item_shop + " items in cart; You allowed at most " + str( shop_policy.quantity) return True
def check_identity_shopping_policies(username, cart_items): identity_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_identity( ) for identity_policy in identity_policies: if username is not "guest": if is_meet_conditions(username, identity_policy.conditions) is False: continue if identity_policy.restriction is 'N': continue elif identity_policy.restriction is 'AL': if len(cart_items) < identity_policy.quantity: return "FAILED: Not enough items in cart; You allowed at least " + identity_policy.quantity elif identity_policy.restriction is 'E': if len(cart_items) != identity_policy.quantity: return "FAILED: Not exact num of items in cart; You allowed exactly " + identity_policy.quantity elif identity_policy.restriction is 'UT': if len(cart_items) > identity_policy.quantity: return "FAILED: Too much items in cart; You allowed at most " + identity_policy.quantity return True
def check_identity_shopping_policies(username, cart_items): identity_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_identity() for identity_policy in identity_policies: if not (username == "guest"): if is_meet_conditions(username, identity_policy.conditions) is False: continue if identity_policy.restriction == 'N': continue num_of_items = 0 for cart_item in cart_items: num_of_items = num_of_items + cart_item.item_quantity if identity_policy.restriction == 'AL': if num_of_items < identity_policy.quantity: return "FAILED: Not enough items in cart; You allowed at least " + str(identity_policy.quantity) elif identity_policy.restriction == 'E': if num_of_items != identity_policy.quantity: return "FAILED: Not exact num of items in cart; You allowed exactly " + str(identity_policy.quantity) elif identity_policy.restriction == 'UT': if num_of_items > identity_policy.quantity: return "FAILED: Too much items in cart; You allowed at most " + str(identity_policy.quantity) return True