Commit 9f54ddd4 authored by Glaucia S. Santos's avatar Glaucia S. Santos
Browse files

Retorn new informations in serializer

parent 677a0e87
......@@ -49,15 +49,17 @@ class ActionSerializer(serializers.ModelSerializer):
action_object = GenericRelatedField(read_only=True)
verb = GenericRelatedField(read_only=True)
action_phrase = serializers.SerializerMethodField()
complements = serializers.SerializerMethodField()
timestamp = serializers.SerializerMethodField()
class Meta:
model = Action
fields = ('actor', 'target', 'action_object', 'verb', 'action_phrase', 'timestamp')
fields = ('actor', 'target', 'action_object', 'verb', 'action_phrase', 'timestamp', 'complements')
def get_target(self, obj):
if isinstance(obj.target, LearningObject):
return obj.target.unit.lesson.course.name
if obj.target.unit:
return obj.target.unit.lesson.course.name
if isinstance(obj.target, Forum):
return obj.target.title
if isinstance(obj.target, Classroom):
......@@ -96,10 +98,11 @@ class ActionSerializer(serializers.ModelSerializer):
if isinstance(obj, AccessibleArea):
return ' {}'.format(self.get_accessible_area_name(obj.name))
if isinstance(obj, LearningObject):
unit = obj.unit.title
step = obj.unit.lesson.name
course = obj.unit.lesson.course.name
return ' a atividade {} na etapa {} do curso {}'.format(unit, step, course)
if obj.unit:
unit = obj.unit.title
step = obj.unit.lesson.name
course = obj.unit.lesson.course.name
return ' a atividade {} na etapa {} do curso {}'.format(unit, step, course)
if isinstance(obj, Card):
title = obj.title
return ' o conteúdo {}'.format(title)
......@@ -125,3 +128,13 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase += self.get_object_type(obj.target)
return action_phrase
def get_complements(self, obj):
if obj.target:
if isinstance(obj.target, LearningObject):
unit = ' a atividade {}'.format(obj.target.unit.title)
step = 'na etapa {}'.format(obj.target.unit.lesson.name)
course = 'do curso {}'.format(obj.target.unit.lesson.course.name)
compl = {'atividade': unit, 'etapa': step, 'curso': course}
return compl
return ''
\ No newline at end of file
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