Commit 6c6683f6 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Translate user actions serializer

parent b8a6e3da
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth import get_user_model
from django.db import transaction
from courses.stats.models import AccessibleArea
class Command(BaseCommand):
help = 'Create AccessibleArea'
@transaction.atomic
def handle(self, *args, **options):
areas = {
'forums': {'name_en': 'Forums', 'name_pt_br': 'Fóruns', 'name_es': 'Foros'},
'messages': {'name_en': 'Messages', 'name_pt_br': 'Avisos', 'name_es': 'Notificaciones'},
'courses': {'name_en': 'Courses', 'name_pt_br': 'Cursos', 'name_es': 'Cursos'},
'classrooms': {'name_en': 'Classrooms', 'name_pt_br': 'Salas', 'name_es': 'Aulas'},
'notes': {'name_en': 'Notes', 'name_pt_br': 'Notas', 'name_es': 'Notas'},
'profile-page': {'name_en': 'Profile Page', 'name_pt_br': 'Página de perfil', 'name_es': 'Página de perfil'},
'chat-main-page': {'name_en': 'Chats page', 'name_pt_br': 'Página de chats', 'name_es': 'Página de chats'},
'dashboard': {'name_en': 'Dashboard', 'name_pt_br': 'Painel', 'name_es': 'Panel'}
}
for slug, attrs in areas.items():
a, created = AccessibleArea.objects.get_or_create(slug=slug)
AccessibleArea.objects.filter(id=a.id).update(**attrs)
......@@ -77,49 +77,86 @@ class ActionSerializer(serializers.ModelSerializer):
date, hour = tz_str.strftime('%d-%m-%Y %H:%M:%S').split()
return '{} / {}'.format(date, hour)
def get_accessible_area_name(self, name):
accessible_areas = {
'Dashboard': 'a Página Inicial',
'Chat Main Page': 'os Chats',
'Profile Page': 'a Página de perfil',
'Notes': 'as Anotações',
'Classrooms': 'as Salas',
'Courses': 'a Lista de Espaços Formativos',
'Messages': 'os Avisos',
'Forums': 'os Fóruns',
'Cards List': 'a Lista de Conteúdos'
}
return accessible_areas.get(name, name)
def get_object_type(self, obj, verb):
def get_object_type(self, obj, verb, lang):
if isinstance(obj, Course):
return ' no curso {}'.format(obj.name)
if lang == 'en':
course = ' at course {}'
if lang == 'pt-br':
course = ' no curso {}'
if lang == 'es':
course = ' en el curso {}'
return course.format(obj.name)
if isinstance(obj, Classroom):
return ' na sala {}'.format(obj.name)
if lang == 'en':
classroom = ' in the classroom {}'
if lang == 'pt-br':
classrom = ' na sala {}'
if lang == 'es':
classroom = ' en la sala {}'
return classroom.format(obj.name)
if isinstance(obj, Topic):
if verb == 'reacted':
topic = ' ao tópico {}'
if lang == 'en':
topic = ' to the topic {}'
if lang == 'pt-br':
topic = ' ao tópico {}'
if lang == 'es':
topic = ' al tema {}'
else:
topic = ' no tópico {}'
if lang == 'en':
topic = ' in the topic {}'
if lang == 'pt-br':
topic = ' no tópico {}'
if lang == 'es':
topic = ' en el tema {}'
return topic.format(obj.title)
if isinstance(obj, Forum):
return ' no fórum {}'.format(obj.title)
if lang == 'en':
forum = ' in the forum {}'
if lang == 'pt-br':
forum = ' no fórum {}'
if lang == 'es':
forum = ' en el foro {}'
return forum.format(obj.title)
if isinstance(obj, AccessibleArea):
return ' {}'.format(self.get_accessible_area_name(obj.name))
return ' {}'.format(obj.name)
if isinstance(obj, LearningObject):
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 lang == 'en':
lo = ' to the activity {} in step {} of course {}'
if lang == 'pt-br':
lo = ' a atividade {} na etapa {} do curso {}'
if lang == 'es':
lo = ' a la actividad {} en el paso {} do curso {}'
return lo.format(unit, step, course)
if isinstance(obj, Card):
if verb == 'reacted':
card = ' ao conteúdo {}'
if lang == 'en':
topic = ' to the content {}'
if lang == 'pt-br':
topic = ' ao conteúdo {}'
if lang == 'es':
topic = ' al contenido {}'
else:
if lang == 'en':
topic = ' the content {}'
if lang == 'pt-br':
topic = ' o conteúdo {}'
if lang == 'es':
topic = ' el contenido {}'
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)
if lang == 'en':
unit = ' the unit {} in step {} of course {}'
if lang == 'pt-br':
unit = ' a unidade {} na etapa {} do curso {}'
if lang == 'es':
unit = ' a la unidad {} en el paso {} do curso {}'
return unit.format(obj.title, obj.lesson, obj.lesson.course)
return ''
def get_actor_name(self, actor):
......@@ -127,24 +164,30 @@ class ActionSerializer(serializers.ModelSerializer):
return actor.name.split()[0]
return actor.username
def get_action_phrase(self, obj):
def get_verb(self, verb, lang):
verbs = {
'access': 'acessou',
'answered': 'respondeu',
'created': 'criou',
'reacted': 'reagiu',
'created comment': 'comentou'
'access': {'en': 'accessed', 'pt-br': 'acessou', 'es': 'accedió'},
'answered': {'en': 'answered', 'pt-br': 'respondeu', 'es': 'respondió'},
'created': {'en': 'created', 'pt-br': 'criou', 'es': 'creado'},
'reacted': {'en': 'reacted', 'pt-br': 'reagiu', 'es': 'reaccionó'},
'created comment': {'en': 'commented', 'pt-br': 'comentou', 'es': 'comentó'}
}
return verbs[verb][lang]
def get_action_phrase(self, obj):
from django.utils.translation import get_language
lang = get_language()
action_phrase = ''
action_phrase += self.get_actor_name(obj.actor)
action_phrase += (' {}'.format(verbs.get(obj.verb)))
action_phrase += (' {}'.format(self.get_verb(obj.verb, lang)))
if obj.action_object:
action_phrase += self.get_object_type(obj.action_object, obj.verb)
action_phrase += self.get_object_type(obj.action_object, obj.verb, lang)
if obj.target:
action_phrase += self.get_object_type(obj.target, obj.verb)
action_phrase += self.get_object_type(obj.target, obj.verb, lang)
return action_phrase
......@@ -156,14 +199,14 @@ 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):
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': ''}
......
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