Commit 57748d6b authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Allow target for user accesses log

parent 4b58ca30
......@@ -30,6 +30,8 @@ class UserActionsSerializer(serializers.Serializer):
class UserAccessSerializer(serializers.Serializer):
area = serializers.CharField(required=True, max_length=100)
target_id = serializers.IntegerField(required=False)
target_type = serializers.CharField(required=False, max_length=100)
class GenericRelatedField(serializers.Field):
......@@ -57,8 +59,9 @@ class ActionSerializer(serializers.ModelSerializer):
if isinstance(obj.target, LearningObject):
return obj.target.unit.lesson.course.name
if isinstance(obj.target, Forum):
print(obj.target)
return obj.target.title
if isinstance(obj.target, Classroom):
return obj.target.name
return obj.target
def get_timestamp(self, obj):
......@@ -99,8 +102,7 @@ class ActionSerializer(serializers.ModelSerializer):
return ' a atividade {} na etapa {} do curso {}'.format(unit, step, course)
if isinstance(obj, Card):
title = obj.title
group_name = obj.groups.first().name
return ' o conteúdo {} na {}'.format(title, group_name)
return ' o conteúdo {}'.format(title)
return ''
def get_action_phrase(self, obj):
......
......@@ -74,8 +74,13 @@ class UserAccessView(views.APIView):
except AccessibleArea.DoesNotExist:
return Response({'error': 'Specified area not found'}, status=status.HTTP_404_NOT_FOUND)
if 'target_type' in data and data['target_type'] == 'Classroom':
target = Classroom.objects.get(id=data['target_id'])
else:
target = None
# Save the action
action.send(request.user, verb='access', action_object=action_object)
action.send(request.user, verb='access', action_object=action_object, target=target)
return Response(None, status=status.HTTP_201_CREATED)
......
Markdown is supported
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