Testing to whether a user can attach/unattach is now deferred to the model.

This commit is contained in:
Michael DeHaan
2013-03-23 14:31:36 -04:00
parent 4e7827829f
commit 0c9aa1a498
4 changed files with 42 additions and 12 deletions

View File

@@ -22,7 +22,7 @@ class BaseList(generics.ListCreateAPIView):
if request.method == 'GET':
return True
if request.method == 'POST':
return False
return self.__class__.model.can_user_add(request.user)
raise exceptions.NotImplementedError
def get_queryset(self):
@@ -32,6 +32,16 @@ class BaseSubList(BaseList):
''' used for subcollections with an overriden post '''
def list_permissions_check(self, request, obj=None):
''' determines some early yes/no access decisions, pre-filtering '''
if request.method == 'GET':
return True
if request.method == 'POST':
# the can_user_attach methods will be called below
return True
raise exceptions.NotImplementedError
def post(self, request, *args, **kwargs):
parent_id = kwargs['pk']