S
S
siarheisiarhei2020-10-24 08:22:21
Django
siarheisiarhei, 2020-10-24 08:22:21

Oscar-django, extended (class CatalogView); but how to do it more (elegantly-correctly)?

class CatalogueView(TemplateView):
    """
    Browse all products in the catalogue
    """
    context_object_name = "products"
    template_name = 'oscar/catalogue/browse.html'

    def get(self, request, *args, **kwargs):
        try:
            self.search_handler = self.get_search_handler(
                self.request.GET, request.get_full_path(), [])
        except InvalidPage:
            # Redirect to page one.
            messages.error(request, _('The given page number was invalid.'))
            return redirect('catalogue:index')
        return super().get(request, *args, **kwargs)

    def get_search_handler(self, *args, **kwargs):
        return get_product_search_handler_class()(*args, **kwargs)

    def get_context_data(self, **kwargs):
        ctx = {}
        ctx['summary'] = _("All products")
        search_context = self.search_handler.get_search_context_data(
            self.context_object_name)
        ctx.update(search_context)
        return ctx
    def get_context_data(self, *args, **kwargs): # <--- method already defined (function-redefined)
        context = super(CatalogueView, self).get_context_data(*args, **kwargs)
        context['slides'] = SliderImage.objects.order_by("-created_on")
        return context

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
siarheisiarhei, 2020-10-24
@siarheisiarhei

def get_context_data(self, *args, **kwargs):
        ctx = {}
        ctx = super(CatalogueView, self).get_context_data(*args, **kwargs)
        ctx['slides'] = SliderImage.objects.order_by("-created_on")


        ctx['summary'] = _("All products")
        search_context = self.search_handler.get_search_context_data(
            self.context_object_name)
        ctx.update(search_context)
        return ctx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question