Commit 6d25b2bc authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add new signature field for CertificateTemplate model

parent eae1e2be
# 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'),
),
]
...@@ -214,6 +214,18 @@ class CertificateTemplate(models.Model): ...@@ -214,6 +214,18 @@ class CertificateTemplate(models.Model):
max_length=255, max_length=255,
null=True, 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( cert_logo = models.ImageField(
_('Logo'), _('Logo'),
null=True, null=True,
...@@ -232,6 +244,12 @@ class CertificateTemplate(models.Model): ...@@ -232,6 +244,12 @@ class CertificateTemplate(models.Model):
blank=True, blank=True,
upload_to=hash_name('signature', 'organization_name'), 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 = models.ImageField(
_('Site Logo'), _('Site Logo'),
null=True, null=True,
...@@ -284,6 +302,12 @@ class CertificateTemplate(models.Model): ...@@ -284,6 +302,12 @@ class CertificateTemplate(models.Model):
return self.signature.url return self.signature.url
return '' return ''
@property
def second_signature_url(self):
if self.second_signature:
return self.second_signature.url
return ''
@property @property
def site_logo_url(self): def site_logo_url(self):
if self.site_logo: if self.site_logo:
......
...@@ -22,7 +22,8 @@ class CertificateTemplateSerializer(serializers.ModelSerializer): ...@@ -22,7 +22,8 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
model = CertificateTemplate model = CertificateTemplate
fields = ('id', 'text', 'base_logo_url', 'cert_logo_url', 'role', 'name', fields = ('id', 'text', 'base_logo_url', 'cert_logo_url', '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')
def get_associate(self, obj): def get_associate(self, obj):
filters = { filters = {
...@@ -52,7 +53,7 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer): ...@@ -52,7 +53,7 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CertificateTemplate model = CertificateTemplate
fields = ('base_logo', 'cert_logo', 'signature', 'site_logo') fields = ('base_logo', 'cert_logo', 'signature', 'site_logo', 'second_signature')
class CertificationProcessSerializer(serializers.ModelSerializer): class CertificationProcessSerializer(serializers.ModelSerializer):
......
...@@ -106,8 +106,8 @@ class CourseCertificationViewSet(viewsets.ModelViewSet): ...@@ -106,8 +106,8 @@ class CourseCertificationViewSet(viewsets.ModelViewSet):
class CertificateTemplateViewSet(viewsets.ModelViewSet): class CertificateTemplateViewSet(viewsets.ModelViewSet):
model = CertificateTemplate model = CertificateTemplate
queryset = CertificateTemplate.objects.all() queryset = CertificateTemplate.objects.filter(document_type='certificate')
# lookup_field = 'course' lookup_field = 'course'
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, ) permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, )
serializer_class = CertificateTemplateSerializer serializer_class = CertificateTemplateSerializer
...@@ -117,7 +117,7 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet): ...@@ -117,7 +117,7 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet):
return CertificateTemplateSerializer return CertificateTemplateSerializer
@action(detail=True, methods=['get', 'post']) @action(detail=True, methods=['get', 'post'])
def images(self, request, pk=None): def images(self, request, course=None):
obj = self.get_object() obj = self.get_object()
errors = [] errors = []
...@@ -125,6 +125,7 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet): ...@@ -125,6 +125,7 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet):
('cert_logo', request.data.get('cert_logo_clear', None)), ('cert_logo', request.data.get('cert_logo_clear', None)),
('base_logo', request.data.get('base_logo_clear', None)), ('base_logo', request.data.get('base_logo_clear', None)),
('signature', request.data.get('signature_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)), ('site_logo', request.data.get('site_logo_clear', None)),
) )
for cl in clear_logos: for cl in clear_logos:
......
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