Gitlab CSE Unil

Commit 72e0c3f6 authored by Julien Furrer's avatar Julien Furrer
Browse files

ajusté adim.view pour compatibilité avec restframework v3.3

parent 0dbce233
......@@ -25,6 +25,7 @@ class AccessibleAnObj(BasePermission):
RestFramework Object-level permission to allow access to objects related to an accessible AnObj
Assumes the model instance has an `annotable` attribute.
"""
def has_object_permission(self, request, view, obj):
try:
return has_anobj_access(request, obj.annotable)
......@@ -54,6 +55,7 @@ class IsOwnerOrReadOnly(BasePermission):
else:
return False
class WritableAnObjOrReadonly(BasePermission):
"""
RestFramework Object-level permission to only allow modification on objects
......@@ -90,6 +92,7 @@ class AnObjViewSet(viewsets.ModelViewSet):
"""
model = AnObj
serializer_class = AnObjSerializer
# lookup_field = 'uuid'
def get_serializer_class(self):
......@@ -122,7 +125,7 @@ class AnObjViewSet(viewsets.ModelViewSet):
if request.method != 'GET':
user_model = get_user_model()
members = []
for member_data in request.DATA.get('members', []):
for member_data in request.data.get('members', []):
try:
q = Q(pk=-1)
if member_data.get('id'):
......@@ -156,7 +159,7 @@ class AnObjViewSet(viewsets.ModelViewSet):
def set_publish_mode(self, request, pk=None):
user = request.user
anobj = AnObj.objects.get(pk=pk)
new_publish_mode = int(request.DATA.get('publish_mode', 0))
new_publish_mode = int(request.data.get('publish_mode', 0))
if new_publish_mode not in xrange(3):
raise ValueError("Invalid publish mode")
......@@ -301,8 +304,14 @@ class AnnotationViewSet(viewsets.ModelViewSet):
:param kwargs:
:return:
"""
request.data['owner'] = request.user.id
request.data['owner_id'] = request.user.id
owner_str_id = str(request.user.id)
if (
owner_str_id not in request.data['owner'] or
owner_str_id not in request.data['owner_id']
):
raise AttributeError("Wrong owner for annotation")
# request.data['owner'] = request.user.id
# request.data['owner_id'] = request.user.id
return super(AnnotationViewSet, self).create(request, *args, **kwargs)
# def list(self, request):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment