Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from rest_framework.permissions import BasePermission 

2 

3import sys 

4 

5class IsLocationSupervisor(BasePermission): 

6 """ 

7 Custom permission to only allow supervisors of an object to edit it. 

8 """ 

9 

10 def has_object_permission(self, request, view, obj): 

11 # Read permissions are allowed to any request, 

12 # so we'll always allow GET, HEAD or OPTIONS requests. 

13 #if request.method in permissions.SAFE_METHODS: 

14 # return True 

15 

16 # Write permissions are only allowed to a supervisor of the object. 

17 return request.user in obj.supervisors.all() 

18 

19class IsSameUser(BasePermission): 

20 

21 """ 

22 Custom permission to only same user as requested 

23 """ 

24 

25 def has_object_permission(self, request, view, obj): 

26 return request.user == obj 

27 

28class IsSupervisorUser(BasePermission): 

29 

30 """ 

31 Custom permission to supervisor user in request 

32 """ 

33 

34 def has_object_permission(self, request, view, obj): 

35 return request.user.is_supervisor