Commit ac21e93e authored by Glaucia Schnoeller dos Santos's avatar Glaucia Schnoeller dos Santos
Browse files

Merge branch 'issue_271_save_actions' into 'develop'

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

See merge request !35
parents a09ddbe6 50e457d0
......@@ -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,8 +65,12 @@ 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):
from django.utils import timezone
tz_str = timezone.localtime(obj.timestamp)
......@@ -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
......@@ -138,11 +151,34 @@ class ActionSerializer(serializers.ModelSerializer):
course = 'do curso {}'.format(obj.target.unit.lesson.course.name)
compl = {'atividade': unit, 'etapa': step, 'curso': course}
return compl
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 isinstance(obj.action_object, Card) and isinstance(obj.target, Classroom):
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': ''}
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