Esempio n. 1
0
 def get_context_data(self, **kwargs):
     context = super(OrderListView, self).get_context_data(**kwargs)
     profile_settings = get_profile_settings(self.request.user)
     context.update(profile_settings)
     self.request.breadcrumbs('Orders', reverse('orders:list'))
     context['paginate_by'] = settings.DEFAULT_PAGINATE_BY
     context['paginate_by_first'] = settings.DEFAULT_PAGINATE_BY
     context['filter'] = self.filter
     return context
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super(ProductDetailView, self).get_context_data(**kwargs)
     profile_settings = get_profile_settings(self.request.user)
     context.update(profile_settings)
     context['product'] = PriceCalculator(self.object, profile_settings['client_category'])
     analogues = PriceCalculator(self.object.analogues.active().select_related(), profile_settings['client_category'])
     context['analogues_list'] = analogues
     self.request.breadcrumbs('Products', reverse('products:list'))
     current_category = self.object.category
     if current_category:
         for cat in current_category.get_ancestors(include_self=True):
             self.request.breadcrumbs(cat.name, cat.get_absolute_url())
     self.request.breadcrumbs(self.object.name, None)
     return context
Esempio n. 3
0
    def get_context_data(self, **kwargs):
        context = super(CartItemListView, self).get_context_data(**kwargs)
        profile_settings = get_profile_settings(self.request.user)
        context.update(profile_settings)
        context['cartitem_list'] = PriceCalculator(self.object_list, profile_settings['client_category'])
        self.request.breadcrumbs('Cart', reverse('cart:list'))
        q = self.request.GET.get("q", None)
        context['paginate_by'] = settings.DEFAULT_PAGINATE_BY
        context['q'] = q

        if q:
            self.request.breadcrumbs('Search: %s' % q, None)
        else:
            context['paginate_by_first'] = max(settings.DEFAULT_PAGINATE_BY, 0)

        return context
Esempio n. 4
0
 def transfer_from_cart(self, user):
     self.user = user
     self.save()
     profile_settings = get_profile_settings(self.user)
     cart_items = PriceCalculator(CartItem.objects.by_user(self.user).select_related(),
                                  profile_settings['client_category'])
     order_items = []
     items_id_to_delete = []
     for cart_item in cart_items:
         if not cart_item.price or not cart_item.product.available:
             continue
         order_item = OrderItem(order=self,
                                product=cart_item.product,
                                quant=cart_item.quant,
                                price=cart_item.price,
                                sum=cart_item.sum)
         order_items.append(order_item)
         items_id_to_delete.append(cart_item.id)
     if not order_items:
         raise NothingToTransfer()
     OrderItem.objects.bulk_create(order_items)
     CartItem.objects.delete_by_user(user=user, items=items_id_to_delete)
     if len(order_items) != len(cart_items):
         raise NotTransferredItems()
Esempio n. 5
0
 def get_context_data(self, **kwargs):
     context = super(ProductListView, self).get_context_data(**kwargs)
     self.request.breadcrumbs('Products', reverse('products:list'))
     profile_settings = get_profile_settings(self.request.user)
     context.update(profile_settings)
     context['current_category'] = self.current_category
     context['product_list'] = PriceCalculator(self.object_list, profile_settings['client_category'])
     q = self.request.GET.get("q", None)
     context['paginate_by'] = settings.DEFAULT_PAGINATE_BY
     context['q'] = q
     if q:
         self.request.breadcrumbs('Search: %s' % q, None)
         context['paginate_by_first'] = settings.DEFAULT_PAGINATE_BY
     else:
         context['category_list'] = Category.objects.by_category(category=self.current_category)
         context['paginate_by_first'] = max(settings.DEFAULT_PAGINATE_BY - len(context['category_list']), 0)
         if self.current_category:
             context['parent_category'] = self.current_category.parent
             for cat in self.current_category.get_ancestors(include_self=True):
                 if cat == self.current_category:
                     self.request.breadcrumbs(cat.name, None)
                 else:
                     self.request.breadcrumbs(cat.name, cat.get_absolute_url())
     return context
Esempio n. 6
0
 def get_queryset(self):
     profile_settins = get_profile_settings(self.request.user)
     self.filter = OrderFilterSet(self.request.GET, Order.objects.by_client(profile_settins['client']))
     return self.filter.qs.select_related()
Esempio n. 7
0
 def get_initial(self):
     initial_data = super(OrderCreateView, self).get_initial()
     profile_settings = get_profile_settings(self.request.user)
     initial_data['shipping_address'] = profile_settings['client'].shipping_address
     return initial_data