예제 #1
0
def get_shop_to_owner(request):
    if request.method == 'GET':
        shop_name = request.GET.get('shop_name')
        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)
        }
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse(error_login_owner)
        else:
            return HttpResponse(error_login_owner)
        if UsersLogic.is_owner_of_shop(username, shop_name) is not False:
            shop_items = ShopLogic.get_shop_items(shop_name)
            string_items = ""
            for item in shop_items:
                string_items += loader.render_to_string(
                    'components/item_owner.html', {
                        'item_name': item.name,
                        'item_quantity': item.quantity,
                        'item_category': item.category,
                        'item_keywords': item.keyWords,
                        'item_price': item.price,
                        'item_url': item.url,
                        'item_id': item.id,
                        'shop_name': item.shop_name
                    })
            context.update({'items': string_items, 'shop_name': shop_name})
            return render(request,
                          'shop_items_management.html',
                          context=context)
        else:
            return HttpResponse(shop_not_exist + " with username=" + username)
    return HttpResponse(not_get_request)
예제 #2
0
def get_shop(request):
    if request.method == 'GET':
        shop_name = request.GET.get('shop_name')
        shop = ShopLogic.search_shop(shop_name)
        if shop is not False:
            username = None
            login = request.COOKIES.get('login_hash')
            if login is not None:
                username = Consumer.loggedInUsers.get(login)
            guest = request.COOKIES.get('guest_hash')
            context = {
                'topbar': Topbar_Navbar.get_top_bar(login),
                'navbar': Topbar_Navbar.get_nav_bar(login, guest)
            }
            items = ShopLogic.get_shop_items(shop.name)
            products = ""
            for item in items:
                if item.kind == 'prize':
                    continue
                products += loader.render_to_string(
                    'components/item.html', {
                        'name':
                        item.name,
                        'price':
                        "{0:.2f}".format(
                            item.price * item_discount(item.id, shop_name) *
                            category_discount(item.category, shop_name)),
                        'url':
                        item.url,
                        'item_id':
                        item.id
                    }, None, None)
            owner_manager_options = ""
            render_edit_remove = loader.render_to_string(
                'components/owner_manager_options.html', {
                    'path': 'owner/items',
                    'id_param': 'edit_remove',
                    'shop_name': shop_name,
                    'button_text': 'Edit & Remove Items'
                })
            render_purchase_history = loader.render_to_string(
                'components/owner_manager_options.html', {
                    'path': 'owner/purchase_history',
                    'id_param': 'purchase_history',
                    'shop_name': shop_name,
                    'button_text': 'Purchase History'
                })
            render_add_item = loader.render_to_string(
                'components/owner_manager_options.html', {
                    'path': 'owner/items/add_item',
                    'id_param': 'add_item',
                    'shop_name': shop_name,
                    'button_text': 'Add Item'
                })
            render_add_discount = loader.render_to_string(
                'components/owner_manager_options.html', {
                    'path': 'owner/add_discount',
                    'id_param': 'add_discount',
                    'shop_name': shop_name,
                    'button_text': 'Add Discount'
                })
            render_delete_discount = loader.render_to_string(
                'components/owner_manager_options.html', {
                    'path': 'owner/delete_discount',
                    'id_param': 'delete_discount',
                    'shop_name': shop_name,
                    'button_text': 'Delete Discount'
                })

            if UsersLogic.is_owner_of_shop(username, shop_name):
                owner_manager_options += render_purchase_history + \
                                         render_edit_remove + \
                                         render_add_item + \
                                         render_add_discount + \
                                         render_delete_discount
            if UsersLogic.is_manager_of_shop(username, shop_name):
                manager = UsersLogic.get_manager(username, shop_name)
                if manager.permission_get_purchased_history == 1:
                    owner_manager_options += render_purchase_history
                if manager.permission_edit_item == 1 or manager.permission_remove_item == 1:
                    owner_manager_options += render_edit_remove
                if manager.permission_add_item == 1:
                    owner_manager_options += render_add_item
                if manager.discount_permission == 1:
                    owner_manager_options += render_add_discount + render_delete_discount

            context.update({
                'shop_name': shop.name,
                'shop_status': shop.status,
                'products': products,
                'owner_manager_options': owner_manager_options
            })
            return render(request, 'shop.html', context=context)
        else:
            login = request.COOKIES.get('login_hash')
            guest = request.COOKIES.get('guest')
            topbar = Topbar_Navbar.get_top_bar(login)
            navbar = Topbar_Navbar.get_nav_bar(login, guest)
            context = {'topbar': topbar, 'navbar': navbar}
            return render(request, 'ShopNotFound.html', context)
    return HttpResponse(not_get_request)