Question

I have a Django-CMS plugin which is used to display a list of objects. The required functionality of the plugin is that the list is paginated and can be re-ordered based on properties of the objects in the list.

Handling this functionality with ajax is not an ideal solution in this particular case so I was planning on using django Paginator, which requires a 'page' querystring parameter, and passing a 'order' querystring parameter which I would then use to define the order of the queryset.

The problem is that I can't see anyway of accessing the request object from within the plugins render function.

Does anyone know if it's possible to access the request object from within the render function, or can suggest a workaround?

Was it helpful?

Solution

The CMSPluginBase's render method takes a context object. You should be able to access the request via that object if your view is using a RequestContext instance.

class MyCoolPlugin(CMSPluginBase):

    def render(self, context, instance, placeholder):

         #Do something with the request, like access the user
         current_user = context['request'].get('user', None)
         ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top