Example #1
0
 def revalidate_discounts(self):
     discounts = self.discount.all()
     if discounts:
         for discount in discounts:
             disc = CartCodeMinOrderDiscount()
             if not disc.is_valid(discount.code, self.get_items_price()):
                 self.discount.remove(discount)
Example #2
0
 def post(self, request):
     self.object = self.get_object()
     context = self.get_context_data(object=self.object)
     form = CartCodeDiscount(request.POST)
     if form.is_valid():
         discount = CartCodeMinOrderDiscount()
         if discount.is_valid(form.cleaned_data['code'],
                            context['object'].get_items_price()):
             context['object'].add_discount(discount.discount)
             return HttpResponseRedirect(reverse('cart:detail'))
         form.errors['code'] = discount.errors
     context['cart_discount_form'] = form
     return self.render_to_response(context)