Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access the request object in a Django-CMS plugin?

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?

like image 826
Eric Ressler Avatar asked Jul 12 '12 19:07

Eric Ressler


1 Answers

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)
         ...
like image 134
Casey Kinsey Avatar answered Sep 21 '22 01:09

Casey Kinsey