Commit 4fe14c02 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add logic to create action phrase

parent ca2b837f
......@@ -10,6 +10,7 @@ User = get_user_model()
from courses.classroom.models import Classroom
from courses.classroom.serializers import BasicClassroomSerializer
from discussion.models import Comment, Topic
class UserActionsSerializer(serializers.Serializer):
verb = serializers.CharField(required=True, max_length=100)
......@@ -37,7 +38,37 @@ class ActionSerializer(serializers.ModelSerializer):
target = GenericRelatedField(read_only=True)
action_object = GenericRelatedField(read_only=True)
verb = GenericRelatedField(read_only=True)
action_phrase = serializers.SerializerMethodField()
class Meta:
model = Action
fields = ('actor', 'target', 'action_object', 'verb')
fields = ('actor', 'target', 'action_object', 'verb', 'action_phrase')
def get_object_type(self, obj):
if isinstance(obj, Classroom):
return ' na sala '
if isinstance(obj, Comment):
return ' no comentário '
if isinstance(obj, Topic):
return ' no tópico '
return ''
def get_action_phrase(self, obj):
verbs = {
'access': 'acessou',
'answered': 'respondeu',
'created': 'criou',
'reacted': 'reagiu'
}
action_phrase = ''
action_phrase += obj.actor.name
action_phrase += (' ' + verbs.get(obj.verb))
if obj.target:
action_phrase += (self.get_object_type(obj.target) + str(obj.target))
if obj.action_object:
action_phrase += (self.get_object_type(obj.action_object) + str(obj.action_object))
return action_phrase
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