예제 #1
0
def get_order(request):
    if request.method == 'GET':
        login = request.COOKIES.get('login_hash')
        purchase_id = request.GET.get('order_id')

        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is not None:
                items_html = ""
                items = ShoppingLogic.get_purchased_items_by_purchase_id(
                    purchase_id)
                for item in items:
                    full_item = ItemsLogic.get_item(item.item_id)
                    items_html += loader.render_to_string(
                        'components/PurchasedItem.html',
                        context={
                            'item_id': item.item_id,
                            'item_url': full_item.url,
                            'item_name': full_item.name,
                            'item_quantity': item.quantity,
                            'item_price': item.price,
                            'shop_name': full_item.shop_name,
                        })
                date = ShoppingLogic.get_purchase(purchase_id).purchase_date
                context = {
                    'topbar': Topbar_Navbar.get_top_bar(login),
                    'navbar': Topbar_Navbar.get_nav_bar(login, None)
                }
                context.update({
                    'items': items_html,
                    'order_id': purchase_id,
                    'order_date': date
                })
                return render(request, 'customer-order.html', context=context)
        return HttpResponse('You are not logged in!')
예제 #2
0
def add_item_to_cart(request):
    if request.method == 'POST':
        item_id = int(request.POST.get('item_id'))
        quantity = int(request.POST.get('quantity'))
        item = ItemsLogic.get_item(item_id)
        if item.quantity < quantity:
            return HttpResponse('Stock_Error')
        login = request.COOKIES.get('login_hash')
        if login is None:
            login = request.POST.get('login_hash')
        if login is not None and Consumer.loggedInUsers.get(login) is not None:
            username = Consumer.loggedInUsers.get(login)
            status = UserShoppingCartLogic.add_item_shopping_cart(
                login, ShoppingCartItem(username, item_id, quantity, None))
            if status is False:
                return HttpResponse('fail')
            else:
                return HttpResponse('OK')
        else:
            if item.kind == 'ticket':
                return HttpResponse('guest ticket')
            guest = request.COOKIES.get('guest_hash')
            if guest is None:
                guest = 'guest' + Consumer.guestIndex
                Consumer.guestIndex += 1
            status = GuestShoppingCartLogic.add_guest_item_shopping_cart(
                guest, item_id, quantity)
            if status is False:
                return HttpResponse('fail')
            else:
                string_guest = str(guest)
                return HttpResponse(string_guest)
예제 #3
0
def remove_item_from_shop(request):
    if request.method == 'POST':
        login = request.COOKIES.get('login_hash')
        username = None
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse('fail')

        item_id = request.POST.get('item_id')

        item = ItemsLogic.get_item(item_id)
        if item is False:
            return HttpResponse('fail')
        if not UsersLogic.is_owner_of_shop(username, item.shop_name):
            if UsersLogic.is_manager_of_shop(username, item.shop_name):
                manager = UsersLogic.get_manager(username, item.shop_name)
                if manager.permission_remove_item is not 1:  # no permission
                    return HttpResponse('no permission to remove item')
            else:
                return HttpResponse('fail')  # not manager not owner

        status = ItemsLogic.remove_item_from_shop(item_id, username)
        if status is False:
            return HttpResponse('fail')
        return HttpResponse('success')
예제 #4
0
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
예제 #5
0
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
예제 #6
0
def check_stock_for_shopping_cart(cart_items):
    for cart_item in cart_items:
        if ItemsLogic.check_in_stock(cart_item.item_id,
                                     cart_item.item_quantity) is False:
            item = ItemsLogic.get_item(cart_item.item_id)
            return 'Only ' + str(
                item.quantity) + ' ' + item.name + ' exist in the system'
    return True
