Commit 50e457d0 authored by Glaucia S. Santos's avatar Glaucia S. Santos
Browse files

Addition of the comment model in apps and update of the serializer with new actions

parent e233fb73
......@@ -14,4 +14,6 @@ class CoursesStatsConfig(AppConfig):
registry.register('stats.AccessibleArea')
registry.register('discussion.Topic')
registry.register('discussion.Forum')
registry.register('discussion.Comment')
registry.register('cards.Card')
registry.register('courses.Unit')
......@@ -7,7 +7,7 @@ from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User = get_user_model()
from courses.models import Course
from courses.models import Course, Unit
from courses.stats.models import AccessibleArea
from courses.classroom.models import Classroom
from courses.classroom.serializers import BasicClassroomSerializer
......@@ -65,6 +65,10 @@ class ActionSerializer(serializers.ModelSerializer):
return obj.target.title
if isinstance(obj.target, Classroom):
return obj.target.name
if isinstance(obj.target, Topic):
return obj.target.title
return obj.target
return obj.target
def get_timestamp(self, obj):
......@@ -87,13 +91,17 @@ class ActionSerializer(serializers.ModelSerializer):
}
return accessible_areas.get(name, name)
def get_object_type(self, obj):
def get_object_type(self, obj, verb):
if isinstance(obj, Course):
return ' no curso {}'.format(obj.name)
if isinstance(obj, Classroom):
return ' na sala {}'.format(obj.name)
if isinstance(obj, Topic):
return ' no tópico {}'.format(obj.title)
if verb == 'reacted':
topic = ' ao tópico {}'
else:
topic = ' no tópico {}'
return topic.format(obj.title)
if isinstance(obj, Forum):
return ' no fórum {}'.format(obj.title)
if isinstance(obj, AccessibleArea):
......@@ -105,8 +113,13 @@ class ActionSerializer(serializers.ModelSerializer):
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)
if verb == 'reacted':
card = ' ao conteúdo {}'
else:
card = ' o conteúdo {}'
return card.format(obj.title)
if isinstance(obj, Unit):
return ' a unidade {} na etapa {} do curso {}'.format(obj.title, obj.lesson, obj.lesson.course)
return ''
def get_action_phrase(self, obj):
......@@ -114,7 +127,7 @@ class ActionSerializer(serializers.ModelSerializer):
'access': 'acessou',
'answered': 'respondeu',
'created': 'criou',
'reacted': 'reagiu a',
'reacted': 'reagiu',
'created comment': 'comentou'
}
......@@ -124,9 +137,9 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase += (' {}'.format(verbs.get(obj.verb)))
if obj.action_object:
action_phrase += self.get_object_type(obj.action_object)
action_phrase += self.get_object_type(obj.action_object, obj.verb)
if obj.target:
action_phrase += self.get_object_type(obj.target)
action_phrase += self.get_object_type(obj.target, obj.verb)
return action_phrase
......@@ -141,8 +154,31 @@ class ActionSerializer(serializers.ModelSerializer):
if obj.action_object and obj.target:
if isinstance(obj.action_object, Card) and isinstance(obj.target, Classroom):
title = 'o conteúdo {}'.format(obj.action_object.title)
if obj.verb == 'reacted':
content = 'ao conteúdo {}'
else:
content = 'o conteúdo {}'
title = content.format(obj.action_object.title)
classroom = 'na sala {}'.format(obj.target.name)
compl = {'title': title, 'classroom': classroom, 'curso': ''}
return compl
if isinstance(obj.action_object, Topic) and isinstance(obj.target, Forum):
if obj.verb == 'reacted':
topic = 'ao tópico {}'
else:
topic = 'no tópico {}'
forum = 'no fórum {}'.format(obj.target.title)
compl = {'topic': topic.format(obj.action_object.title), 'forum': forum, 'curso': ''}
return compl
if obj.action_object:
if isinstance(obj.action_object, Unit):
unit = 'a unidade {}'.format(obj.action_object.title)
step = 'na etapa {}'.format(obj.action_object.lesson)
course = 'do curso {}'.format(obj.action_object.lesson.course)
compl = {'atividade': unit, 'etapa': step, 'curso': course}
return compl
return ''
\ No newline at end of file
......@@ -13,6 +13,8 @@ from ..models import Course
from ..classroom.models import Classroom
from cards.models import Card
from courses.models import Unit
from courses_learning_objects.models import LearningObject
......@@ -35,6 +37,7 @@ class UserActionsView(views.APIView):
'AccessibleArea': AccessibleArea,
'LearningObject': LearningObject,
'Card': Card,
'Unit': Unit,
}
# Validate incoming data
......
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