|
|
@@ -250,39 +250,62 @@ class LineMixin(object):
|
|
250
|
250
|
* product_pk: The primary key of the product
|
|
251
|
251
|
"""
|
|
252
|
252
|
|
|
253
|
|
- def dispatch(self, request, *args, **kwargs):
|
|
254
|
|
- self.wishlist = get_object_or_404(
|
|
255
|
|
- WishList, owner=request.user, key=kwargs['key'])
|
|
256
|
|
- try:
|
|
257
|
|
- if 'line_pk' in kwargs:
|
|
258
|
|
- self.line = self.wishlist.lines.get(pk=kwargs['line_pk'])
|
|
259
|
|
- elif 'product_pk' in kwargs:
|
|
260
|
|
- self.line = self.wishlist.lines.get(
|
|
261
|
|
- product_id=kwargs['product_pk'])
|
|
262
|
|
- except (ObjectDoesNotExist, MultipleObjectsReturned):
|
|
263
|
|
- raise Http404
|
|
|
253
|
+ def fetch_line(self, user, wishlist_key, line_pk=None, product_pk=None):
|
|
|
254
|
+ self.wishlist = WishList._default_manager.get(
|
|
|
255
|
+ owner=user, key=wishlist_key)
|
|
|
256
|
+ if line_pk is not None:
|
|
|
257
|
+ self.line = self.wishlist.lines.get(pk=line_pk)
|
|
|
258
|
+ else:
|
|
|
259
|
+ self.line = self.wishlist.lines.get(product_id=product_pk)
|
|
264
|
260
|
self.product = self.line.product
|
|
265
|
|
- return super(LineMixin, self).dispatch(request, *args, **kwargs)
|
|
266
|
261
|
|
|
267
|
262
|
|
|
268
|
|
-class WishListRemoveProduct(LineMixin, View):
|
|
|
263
|
+class WishListRemoveProduct(LineMixin, PageTitleMixin, DeleteView):
|
|
|
264
|
+ template_name = 'customer/wishlists/wishlists_delete_product.html'
|
|
|
265
|
+ active_tab = "wishlists"
|
|
269
|
266
|
|
|
270
|
|
- def post(self, request, *args, **kwargs):
|
|
271
|
|
- self.line.delete()
|
|
|
267
|
+ def get_page_title(self):
|
|
|
268
|
+ return _(u'Remove %s') % self.object.product.get_title()
|
|
|
269
|
+
|
|
|
270
|
+ def get_object(self, queryset=None):
|
|
|
271
|
+ self.fetch_line(
|
|
|
272
|
+ self.request.user, self.kwargs['key'],
|
|
|
273
|
+ self.kwargs.get('line_pk'), self.kwargs.get('product_pk'))
|
|
|
274
|
+ return self.line
|
|
|
275
|
+
|
|
|
276
|
+ def get_context_data(self, **kwargs):
|
|
|
277
|
+ ctx = super(WishListRemoveProduct, self).get_context_data(**kwargs)
|
|
|
278
|
+ ctx['wishlist'] = self.wishlist
|
|
|
279
|
+ ctx['product'] = self.product
|
|
|
280
|
+ return ctx
|
|
272
|
281
|
|
|
|
282
|
+ def get_success_url(self):
|
|
273
|
283
|
msg = _("'%(title)s' was removed from your '%(name)s' wish list") % {
|
|
274
|
284
|
'title': self.product.get_title(),
|
|
275
|
285
|
'name': self.wishlist.name}
|
|
276
|
286
|
messages.success(self.request, msg)
|
|
277
|
287
|
|
|
278
|
|
- default_url = reverse(
|
|
279
|
|
- 'customer:wishlists-detail', kwargs={'key': self.wishlist.key})
|
|
280
|
|
- return HttpResponseRedirect(self.request.META.get(
|
|
281
|
|
- 'HTTP_REFERER', default_url))
|
|
|
288
|
+ # We post directly to this view on product pages; and should send the
|
|
|
289
|
+ # user back there if that was the case
|
|
|
290
|
+ referrer = self.request.META.get('HTTP_REFERER', '')
|
|
|
291
|
+ if self.product.get_absolute_url() in referrer:
|
|
|
292
|
+ return referrer
|
|
|
293
|
+ else:
|
|
|
294
|
+ return reverse(
|
|
|
295
|
+ 'customer:wishlists-detail', kwargs={'key': self.wishlist.key})
|
|
282
|
296
|
|
|
283
|
297
|
|
|
284
|
298
|
class WishListMoveProductToAnotherWishList(LineMixin, View):
|
|
285
|
299
|
|
|
|
300
|
+ def dispatch(self, request, *args, **kwargs):
|
|
|
301
|
+ try:
|
|
|
302
|
+ self.fetch_line(request.user, kwargs['key'],
|
|
|
303
|
+ product_pk=kwargs['product_pk'])
|
|
|
304
|
+ except (ObjectDoesNotExist, MultipleObjectsReturned):
|
|
|
305
|
+ raise Http404
|
|
|
306
|
+ return super(WishListMoveProductToAnotherWishList, self).dispatch(
|
|
|
307
|
+ request, *args, **kwargs)
|
|
|
308
|
+
|
|
286
|
309
|
def get(self, request, *args, **kwargs):
|
|
287
|
310
|
to_wishlist = get_object_or_404(
|
|
288
|
311
|
WishList, owner=request.user, key=kwargs['to_key'])
|