예제 #7
0
def edit_shop_item(request):
    if request.method == 'POST':
        login = request.COOKIES.get('login_hash')
        username = None
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse('fail')
        item_id = request.POST.get('item_id')

        fields = ['quantity', 'category', 'keywords', 'price', 'url']
        new_values = [
            request.POST.get('item_quantity'),
            request.POST.get('item_category'),
            request.POST.get('item_keywords'),
            request.POST.get('item_price'),
            request.POST.get('item_url')
        ]

        event = "EDIT ITEM"
        suspect_sql_injection = False
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[0], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[1], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[2], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[3], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[4], event) or suspect_sql_injection
        if suspect_sql_injection:
            return HttpResponse(MESSAGE_SQL_INJECTION)

        item = ItemsLogic.get_item(item_id)
        if item is False:
            return HttpResponse('fail')
        if not UsersLogic.is_owner_of_shop(username, item.shop_name):
            if UsersLogic.is_manager_of_shop(username, item.shop_name):
                manager = UsersLogic.get_manager(username, item.shop_name)
                if manager.permission_edit_item is not 1:  # no permission
                    return HttpResponse('no permission to edit item')
            else:
                return HttpResponse('fail')  # not manager not owner

        for i in range(0, len(fields)):
            status = ItemsLogic.edit_shop_item(username, item_id, fields[i],
                                               new_values[i])
            if status is False:
                return HttpResponse('fail')
        return HttpResponse('success')
예제 #8
0
def lottery_timer(lottery_id):
    lottery = Lotteries.get_lottery(lottery_id)
    if lottery.real_end_date is not None:
        return
    ticket = ItemsLogic.get_item(lottery_id)
    lottery_customers = get_lottery_customers(lottery_id)
    if ticket.quantity > 0:
        Lotteries.update_lottery_real_date(
            lottery_id,
            datetime.now().strftime("%Y-%m-%d %H:%M"))
        customer_names = []
        for customer in lottery_customers:
            # TODO add live alert to customers
            customer_names.append(customer.username)
        LoterryAlerts.notify_lottery_alerts(
            customer_names,
            'Lottery for item  <a href="http://localhost:8000/app/item/?item_id='
            + str(lottery_id) + '"># <strong>' + str(lottery_id) +
            '</strong></a> has been canceled.')
예제 #9
0
파일: Item.py 프로젝트: omriattiya/uTrade
def get_reviews(request):
    if request.method == 'GET':
        item_id = request.GET.get('item_id')
        item = ItemsLogic.get_item(item_id)
        if item is not False:
            reviews = ItemsLogic.get_all_reviews_on_item(item.id)
            string_reviews = ""
            for review in reviews:
                string_reviews += loader.render_to_string(
                    'component/../../../PresentationLayer/templates/components/review.html',
                    {'writer_name': review.writerId, 'rank': review.rank, 'description': review.description}, None,
                    None)
            login = request.COOKIES.get('login_hash')
            guest = request.COOKIES.get('guest_hash')
            context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest)}
            context.update({'item_name': item.name, 'shop_name': item.shop_name, 'reviews': string_reviews})
            return render(request, 'item_reviews.html', context=context)
        return HttpResponse(shop_not_exist)
    return HttpResponse(not_get_request)
예제 #10
0
def get_system_history(request):
    if request.method == 'GET':
        login = request.COOKIES.get('login_hash')

        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is not None:
                if UsersLogic.is_system_manager(username):
                    history_html = ""
                    purchased_items = ItemsLogic.get_all_purchased_items(
                        username)
                    for purchased_item in purchased_items:
                        item = ItemsLogic.get_item(purchased_item.item_id)
                        if item is False:
                            item = Item(purchased_item.item_id, None, None,
                                        None, None, None, None, None, None, 0,
                                        0, 0)
                        purchase = ShoppingLogic.get_purchase(
                            purchased_item.purchase_id)
                        history_html += loader.render_to_string(
                            'components/purchase_history.html',
                            context={
                                'username': purchase.username,
                                'shop_name': item.shop_name,
                                'purchase_id': purchased_item.purchase_id,
                                'item_id': item.id,
                                'quantity': purchased_item.quantity,
                                'price': purchased_item.price
                            })

                    context = {
                        'topbar': Topbar_Navbar.get_top_bar(login),
                        'navbar': Topbar_Navbar.get_nav_bar(login, None)
                    }
                    context.update({'history': history_html})
                    return render(request,
                                  'system-history.html',
                                  context=context)
        return HttpResponse("You don't have the privilege to be here")
