Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
79d5d374
Commit
79d5d374
authored
Aug 17, 2021
by
Bruno Martin
Browse files
implement new class based certificate
templates logic; fix saving certificates
parent
465ba680
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
17 deletions
+109
-17
courses/certification/migrations/0009_auto_20210817_0034.py
courses/certification/migrations/0009_auto_20210817_0034.py
+77
-0
courses/certification/models.py
courses/certification/models.py
+19
-3
courses/certification/serializers.py
courses/certification/serializers.py
+7
-2
courses/certification/views.py
courses/certification/views.py
+5
-11
courses/translation.py
courses/translation.py
+1
-1
No files found.
courses/certification/migrations/0009_auto_20210817_0034.py
0 → 100644
View file @
79d5d374
# 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
(),
),
]
courses/certification/models.py
View file @
79d5d374
...
...
@@ -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
)
...
...
courses/certification/serializers.py
View file @
79d5d374
...
...
@@ -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
):
...
...
courses/certification/views.py
View file @
79d5d374
...
...
@@ -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
courses/translation.py
View file @
79d5d374
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment