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
9dc2f0ab
Commit
9dc2f0ab
authored
Jul 01, 2020
by
Virgilio Santos
Browse files
certificate: change certificate generation workflow
parent
bb78c335
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
4 deletions
+41
-4
courses/certification/apps.py
courses/certification/apps.py
+3
-0
courses/certification/migrations/0003_auto_20200630_2323.py
courses/certification/migrations/0003_auto_20200630_2323.py
+19
-0
courses/certification/models.py
courses/certification/models.py
+1
-0
courses/certification/serializers.py
courses/certification/serializers.py
+3
-1
courses/certification/signals.py
courses/certification/signals.py
+15
-3
No files found.
courses/certification/apps.py
View file @
9dc2f0ab
...
...
@@ -3,3 +3,6 @@ from django.apps import AppConfig
class
CoursesCertificationConfig
(
AppConfig
):
name
=
'courses.certification'
def
ready
(
self
):
import
courses.certification.signals
\ No newline at end of file
courses/certification/migrations/0003_auto_20200630_2323.py
0 → 100644
View file @
9dc2f0ab
# Generated by Django 2.2.13 on 2020-07-01 02:23
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'certification'
,
'0002_certificatedata'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'certificatedata'
,
name
=
'workspace'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'courses.Workspace'
),
),
]
courses/certification/models.py
View file @
9dc2f0ab
...
...
@@ -287,6 +287,7 @@ class CertificateData(models.Model):
workspace
=
models
.
ForeignKey
(
Workspace
,
models
.
CASCADE
,
null
=
True
)
certificate_template
=
models
.
ForeignKey
(
CertificateTemplate
,
...
...
courses/certification/serializers.py
View file @
9dc2f0ab
...
...
@@ -58,7 +58,9 @@ class CertificateDataSerializer(serializers.ModelSerializer):
return
None
def
get_contract
(
self
,
obj
):
return
SimpleWorkspaceSerializer
(
obj
.
workspace
).
data
if
obj
.
workspace
:
return
SimpleWorkspaceSerializer
(
obj
.
workspace
).
data
return
None
def
update
(
self
,
instance
,
validated_data
):
ct
=
dict
(
validated_data
.
pop
(
'certificate_template'
))
...
...
courses/certification/signals.py
View file @
9dc2f0ab
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
base64
import
urlsafe_b64encode
as
ub64
from
hashlib
import
sha1
from
time
import
time
from
courses.models
import
CourseStudent
from
courses.certification.models
import
CourseCertification
from
courses.models
import
Course
,
CourseStudent
from
courses.certification.models
import
CourseCertification
,
CertificateTemplate
,
CertificateData
@
receiver
(
post_save
,
sender
=
CourseStudent
)
...
...
@@ -17,4 +18,15 @@ def course_student_created_or_updated(sender, created, instance, **kwargs):
course
=
instance
.
course
,
type
=
CourseCertification
.
TYPES
[
0
][
0
],
is_valid
=
True
,
link_hash
=
link_hash
.
decode
())
receipt
.
save
()
\ No newline at end of file
receipt
.
save
()
@
receiver
(
post_save
,
sender
=
Course
)
def
course_created
(
sender
,
created
,
instance
,
**
kwargs
):
if
created
:
for
type_
in
CertificateData
.
TYPES
:
ct
=
CertificateTemplate
(
course
=
instance
)
ct
.
save
()
cd
=
CertificateData
(
type
=
type_
[
0
],
certificate_template
=
ct
)
cd
.
save
()
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