예제 #11
0
파일: Bridge.py 프로젝트: omriattiya/uTrade
def quantity_in_store(item_id):
    item = ItemsLogic.get_item(item_id)
    if item is not False:
        return item.quantity
    return False
예제 #12
0
파일: Item.py 프로젝트: omriattiya/uTrade
def get_item(request):
    if request.method == 'GET':
        item_id = request.GET.get('item_id')
        item = ItemsLogic.get_item(item_id)
        if item is not False:
            # product = ""
            # product += loader.render_to_string('component/item.html',
            #                                   {'name': item.name, 'price': item.price, 'url': item.url}, None,
            #                                  None)
            right1 = "Percentage"
            policy_or_percentage = "0"
            item_percentage = "0"
            right2 = "Start Date"
            deadline_or_start_date = "None"
            item_start_date = "None"
            item_end_date = "None"
            right3 = "End Time"
            real_end_time_or_end_date = "None"
            headline = "Purchase Policy"
            price = item.price
            former_price = ""
            visibility_quantity = "visible"
            visibility_add_to_cart = "visible"
            lottery = Lotteries.get_lottery(item_id)
            header_of_table = "Category Discount"
            invisible = ""
            lottery_margin_left = 0
            quantity_icon = 'icon-inventory.png'
            if lottery is not False:
                right1 = "Policy"
                policy_or_percentage = "Lottery"
                print(lottery.final_date)
                right2 = "Deadline"
                deadline_or_start_date = lottery.final_date
                right3 = "Actual End Time"
                invisible = "display: none;"
                header_of_table = "Additional details you should know before purchase"
                lottery_margin_left = 30
                if lottery.real_end_date is not None:
                    real_end_time_or_end_date = lottery.real_end_date
                    visibility_quantity = "hidden"
                    visibility_add_to_cart = "hidden"
                else:
                    real_end_time_or_end_date = "---------"
                quantity_icon = 'tickets-icon.png'
            else:
                headline = "Discounts on Product"
                discount = get_visible_discount(item.id, item.shop_name)
                if discount is not False:
                    item_start_date = discount.from_date
                    item_percentage = str(discount.percentage) + "%"
                    item_end_date = discount.end_date
                    former_price = "$" + str(item.price)
                    price = price*(1 - (discount.percentage / 100))
                discount = get_visible_discount_category(item.category, item.shop_name)
                if discount is not False:
                    deadline_or_start_date = discount.from_date
                    policy_or_percentage = str(discount.percentage) + "%"
                    real_end_time_or_end_date = discount.end_date
                    former_price = "$" + str(item.price)
                    price = price * (1 - (discount.percentage / 100))
            login = request.COOKIES.get('login_hash')
            guest = request.COOKIES.get('guest_hash')
            context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest)}
            item_rank = item.item_rating
            if item_rank is False:
                item_rank = "-----"
            else:
                item_rank = str(item_rank)
            if item.quantity < 1:
                visibility_add_to_cart = "hidden"
            context.update({'item_id': item.id,
                            'item_name': item.name,
                            'shop_name': item.shop_name,
                            'category': item.category,
                            'keyWords': item.keyWords,
                            'price': round(price, 2),
                            'former_price': former_price,
                            'quantity': item.quantity,
                            'kind': item.kind,
                            'item_rank': item_rank,
                            'url': item.url,
                            'policy_or_percentage': policy_or_percentage,
                            'headline': headline,
                            'deadline_or_start_date': deadline_or_start_date,
                            'real_end_time_or_end_date': real_end_time_or_end_date,
                            'right1': right1,
                            'right2': right2,
                            'right3': right3,
                            'invisible': invisible,
                            'header_of_table': header_of_table,
                            'lottery_margin_left': lottery_margin_left,
                            'item_percentage': item_percentage,
                            'item_start_date': item_start_date,
                            'item_end_date': item_end_date,
                            'visibility_quantity': visibility_quantity,
                            'visibility_add_to_cart': visibility_add_to_cart,
                            'quantity_icon': quantity_icon})
            return render(request, 'detail.html', context=context)
        else:
            return HttpResponse(shop_not_exist)
    return HttpResponse(not_get_request)