Commit 426249a0 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Translate Accessible Areas

See merge request !55
parents 1e7c502b eae1e2be
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)
attrs['slug_en'] = slug
attrs['slug_pt_br'] = slug
attrs['slug_es'] = slug
AccessibleArea.objects.filter(id=a.id).update(**attrs)
......@@ -151,7 +151,7 @@ class UserStatsSerializer(serializers.ModelSerializer):
from django.utils import timezone
tz_str = timezone.localtime(timestamp)
date, hour = tz_str.strftime('%d-%m-%Y %H:%M:%S').split()
return '{} às {}'.format(date, hour)
return '{} / {}'.format(date, hour)
else:
return ''
......
......@@ -351,7 +351,7 @@ class UserAccessView(views.APIView):
from django.utils import timezone
tz_str = timezone.localtime(timestamp)
date, hour = tz_str.strftime('%d-%m-%Y %H:%M:%S').split()
return '{} às {}'.format(date, hour)
return '{} / {}'.format(date, hour)
def get(self, request, format=None):
user_id = request.GET['user']
......
# Generated by Django 2.2.22 on 2021-05-17 15:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stats', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='accessiblearea',
name='name_en',
field=models.CharField(max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='accessiblearea',
name='name_es',
field=models.CharField(max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='accessiblearea',
name='name_pt_br',
field=models.CharField(max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='accessiblearea',
name='slug_en',
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Slug'),
),
migrations.AddField(
model_name='accessiblearea',
name='slug_es',
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Slug'),
),
migrations.AddField(
model_name='accessiblearea',
name='slug_pt_br',
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Slug'),
),
]
......@@ -60,7 +60,7 @@ class ActionSerializer(serializers.ModelSerializer):
if isinstance(obj.target, LearningObject):
if not obj.target.unit:
return ''
return obj.target.unit.lesson.course.name
return obj.target.unit.lesson.course.name
if isinstance(obj.target, Forum):
return obj.target.title
if isinstance(obj.target, Classroom):
......@@ -70,56 +70,93 @@ class ActionSerializer(serializers.ModelSerializer):
return obj.target
return obj.target
def get_timestamp(self, obj):
from django.utils import timezone
tz_str = timezone.localtime(obj.timestamp)
date, hour = tz_str.strftime('%d-%m-%Y %H:%M:%S').split()
return '{} às {}'.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)
return '{} / {}'.format(date, hour)
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':
card = ' to the content {}'
if lang == 'pt-br':
card = ' ao conteúdo {}'
if lang == 'es':
card = ' al contenido {}'
else:
if lang == 'en':
card = ' the content {}'
if lang == 'pt-br':
card = ' o conteúdo {}'
if lang == 'es':
card = ' 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': ''}
......
......@@ -49,9 +49,9 @@ class UserActionsView(views.APIView):
# Get the actual model objects for action and target
action_object = None
target = None
if 'action_object_type' in data:
if 'action_object_type' in data and 'action_object_id' in data:
action_object = allowed_models[data['action_object_type']].objects.get(id=data['action_object_id'])
if 'target_type' in data:
if 'target_type' in data and 'target_id' in data:
target = allowed_models[data['target_type']].objects.get(id=data['target_id'])
# Save the action
......
from modeltranslation.translator import register, TranslationOptions
from .models import Course, Lesson, Unit, ProfessorMessage
from .course_material.models import CourseMaterial, File
from .stats.models import AccessibleArea
@register(Course)
......@@ -34,3 +35,8 @@ class CourseMaterialTranslationOptions(TranslationOptions):
@register(File)
class FileTranslationOptions(TranslationOptions):
fields = ('title', 'file')
@register(AccessibleArea)
class AccessibleAreaTranslationOptions(TranslationOptions):
fields = ('name', 'slug')
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