Commit 43f604ec authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Create course certification PDF view

See merge request !72
parents aa9a225a 97ee60c9
......@@ -3,9 +3,12 @@ from rest_framework.response import Response
from rest_framework.decorators import action
from django.views.generic import DetailView
from django.views.generic.detail import SingleObjectMixin
from django.urls import resolve
from django.http import Http404
from django_renderpdf.views import PDFView
from courses.permissions import IsProfessorCoordinatorOrAdminPermissionOrReadOnly
from courses.certification.serializers import (
......@@ -246,3 +249,29 @@ class CourseCertificationDetailView(DetailView):
url_name = resolve(self.request.path_info).url_name
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
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