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
f119fbd0
Commit
f119fbd0
authored
Jul 30, 2021
by
Bruno Martin
Browse files
new certificate template admin
parent
203e6557
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
14 deletions
+71
-14
courses/certification/migrations/0008_auto_20210730_1110.py
courses/certification/migrations/0008_auto_20210730_1110.py
+43
-0
courses/certification/models.py
courses/certification/models.py
+16
-3
courses/certification/serializers.py
courses/certification/serializers.py
+11
-3
courses/certification/views.py
courses/certification/views.py
+1
-8
No files found.
courses/certification/migrations/0008_auto_20210730_1110.py
0 → 100644
View file @
f119fbd0
# 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'
),
),
]
courses/certification/models.py
View file @
f119fbd0
...
...
@@ -256,21 +256,34 @@ class CertificateTemplate(models.Model):
blank
=
True
,
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
(
_
(
'Name'
),
max_length
=
255
,
blank
=
True
,
null
=
True
,
)
text
=
models
.
TextField
(
_
(
'Content'
),
default
=
''
)
text
=
models
.
TextField
(
_
(
'Content'
),
default
=
''
,
null
=
True
,
blank
=
True
,
)
document_type
=
models
.
CharField
(
_
(
'Certificate Type'
),
choices
=
TYPES
,
max_length
=
127
,
default
=
TYPES
[
0
][
0
]
)
workspace
=
models
.
ForeignKey
(
Workspace
,
models
.
CASCADE
,
...
...
courses/certification/serializers.py
View file @
f119fbd0
...
...
@@ -16,14 +16,15 @@ class CertificateTemplateSerializer(serializers.ModelSerializer):
course_name
=
serializers
.
SerializerMethodField
(
read_only
=
True
,)
# TODO: Legacy compat field, remove in the future
contract
=
serializers
.
SerializerMethodField
()
contract
=
serializers
.
SerializerMethodField
(
read_only
=
True
)
class
Meta
:
model
=
CertificateTemplate
fields
=
(
'id'
,
'text'
,
'base_logo_url'
,
'cert_logo_url'
,
'role'
,
'name'
,
'course_name'
,
'contract'
,
'associate'
,
'workspace'
,
'document_type'
,
'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
):
filters
=
{
...
...
@@ -53,7 +54,14 @@ class CertificateTemplateImageSerializer(serializers.ModelSerializer):
class
Meta
:
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
):
...
...
courses/certification/views.py
View file @
f119fbd0
...
...
@@ -119,7 +119,7 @@ class CourseCertificationViewSet(viewsets.ModelViewSet):
class
CertificateTemplateViewSet
(
viewsets
.
ModelViewSet
):
model
=
CertificateTemplate
queryset
=
CertificateTemplate
.
objects
.
all
()
#lookup
_field = 'course'
filter
_field
s
=
(
'course'
,)
permission_classes
=
(
IsProfessorCoordinatorOrAdminPermissionOrReadOnly
,
)
serializer_class
=
CertificateTemplateSerializer
...
...
@@ -152,13 +152,6 @@ class CertificateTemplateViewSet(viewsets.ModelViewSet):
else
:
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
):
queryset
=
CertificateTemplate
.
objects
.
all
()
...
...
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