def formset_invalid(self, formset): messages.error( self.request, '\n'.join( error for ed in formset.errors for el in ed.values() for error in el)) return redirect_to_referrer(self.request, 'basket:summary')
def form_invalid(self, form): msgs = [] for error in form.errors.values(): msgs.append(error.as_text()) clean_msgs = [m.replace('* ', '') for m in msgs if m.startswith('* ')] messages.error(self.request, ",".join(clean_msgs)) return redirect_to_referrer(self.request, 'basket:summary')
def form_valid(self, form): code = form.cleaned_data['code'] if not self.request.basket.id: return redirect_to_referrer(self.request, 'basket:summary') if self.request.basket.contains_voucher(code): messages.error( self.request, _("You have already added the '%(code)s' voucher to " "your basket") % {'code': code}) else: try: voucher = self.voucher_model._default_manager.get(code=code) except self.voucher_model.DoesNotExist: messages.error( self.request, _("No voucher found with code '%(code)s'") % { 'code': code}) else: self.apply_voucher_to_basket(voucher) return redirect_to_referrer(self.request, 'basket:summary')
def post(self, request, *args, **kwargs): product = get_object_or_404(Product, pk=kwargs['product_pk']) wishlists = request.user.wishlists.all() if len(wishlists) == 0: wishlist = request.user.wishlists.create() else: # This shouldn't really happen but we default to using the first # wishlist for a user if one already exists when they make this # request. wishlist = wishlists[0] wishlist.add(product) messages.success( request, _("%(title)s has been added to your wishlist") % { 'title': product.get_title()}) return redirect_to_referrer(request, wishlist.get_absolute_url())
def post(self, request, *args, **kwargs): product = get_object_or_404(Product, pk=self.kwargs['product_pk']) review = get_object_or_404(ProductReview, pk=self.kwargs['pk']) form = VoteForm(review, request.user, request.POST) if form.is_valid(): if form.is_up_vote: review.vote_up(request.user) elif form.is_down_vote: review.vote_down(request.user) messages.success(request, _("Thanks for voting!")) else: for error_list in form.errors.values(): for msg in error_list: messages.error(request, msg) return redirect_to_referrer(request, product.get_absolute_url())
def get(self, request, *args, **kwargs): to_wishlist = get_object_or_404( WishList, owner=request.user, key=kwargs['to_key']) if to_wishlist.lines.filter(product=self.line.product).count() > 0: msg = _("Wish list '%(name)s' already containing '%(title)s'") % { 'title': self.product.get_title(), 'name': to_wishlist.name} messages.error(self.request, msg) else: self.line.wishlist = to_wishlist self.line.save() msg = _("'%(title)s' moved to '%(name)s' wishlist") % { 'title': self.product.get_title(), 'name': to_wishlist.name} messages.success(self.request, msg) default_url = reverse( 'customer:wishlists-detail', kwargs={'key': self.wishlist.key}) return redirect_to_referrer(self.request, default_url)
def get_success_response(self): return redirect_to_referrer(self.request, 'customer:notifications-inbox')
def add_product(self): self.wishlist.add(self.product) msg = _("'%s' was added to your wish list.") % self.product.get_title() messages.success(self.request, msg) return redirect_to_referrer( self.request, self.product.get_absolute_url())