Exemplo n.º 1
0
def getShopShoppingPolicies(request):
    if request.method == 'GET':
        shop_name = request.GET.get('shop_name')
        shop_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_shop(shop_name)
        html = ""
        for policy in shop_policies:
            is_none = ""
            selectors = {}
            if policy.restriction is 'N':
                is_none = "disabled"
            selectors['N'] = ""
            selectors['UT'] = ""
            selectors['AL'] = ""
            selectors['E'] = ""
            selectors[policy.restriction] = 'selected="selected"'

            html += loader.render_to_string('components/shopping_shop_policy.html', context={
                'id': policy.policy_id,
                'selector_value': policy.restriction,
                'quantity': policy.quantity,
                'is_none': is_none,
                'N_S': selectors.get('N'),
                'UT_S': selectors.get('UT'),
                'AL_S': selectors.get('AL'),
                'E_S': selectors.get('E'),
            })

        return HttpResponse(html)
Exemplo n.º 2
0
    def test_add_get_policy(self):
        status = ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "UT", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        IP = ShoppingPolicyLogic.get_all_shopping_policy_on_identity()
        CP = ShoppingPolicyLogic.get_all_shopping_policy_on_category()
        ITP = ShoppingPolicyLogic.get_all_shopping_policy_on_items()
        SP = ShoppingPolicyLogic.get_all_shopping_policy_on_shop('eBay')
        self.assertEqual(len(IP), 2)
        self.assertEqual(len(CP), 2)
        self.assertEqual(len(ITP), 2)
        self.assertEqual(len(SP), 2)
Exemplo n.º 3
0
def getShopShoppingPolicyConditions(request):
    if request.method == 'GET':
        shop_name = request.GET.get('shop_name')
        policy_id = request.GET.get('policy_id')
        shop_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_shop(shop_name)
        for SP in shop_policies:
            if SP.policy_id == int(policy_id):
                if SP.conditions == "1=1":
                    return HttpResponse("")
                return HttpResponse(SP.conditions.replace("'", "''"))
        return HttpResponse("FAILED: Can't find that policy")
Exemplo n.º 4
0
    def test_update_policy(self):
        status = True
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0))

        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_shop('ShaharBenS2', 1, "restriction", "N", 'eBay'))
        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_shop('ShaharBenS2', 1, "quantity", 10, 'eBay'))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_identity('Ultimate_ShaharShahar', 1, "restriction", "AL"))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_identity('Ultimate_ShaharShahar', 1, "quantity", 4))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "restriction", "E"))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "quantity", 3))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "category", "books"))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "restriction", "UT"))
        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "quantity", 10))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "item_name", "DP by GoF"))
        self.assertTrue(status)

        IP = ShoppingPolicyLogic.get_all_shopping_policy_on_identity()
        CP = ShoppingPolicyLogic.get_all_shopping_policy_on_category()
        ITP = ShoppingPolicyLogic.get_all_shopping_policy_on_items()
        SP = ShoppingPolicyLogic.get_all_shopping_policy_on_shop('eBay')

        self.assertEqual(IP[0].restriction, "AL")
        self.assertEqual(IP[0].quantity, 4)

        self.assertEqual(CP[0].restriction, "E")
        self.assertEqual(CP[0].quantity, 3)
        self.assertEqual(CP[0].category, "books")

        self.assertEqual(ITP[0].restriction, "UT")
        self.assertEqual(ITP[0].quantity, 10)
        self.assertEqual(ITP[0].item_name, "DP by GoF")

        self.assertEqual(SP[0].restriction, "N")
        self.assertEqual(SP[0].quantity, 10)
Exemplo n.º 5
0
def check_shop_shopping_policies(username, cart_items):
    shop_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_shop()
    for shop_policy in shop_policies:
        if username is not "guest":
            if is_meet_conditions(username, shop_policy.conditions) is False:
                continue
        if shop_policy.restriction is 'N':
            continue
        num_of_items = 0
        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.category == cart_item_shop:
                num_of_items = num_of_items + cart_item.item_quantity
        if shop_policy.restriction is 'AL':
            if num_of_items < shop_policy.quantity:
                return "FAILED: Not enough " + cart_item_shop + " items in cart; You allowed at least " + shop_policy.quantity
        elif shop_policy.restriction is 'E':
            if num_of_items != shop_policy.quantity:
                return "FAILED: Not exact num of " + cart_item_shop + " items in cart; You allowed exactly " + shop_policy.quantity
        elif shop_policy.restriction is 'UT':
            if num_of_items > shop_policy.quantity:
                return "FAILED: Too much " + cart_item_shop + " items in cart; You allowed at most " + shop_policy.quantity
    return True
Exemplo n.º 6
0
def get_all_shopping_policy_on_shop(request):
    if request.method == 'GET':
        return ShoppingPolicyLogic.get_all_shopping_policy_on_shop()
    return HttpResponse('FAILED')