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
97ee60c9
Commit
97ee60c9
authored
Jul 21, 2021
by
Bruno Martin
Browse files
Create course certification PDF view
parent
219a8ae5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
courses/certification/views.py
courses/certification/views.py
+29
-0
No files found.
courses/certification/views.py
View file @
97ee60c9
...
@@ -3,9 +3,12 @@ from rest_framework.response import Response
...
@@ -3,9 +3,12 @@ from rest_framework.response import Response
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
from
django.views.generic
import
DetailView
from
django.views.generic
import
DetailView
from
django.views.generic.detail
import
SingleObjectMixin
from
django.urls
import
resolve
from
django.urls
import
resolve
from
django.http
import
Http404
from
django.http
import
Http404
from
django_renderpdf.views
import
PDFView
from
courses.permissions
import
IsProfessorCoordinatorOrAdminPermissionOrReadOnly
from
courses.permissions
import
IsProfessorCoordinatorOrAdminPermissionOrReadOnly
from
courses.certification.serializers
import
(
from
courses.certification.serializers
import
(
...
@@ -246,3 +249,29 @@ class CourseCertificationDetailView(DetailView):
...
@@ -246,3 +249,29 @@ class CourseCertificationDetailView(DetailView):
url_name
=
resolve
(
self
.
request
.
path_info
).
url_name
url_name
=
resolve
(
self
.
request
.
path_info
).
url_name
return
super
().
render_to_response
(
context
,
**
response_kwargs
)
return
super
().
render_to_response
(
context
,
**
response_kwargs
)
class
CourseCertificationPDFView
(
PDFView
,
SingleObjectMixin
):
model
=
CourseCertification
template_name
=
'certificate.html'
slug_field
=
"link_hash"
serializer_class
=
CourseCertificationSerializer
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
"""Pass some extra context to the template."""
self
.
object
=
self
.
get_object
()
context
=
super
().
get_context_data
(
*
args
,
**
kwargs
)
certificate
=
self
.
object
if
not
certificate
.
course_student
.
can_emmit_receipt
():
raise
Http404
if
certificate
:
context
[
'cert_template'
]
=
CertificateTemplate
.
objects
.
get
(
course
=
certificate
.
course_student
.
course
,
document_type
=
certificate
.
type
,
)
return
context
\ No newline at end of file
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