Commit 8c481b33 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Add i18n to certificates templates

See merge request !56
parents 426249a0 91f0df80
# Generated by Django 2.2.23 on 2021-05-20 14:26
import courses.utils
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('certification', '0004_auto_20200703_2023'),
]
operations = [
migrations.AddField(
model_name='certificatetemplate',
name='second_name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Second Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_role',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Second Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_signature',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('second_signature', 'organization_name'), verbose_name='Second Signature'),
),
]
# Generated by Django 2.2.23 on 2021-05-20 20:24
import courses.utils
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('certification', '0005_auto_20210520_1126'),
]
operations = [
migrations.AddField(
model_name='certificatetemplate',
name='base_logo_en',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('base_logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='base_logo_es',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('base_logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='base_logo_pt_br',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('base_logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='cert_logo_en',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='cert_logo_es',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='cert_logo_pt_br',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('logo', 'organization_name'), verbose_name='Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='organization_name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='organization_name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='organization_name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='role_en',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='role_es',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='role_pt_br',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Second Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Second Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Second Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_role_en',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Second Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_role_es',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Second Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_role_pt_br',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Second Role'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_signature_en',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('second_signature', 'organization_name'), verbose_name='Second Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_signature_es',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('second_signature', 'organization_name'), verbose_name='Second Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='second_signature_pt_br',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('second_signature', 'organization_name'), verbose_name='Second Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_en',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('signature', 'organization_name'), verbose_name='Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_es',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('signature', 'organization_name'), verbose_name='Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_pt_br',
field=models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('signature', 'organization_name'), verbose_name='Signature'),
),
migrations.AddField(
model_name='certificatetemplate',
name='site_logo_en',
field=models.ImageField(blank=True, null=True, upload_to='certificates_files', verbose_name='Site Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='site_logo_es',
field=models.ImageField(blank=True, null=True, upload_to='certificates_files', verbose_name='Site Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='site_logo_pt_br',
field=models.ImageField(blank=True, null=True, upload_to='certificates_files', verbose_name='Site Logo'),
),
migrations.AddField(
model_name='certificatetemplate',
name='text_en',
field=models.TextField(default='', null=True, verbose_name='Content'),
),
migrations.AddField(
model_name='certificatetemplate',
name='text_es',
field=models.TextField(default='', null=True, verbose_name='Content'),
),
migrations.AddField(
model_name='certificatetemplate',
name='text_pt_br',
field=models.TextField(default='', null=True, verbose_name='Content'),
),
]
......@@ -214,6 +214,18 @@ class CertificateTemplate(models.Model):
max_length=255,
null=True,
)
second_role = models.CharField(
_('Second Role'),
max_length=128,
blank=True,
null=True,
)
second_name = models.CharField(
_('Second Signature Name'),
blank=True,
max_length=255,
null=True,
)
cert_logo = models.ImageField(
_('Logo'),
null=True,
......@@ -232,6 +244,12 @@ class CertificateTemplate(models.Model):
blank=True,
upload_to=hash_name('signature', 'organization_name'),
)
second_signature = models.ImageField(
_('Second Signature'),
null=True,
blank=True,
upload_to=hash_name('second_signature', 'organization_name'),
)
site_logo = models.ImageField(
_('Site Logo'),
null=True,
......@@ -284,6 +302,12 @@ class CertificateTemplate(models.Model):
return self.signature.url
return ''
@property
def second_signature_url(self):
if self.second_signature:
return self.second_signature.url
return ''
@property
def site_logo_url(self):
if self.site_logo:
......
......@@ -22,7 +22,8 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
model = CertificateTemplate
fields = ('id', 'text', 'base_logo_url', 'cert_logo_url', 'role', 'name',
'course_name', 'contract', 'associate', 'workspace', 'document_type',
'organization_name', 'site_logo_url', 'signature_url', 'course',)
'organization_name', 'site_logo_url', 'signature_url', 'course',
'second_signature_url', 'second_name', 'second_role')
def get_associate(self, obj):
filters = {
......@@ -52,7 +53,7 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer):
class Meta:
model = CertificateTemplate
fields = ('base_logo', 'cert_logo', 'signature', 'site_logo')
fields = ('base_logo', 'cert_logo', 'signature', 'site_logo', 'second_signature')
class CertificationProcessSerializer(serializers.ModelSerializer):
......
......@@ -107,7 +107,7 @@ class CourseCertificationViewSet(viewsets.ModelViewSet):
class CertificateTemplateViewSet(viewsets.ModelViewSet):
model = CertificateTemplate
queryset = CertificateTemplate.objects.all()
# lookup_field = 'course'
#lookup_field = 'course'
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, )
serializer_class = CertificateTemplateSerializer
......@@ -125,6 +125,7 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet):
('cert_logo', request.data.get('cert_logo_clear', None)),
('base_logo', request.data.get('base_logo_clear', None)),
('signature', request.data.get('signature_clear', None)),
('second_signature', request.data.get('second_signature_clear', None)),
('site_logo', request.data.get('site_logo_clear', None)),
)
for cl in clear_logos:
......@@ -222,9 +223,11 @@ class CourseCertificationDetailView(DetailView):
certificate.course_student.finish_date.year
)
workspace = context['cert_template'].workspace
w_name = workspace.name if workspace else ''
context['cert_template'].text = context['cert_template'].text\
.replace('{NOME}', certificate.student.get_full_name())\
.replace('{CONTRATO}', context['cert_template'].workspace.name)\
.replace('{CONTRATO}', w_name)\
.replace('{NUM_UNIDADES}', str(certificate.course_total_units))\
.replace('{HORAS}', str(certificate.course.course_load))\
.replace('{TURMA}', certificate.course_student.get_current_class().name)\
......
......@@ -13,6 +13,7 @@ from .models import (
Unit,
Lesson
)
from .certification.models import CertificateTemplate
User = get_user_model()
......@@ -37,6 +38,7 @@ class CourseSerializer(serializers.ModelSerializer):
is_user_coordinator = serializers.SerializerMethodField()
is_assistant_or_coordinator = serializers.SerializerMethodField()
track = serializers.SerializerMethodField()
ct_id = serializers.SerializerMethodField()
class Meta:
model = Course
......@@ -46,7 +48,7 @@ class CourseSerializer(serializers.ModelSerializer):
'start_date', 'home_published', 'authors_names', 'has_started',
'min_percent_to_complete', 'is_user_assistant', 'is_user_coordinator',
'is_assistant_or_coordinator', 'professors', 'track', 'forum_id',
'informations', 'description', 'lang', 'course_load')
'informations', 'description', 'lang', 'course_load', 'ct_id',)
@staticmethod
def get_home_thumbnail_url(obj):
......@@ -69,6 +71,12 @@ class CourseSerializer(serializers.ModelSerializer):
return {'name': course_track.first().name, 'home_position': course_track.first().home_position }
return {}
def get_ct_id(self, obj):
ct = CertificateTemplate.objects.filter(course=obj).first()
if ct:
return ct.id
return None
def update(self, instance, validated_data):
intro_video_data = validated_data.pop('intro_video', None)
......
......@@ -2,6 +2,7 @@ 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
from .certification.models import CertificateTemplate
@register(Course)
......@@ -40,3 +41,10 @@ class FileTranslationOptions(TranslationOptions):
@register(AccessibleArea)
class AccessibleAreaTranslationOptions(TranslationOptions):
fields = ('name', 'slug')
@register(CertificateTemplate)
class CertificateTemplateTranslationOptions(TranslationOptions):
fields = ('role', 'name', 'second_role', 'second_name', 'cert_logo',
'base_logo', 'signature', 'second_signature', 'site_logo',
'organization_name', 'text')
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