Commit f119fbd0 authored by Bruno Martin's avatar Bruno Martin
Browse files

new certificate template admin

parent 203e6557
# Generated by Django 2.2.24 on 2021-07-30 14:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('certification', '0007_auto_20210526_1217'),
]
operations = [
migrations.AddField(
model_name='certificatetemplate',
name='background_image',
field=models.ImageField(blank=True, null=True, upload_to='certificates_files', verbose_name='Background image'),
),
migrations.AddField(
model_name='certificatetemplate',
name='display_background_image',
field=models.BooleanField(default=True, verbose_name='Display background image'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='text',
field=models.TextField(blank=True, default='', null=True, verbose_name='Content'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='text_en',
field=models.TextField(blank=True, default='', null=True, verbose_name='Content'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='text_es',
field=models.TextField(blank=True, default='', null=True, verbose_name='Content'),
),
migrations.AlterField(
model_name='certificatetemplate',
name='text_pt_br',
field=models.TextField(blank=True, default='', null=True, verbose_name='Content'),
),
]
...@@ -256,21 +256,34 @@ class CertificateTemplate(models.Model): ...@@ -256,21 +256,34 @@ class CertificateTemplate(models.Model):
blank=True, blank=True,
upload_to='certificates_files' upload_to='certificates_files'
) )
background_image = models.ImageField(
_('Background image'),
null=True,
blank=True,
upload_to='certificates_files'
)
display_background_image = models.BooleanField(
_('Display background image'),
default=True,
)
organization_name = models.CharField( organization_name = models.CharField(
_('Name'), _('Name'),
max_length=255, max_length=255,
blank=True, blank=True,
null=True, null=True,
) )
text = models.TextField(_('Content'), default='') text = models.TextField(
_('Content'),
default='',
null=True,
blank=True,
)
document_type = models.CharField( document_type = models.CharField(
_('Certificate Type'), _('Certificate Type'),
choices=TYPES, choices=TYPES,
max_length=127, max_length=127,
default=TYPES[0][0] default=TYPES[0][0]
) )
workspace = models.ForeignKey( workspace = models.ForeignKey(
Workspace, Workspace,
models.CASCADE, models.CASCADE,
......
...@@ -16,14 +16,15 @@ class CertificateTemplateSerializer(serializers.ModelSerializer): ...@@ -16,14 +16,15 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
course_name = serializers.SerializerMethodField(read_only=True,) course_name = serializers.SerializerMethodField(read_only=True,)
# TODO: Legacy compat field, remove in the future # TODO: Legacy compat field, remove in the future
contract = serializers.SerializerMethodField() contract = serializers.SerializerMethodField(read_only=True)
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', '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',
'display_background_image',)
def get_associate(self, obj): def get_associate(self, obj):
filters = { filters = {
...@@ -53,7 +54,14 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer): ...@@ -53,7 +54,14 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CertificateTemplate model = CertificateTemplate
fields = ('base_logo', 'cert_logo', 'signature', 'site_logo', 'second_signature') fields = (
'base_logo',
'cert_logo',
'signature',
'site_logo',
'second_signature',
'background_image',
)
class CertificationProcessSerializer(serializers.ModelSerializer): class CertificationProcessSerializer(serializers.ModelSerializer):
......
...@@ -119,7 +119,7 @@ class CourseCertificationViewSet(viewsets.ModelViewSet): ...@@ -119,7 +119,7 @@ class CourseCertificationViewSet(viewsets.ModelViewSet):
class CertificateTemplateViewSet(viewsets.ModelViewSet): class CertificateTemplateViewSet(viewsets.ModelViewSet):
model = CertificateTemplate model = CertificateTemplate
queryset = CertificateTemplate.objects.all() queryset = CertificateTemplate.objects.all()
#lookup_field = 'course' filter_fields = ('course',)
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, ) permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, )
serializer_class = CertificateTemplateSerializer serializer_class = CertificateTemplateSerializer
...@@ -152,13 +152,6 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet): ...@@ -152,13 +152,6 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet):
else: else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
class CertificateTemplateImageViewSet(viewsets.ModelViewSet): class CertificateTemplateImageViewSet(viewsets.ModelViewSet):
queryset = CertificateTemplate.objects.all() queryset = CertificateTemplate.objects.all()
......
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