django-shop
django-shop copied to clipboard
CMSPageCatalogWrapper does not allow to change pagination_class
Problem
I'm trying to overwrite the default_limit on the ProductListPagination. To do that I have created a derived class
class BiggerProductListPagination(ProductListPagination):
default_limit = 100
However, passing there is no easy option to set the pagination class in the cms_apps.py (e.g. via CMSPageCatalogWrapper.as_view(pagination_class=BiggerProductListPagination)
).
Workaround
My workaround is currently deriving from CMSPageCatalogWrapper and overwriting the as_view
method:
@classmethod
def as_view(cls, **initkwargs):
self = super().as_view(**initkwargs)
attrs = dict(renderer_classes=self.renderer_classes, product_model=self.product_model,
limit_choices_to=self.limit_choices_to, filter_class=self.filter_class,
filter_backends=self.filter_backends, cms_pages_fields=self.cms_pages_fields,
pagination_class=self.pagination_class
)
bases = (AddFilterContextMixin, AddSearchContextMixin, ProductListView)
self.list_view = type(str('CatalogListView'), bases, attrs).as_view(
serializer_class=self.model_serializer_class)
return self
Ideas
Not sure if we could modify just pass all attributes to the list_view and search_view type creations. This would enable us to set all list_view and search_view attributes via the as_view
method of CMSPageCatalogWrapper
used when setting urls.
This security mechanism/pattern has been copied from DRF. They also do it like so.
What about adding pagination_class = ProductListPagination
to CMSPageCatalogWrapper
? This then would be consistent with the current approach.
Please try the latest master branch. There I added a my proposal from above. If that works for you, I'll release a new version.