Commit 1e7c502b authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Add translation for messages

See merge request !54
parents e0011d04 fa1f3e97
# Generated by Django 2.2.22 on 2021-05-14 11:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('courses', '0026_auto_20210504_1504'),
]
operations = [
migrations.AddField(
model_name='professormessage',
name='message_en',
field=models.TextField(null=True, verbose_name='Message'),
),
migrations.AddField(
model_name='professormessage',
name='message_es',
field=models.TextField(null=True, verbose_name='Message'),
),
migrations.AddField(
model_name='professormessage',
name='message_pt_br',
field=models.TextField(null=True, verbose_name='Message'),
),
migrations.AddField(
model_name='professormessage',
name='subject_en',
field=models.CharField(max_length=255, null=True, verbose_name='Subject'),
),
migrations.AddField(
model_name='professormessage',
name='subject_es',
field=models.CharField(max_length=255, null=True, verbose_name='Subject'),
),
migrations.AddField(
model_name='professormessage',
name='subject_pt_br',
field=models.CharField(max_length=255, null=True, verbose_name='Subject'),
),
]
......@@ -142,8 +142,9 @@ class ProfessorMessageSerializer(serializers.ModelSerializer):
class Meta:
model = ProfessorMessage
fields = ('id', 'course', 'course_name', 'course_slug', 'professor',
'users', 'subject', 'message', 'date', 'is_read', 'groups', 'classes',
'classrooms',
'users', 'subject', 'message','subject_en', 'message_en',
'subject_pt_br', 'message_pt_br', 'subject_es', 'message_es',
'date', 'is_read', 'groups', 'classes', 'classrooms',
)
def get_course_slug(self, obj):
......
......@@ -122,6 +122,11 @@ class ActionSerializer(serializers.ModelSerializer):
return ' a unidade {} na etapa {} do curso {}'.format(obj.title, obj.lesson, obj.lesson.course)
return ''
def get_actor_name(self, actor):
if actor.name:
return actor.name.split()[0]
return actor.username
def get_action_phrase(self, obj):
verbs = {
'access': 'acessou',
......@@ -133,7 +138,7 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase = ''
action_phrase += obj.actor.name.split()[0]
action_phrase += self.get_actor_name(obj.actor)
action_phrase += (' {}'.format(verbs.get(obj.verb)))
if obj.action_object:
......@@ -181,4 +186,4 @@ class ActionSerializer(serializers.ModelSerializer):
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
return ''
from modeltranslation.translator import register, TranslationOptions
from .models import Course, Lesson, Unit
from .models import Course, Lesson, Unit, ProfessorMessage
from .course_material.models import CourseMaterial, File
......@@ -20,10 +20,17 @@ class LessonTranslationOptions(TranslationOptions):
class UnitTranslationOptions(TranslationOptions):
fields = ('title', 'video', 'side_notes', 'chat_room')
@register(ProfessorMessage)
class ProfessorMessageTranslationOptions(TranslationOptions):
fields = ('subject','message')
@register(CourseMaterial)
class CourseMaterialTranslationOptions(TranslationOptions):
fields = ('text',)
@register(File)
class FileTranslationOptions(TranslationOptions):
fields = ('title', 'file')
......@@ -68,7 +68,9 @@ class CourseViewSet(viewsets.ModelViewSet):
# Q(is_public=True, ) | Q(groups__in=self.request.user.groups.all(), status='published')
# )
#)
query = Q(status='published')
from django.utils.translation import get_language
current_language = get_language()
query = Q(status='published', lang__contains=[current_language])
if (CourseProfessor.objects.filter(user=self.request.user, role='coordinator').exists()):
query.add(Q(
......
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