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