Ejemplo n.º 1
0
 def get_history_products(self):
     ids = extract(self.request)
     history_products = Product.objects.filter(
         id__in=ids,
         opening_date__lte=datetime.datetime.now().date()).order_by(
             '-browse_num')[:7]
     return history_products
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(BasketView, self).get_context_data(**kwargs)
        all_lines = self.request.basket.lines.all()
        if all_lines:
            all_products = Product.objects.filter(id__in=all_lines.values_list('product', flat=True))
            all_products_ids = all_products.values_list('id', flat=True)
            all_recommended_products_ids = all_products.values_list('recommended_products', flat=True)
            recommended_products_ids = set(all_recommended_products_ids).difference(set(all_products_ids))
            if all_recommended_products_ids:
                all_recommended_products = Product.objects.filter(id__in=recommended_products_ids,opening_date__lte=datetime.datetime.now().date())
            else:
                all_recommended_products = []

            total_quantity = all_lines.aggregate(Sum('quantity')).get('quantity__sum')
            total_price = 0
            for line in all_lines:
                total_price += line.total_price
        else:
            all_recommended_products = []
            total_quantity = 0
            total_price = 0

        history_products = Product.objects.filter(id__in = extract(self.request),opening_date__lte=datetime.datetime.now().date())[:5]
        context['history_products'] = history_products
        context['all_recommended_products'] = all_recommended_products
        context['total_quantity'] = total_quantity
        context['total_price'] = total_price
        category_list = Category.objects.filter(depth=1).order_by('path')[:10]
        context['category_list']=category_list
        context['open_or_close'] = open_close_date()[0]
        context['open_close_msg'] = open_close_date()[1]

        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        ctx = {}
        ctx['summary'] = _("All products")
        search_context = self.search_handler.get_search_context_data(
            self.context_object_name)
        ctx.update(search_context)

        pq = Product.objects.filter(
            is_on_shelves=True,
            opening_date__lte=datetime.datetime.now().date()).annotate(
                q=Sum('trade_complete_product__quantity')).order_by('-q')[:7]
        hotproduct = pq
        ctx['hotproduct'] = hotproduct

        history_products = Product.objects.filter(
            id__in=extract(self.request),
            opening_date__lte=datetime.datetime.now().date()).order_by(
                '-browse_num')[:7]
        ctx['history_products'] = history_products

        category_list = Category.objects.filter(depth=1).order_by('path')[:10]
        ctx['category_list'] = category_list

        ctx['open_or_close'] = open_close_date()[0]
        ctx['open_close_msg'] = open_close_date()[1]

        return ctx
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        context = super(BasketView, self).get_context_data(**kwargs)
        all_lines = self.request.basket.lines.all()
        if all_lines:
            all_products = Product.objects.filter(
                id__in=all_lines.values_list('product', flat=True))
            all_products_ids = all_products.values_list('id', flat=True)
            all_recommended_products_ids = all_products.values_list(
                'recommended_products', flat=True)
            recommended_products_ids = set(
                all_recommended_products_ids).difference(set(all_products_ids))
            if all_recommended_products_ids:
                all_recommended_products = Product.objects.filter(
                    id__in=recommended_products_ids,
                    opening_date__lte=datetime.datetime.now().date())
            else:
                all_recommended_products = []

            total_quantity = all_lines.aggregate(
                Sum('quantity')).get('quantity__sum')
            total_price = 0
            for line in all_lines:
                total_price += line.total_price
        else:
            all_recommended_products = []
            total_quantity = 0
            total_price = 0

        history_products = Product.objects.filter(
            id__in=extract(self.request),
            opening_date__lte=datetime.datetime.now().date())[:5]
        context['history_products'] = history_products
        context['all_recommended_products'] = all_recommended_products
        context['total_quantity'] = total_quantity
        context['total_price'] = total_price
        category_list = Category.objects.filter(depth=1).order_by('path')[:10]
        context['category_list'] = category_list
        context['open_or_close'] = open_close_date()[0]
        context['open_close_msg'] = open_close_date()[1]

        return context
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        ctx = {}
        ctx['summary'] = _("All products")
        search_context = self.search_handler.get_search_context_data(
            self.context_object_name)
        ctx.update(search_context)

        pq = Product.objects.filter(is_on_shelves = True,opening_date__lte=datetime.datetime.now().date()).annotate(q=Sum('trade_complete_product__quantity')).order_by('-q')[:7]
        hotproduct = pq
        ctx['hotproduct'] = hotproduct

        history_products = Product.objects.filter(id__in = extract(self.request),opening_date__lte=datetime.datetime.now().date()).order_by('-browse_num')[:7]
        ctx['history_products'] = history_products

        category_list = Category.objects.filter(depth=1).order_by('path')[:10]
        ctx['category_list'] =category_list

        ctx['open_or_close'] = open_close_date()[0]
        ctx['open_close_msg'] = open_close_date()[1]

        return ctx
Ejemplo n.º 6
0
 def test_id_gets_added_to_cookie(self):
     response = self.client.get(self.product.get_absolute_url())
     request = HttpRequest()
     request.COOKIES[COOKIE_NAME] = response.cookies[COOKIE_NAME].value
     self.assertTrue(self.product.id in history.extract(request))
Ejemplo n.º 7
0
 def test_id_gets_added_to_cookie(self):
     response = self.app.get(self.product.get_absolute_url())
     request = HttpRequest()
     request.COOKIES[COOKIE_NAME] = _unquote(response.test_app.cookies[COOKIE_NAME])
     self.assertTrue(self.product.id in history.extract(request))
Ejemplo n.º 8
0
 def get_history_products(self):
     ids = extract(self.request)
     history_products = Product.objects.filter(id__in = ids).order_by('-browse_num')[:7]
     return history_products
 def test_id_gets_added_to_cookie(self):
     response = self.client.get(self.product.get_absolute_url())
     request = HttpRequest()
     request.COOKIES[history.COOKIE_NAME] = response.cookies[history.COOKIE_NAME].value
     self.assertTrue(self.product.id in history.extract(request))
Ejemplo n.º 10
0
 def get_history_products(self):
     ids = extract(self.request)
     history_products = Product.objects.filter(
         id__in=ids).order_by('-browse_num')[:7]
     return history_products
Ejemplo n.º 11
0
 def get_history_products(self):
     ids = extract(self.request)
     history_products = Product.objects.filter(id__in = ids,opening_date__lte=datetime.datetime.now().date()).order_by('-browse_num')[:7]
     return history_products