0

Is it possible to use Django (and self-made) view decorators with Piston handler methods? The problem is that with the methods, the first argument is self (the handler) and the second the request, while for the methods the first argument is the request.

Basically I'd like to do something like this:

from piston.handler import BaseHandler
from django.contrib.auth.decorators import permission_required

class MyHandler(BaseHandler):
    @permission_required(lambda u: u.is_staff or u.is_superuser)
    def read(self, request, foo, bar):
        # do something
hupf
  • 604
  • 1
  • 6
  • 10

1 Answers1

2
from django.utils.decorators import method_decorator

class MyHandler(BaseHandler):
    @method_decorator(permission_required(lambda u: u.is_staff or u.is_superuser))
    def read(self, request, foo, bar):
        # do something
DrTyrsa
  • 31,014
  • 7
  • 86
  • 86