Commit 79d5d374 authored by Bruno Martin's avatar Bruno Martin
Browse files

implement new class based certificate

templates logic;
fix saving certificates
parent 465ba680
# 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):
def course(self):
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().certificate_template
else:
return self.course_student.get_current_class().receipt_template
@property
def get_approved_process(self):
return CertificationProcess.objects.get(course_certification=self.id,
......@@ -197,6 +208,12 @@ class CertificateTemplate(models.Model):
('certificate', _('Certificate')),
)
name = models.CharField(
_('Name'),
blank=True,
max_length=255,
null=True,
)
course = models.ForeignKey(
Course,
models.CASCADE,
......@@ -208,7 +225,7 @@ class CertificateTemplate(models.Model):
blank=True,
null=True,
)
name = models.CharField(
signature_name = models.CharField(
_('Signature Name'),
blank=True,
max_length=255,
......@@ -267,7 +284,7 @@ class CertificateTemplate(models.Model):
default=True,
)
organization_name = models.CharField(
_('Name'),
_('Organization Name'),
max_length=255,
blank=True,
null=True,
......@@ -292,7 +309,6 @@ class CertificateTemplate(models.Model):
class Meta:
verbose_name = _('Certificate Template')
unique_together = ('workspace', 'course', 'document_type')
def __str__(self):
return '({0})'.format(self.course)
......
......@@ -20,7 +20,7 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
class Meta:
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',
'organization_name', 'site_logo_url', 'signature_url', 'course',
'second_signature_url', 'second_name', 'second_role',
......@@ -48,7 +48,12 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
class CertificateTemplateCreateSerializer(serializers.ModelSerializer):
class Meta:
model = CertificateTemplate
fields = ('course', 'document_type', 'workspace')
fields = (
'name',
'course',
'document_type',
'workspace',
)
class CertificateTemplateImageSerializer(serializers.ModelSerializer):
......
......@@ -184,14 +184,12 @@ class CourseCertificationDetailView(DetailView):
workspace = certificate.course_student\
.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
if certificate:
context['cert_template'] = CertificateTemplate.objects.get(
course=certificate.course_student.course,
document_type=certificate.type,
)
context['cert_template'] = certificate.template
# Interpolate data into text string
# {Nome} : certificate.student (name)
# {CPF} : certificate.student.cpf)
......@@ -258,13 +256,9 @@ class CourseCertificationPDFView(PDFView, SingleObjectMixin):
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
if certificate:
context['cert_template'] = CertificateTemplate.objects.get(
course=certificate.course_student.course,
document_type=certificate.type,
)
context['cert_template'] = certificate.template
return context
\ No newline at end of file
......@@ -46,7 +46,7 @@ class AccessibleAreaTranslationOptions(TranslationOptions):
@register(CertificateTemplate)
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',
'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