Search code examples
pythondjangofacebookfandjango

Apply decorator to context processor


I'm using Fandjango for a Django Facebook Canvas app.

To use fandjango, you need to wrap all view functions with @facebook_authorization_required, which makes sure you're authorized, then gives you the variable request.facebook.user.

What I want is to make a context processor which defines a few more variables based on this, i.e., I want all my templates to be able to use fb_user as a shortcut for request.facebook.user.

The problem is, I don't know how to use the decorator on the context processor.

Any ideas how I can do this?


Solution

  • There's no need to wrap the context processor. If you've wrapped the view in the first place, then the request will already be annotated with the facebook.user attribute. Since the request is passed to the context processor anyway, you have access to that attribute.

    You should probably do a quick check - if hasattr(request, 'facebook') - within the context processor, just to make sure it's being called from a wrapped view.