Commit 2c4e4d0d authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

implement new class based certificate

See merge request !80
parents 9dc49bf7 dca44dcb
# Generated by Django 2.2.24 on 2021-08-17 03:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('certification', '0008_auto_20210730_1110'),
]
operations = [
migrations.AddField(
model_name='certificatetemplate',
name='signature_name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AddField(
model_name='certificatetemplate',
name='signature_name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Signature Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='organization_name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Organization Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='organization_name_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Organization Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='organization_name_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Organization Name'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='organization_name_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Organization Name'),
),
migrations.AlterUniqueTogether(
name='certificatetemplate',
unique_together=set(),
),
]
...@@ -61,6 +61,17 @@ class CourseCertification(models.Model): ...@@ -61,6 +61,17 @@ class CourseCertification(models.Model):
def course(self): def course(self):
return self.course_student.course return self.course_student.course
@property
def klass(self):
return self.course_student.get_current_class()
@property
def template(self):
if self.type == self.TYPES[0][1]:
return self.course_student.get_current_class().receipt_template
else:
return self.course_student.get_current_class().certificate_template
@property @property
def get_approved_process(self): def get_approved_process(self):
return CertificationProcess.objects.get(course_certification=self.id, return CertificationProcess.objects.get(course_certification=self.id,
...@@ -209,6 +220,12 @@ class CertificateTemplate(models.Model): ...@@ -209,6 +220,12 @@ class CertificateTemplate(models.Model):
null=True, null=True,
) )
name = models.CharField( name = models.CharField(
_('Name'),
blank=True,
max_length=255,
null=True,
)
signature_name = models.CharField(
_('Signature Name'), _('Signature Name'),
blank=True, blank=True,
max_length=255, max_length=255,
...@@ -267,7 +284,7 @@ class CertificateTemplate(models.Model): ...@@ -267,7 +284,7 @@ class CertificateTemplate(models.Model):
default=True, default=True,
) )
organization_name = models.CharField( organization_name = models.CharField(
_('Name'), _('Organization Name'),
max_length=255, max_length=255,
blank=True, blank=True,
null=True, null=True,
...@@ -292,7 +309,6 @@ class CertificateTemplate(models.Model): ...@@ -292,7 +309,6 @@ class CertificateTemplate(models.Model):
class Meta: class Meta:
verbose_name = _('Certificate Template') verbose_name = _('Certificate Template')
unique_together = ('workspace', 'course', 'document_type')
def __str__(self): def __str__(self):
return '({0})'.format(self.course) return '({0})'.format(self.course)
......
...@@ -20,7 +20,7 @@ class CertificateTemplateSerializer(serializers.ModelSerializer): ...@@ -20,7 +20,7 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CertificateTemplate model = CertificateTemplate
fields = ('id', 'text', 'base_logo_url', 'cert_logo_url', 'role', 'name', fields = ('id', 'text', 'base_logo_url', 'cert_logo_url', 'signature_name', 'role', 'name',
'course_name', 'contract', 'associate', 'workspace', 'document_type', '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', 'second_signature_url', 'second_name', 'second_role',
...@@ -48,7 +48,12 @@ class CertificateTemplateSerializer(serializers.ModelSerializer): ...@@ -48,7 +48,12 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
class CertificateTemplateCreateSerializer(serializers.ModelSerializer): class CertificateTemplateCreateSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CertificateTemplate model = CertificateTemplate
fields = ('course', 'document_type', 'workspace') fields = (
'name',
'course',
'document_type',
'workspace',
)
class CertificateTemplateImageSerializer(serializers.ModelSerializer): class CertificateTemplateImageSerializer(serializers.ModelSerializer):
......
...@@ -184,14 +184,12 @@ class CourseCertificationDetailView(DetailView): ...@@ -184,14 +184,12 @@ class CourseCertificationDetailView(DetailView):
workspace = certificate.course_student\ workspace = certificate.course_student\
.get_current_class().contract.first() .get_current_class().contract.first()
if not certificate.course_student.can_emmit_receipt(): if not certificate.course_student.can_emmit_receipt() or not certificate.template:
raise Http404 raise Http404
if certificate: if certificate:
context['cert_template'] = CertificateTemplate.objects.get(
course=certificate.course_student.course, context['cert_template'] = certificate.template
document_type=certificate.type,
)
# Interpolate data into text string # Interpolate data into text string
# {Nome} : certificate.student (name) # {Nome} : certificate.student (name)
# {CPF} : certificate.student.cpf) # {CPF} : certificate.student.cpf)
...@@ -258,13 +256,9 @@ class CourseCertificationPDFView(PDFView, SingleObjectMixin): ...@@ -258,13 +256,9 @@ class CourseCertificationPDFView(PDFView, SingleObjectMixin):
certificate = self.object certificate = self.object
if not certificate.course_student.can_emmit_receipt(): if not certificate.course_student.can_emmit_receipt() or not certificate.template:
raise Http404 raise Http404
if certificate: context['cert_template'] = certificate.template
context['cert_template'] = CertificateTemplate.objects.get(
course=certificate.course_student.course,
document_type=certificate.type,
)
return context return context
\ No newline at end of file
...@@ -46,7 +46,7 @@ class AccessibleAreaTranslationOptions(TranslationOptions): ...@@ -46,7 +46,7 @@ class AccessibleAreaTranslationOptions(TranslationOptions):
@register(CertificateTemplate) @register(CertificateTemplate)
class CertificateTemplateTranslationOptions(TranslationOptions): class CertificateTemplateTranslationOptions(TranslationOptions):
fields = ('role', 'name', 'second_role', 'second_name', 'cert_logo', fields = ('role', 'name', 'signature_name', 'second_role', 'second_name', 'cert_logo',
'base_logo', 'signature', 'second_signature', 'site_logo', 'base_logo', 'signature', 'second_signature', 'site_logo',
'organization_name', 'text') '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