Skip to content

Commit

Permalink
Hooks for modifying ProductCreateRedirectView
Browse files Browse the repository at this point in the history
  • Loading branch information
izidormatusov committed Feb 6, 2014
1 parent 03984b1 commit 9cffaba
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions oscar/apps/dashboard/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,26 @@ def apply_search(self, queryset):

class ProductCreateRedirectView(generic.RedirectView):
permanent = False

def handle_invalid_product_class(self):
messages.error(self.request, _("Please choose a product class"))
return reverse('dashboard:catalogue-product-list')

def get_product_create_url(self, product_class):
""" Allow site to provide custom URL """
return reverse('dashboard:catalogue-product-create',
kwargs={'product_class_id': product_class.id})

def get_redirect_url(self, **kwargs):
product_class_id = self.request.GET.get('product_class', None)
if not product_class_id or not product_class_id.isdigit():
messages.error(self.request, _("Please choose a product class"))
return reverse('dashboard:catalogue-product-list')
return self.handle_invalid_product_class()
try:
product_class = ProductClass.objects.get(id=product_class_id)
except ProductClass.DoesNotExist:
messages.error(self.request, _("Please choose a product class"))
return reverse('dashboard:catalogue-product-list')
return self.handle_invalid_product_class()
else:
return reverse('dashboard:catalogue-product-create',
kwargs={'product_class_id': product_class.id})
return self.get_product_create_url(product_class)


class ProductCreateUpdateView(generic.UpdateView):
Expand Down

0 comments on commit 9cffaba

Please sign in to comment.