Tastypie v0.9.11 LoginRequiredAuthorization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from tastypie.authorization import Authorization


class LoginRequiredAuthorization(Authorization):
    """
    Equivalent to Django's login_required decorator
    Be careful with this; it will allow DELETE and everything else.

    """
    def is_authorized(self, request, object=None):
        # GET is always allowed
        if request.method == 'GET':
            return True
        return request.user.is_authenticated()


# Use like this in a ModelResource
class MyResource(ModelResource):
    class Meta:
        authorization = LoginRequiredAuthorization()
        allowed_methods = ['get', 'post', ...]  # pay attention to what you allow

More like this

  1. LoginRequired class-based view decorator by mjumbe 1 year, 9 months ago
  2. Custom requests auth class for Tastypie API key authentication by jezdez 1 year, 1 month ago
  3. View Permission Decorator Helper by jgeewax 4 years, 10 months ago
  4. UKPhoneNumberField GB v2 by g1smd 8 months, 2 weeks ago
  5. caching parsed templates by forgems 5 years, 5 months ago

Comments

(Forgotten your password?)