We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Certificate URL needs to include domain
See the url below - it is not useful since it does not specify a domain.

<img width="1285" alt="screen shot 2017-07-24 at 10 52 15 pm" src="https://user-images.githubusercontent.com/178003/28544268-e2f26940-70c2-11e7-8d08-d4c39b466600.png">


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `django_project/certification/views/certificate.py`
Content:
```
1 # coding=utf-8
2 from django.http import Http404, HttpResponse
3 from django.views.generic import CreateView, DetailView
4 from django.core.urlresolvers import reverse
5 from braces.views import LoginRequiredMixin
6 from reportlab.pdfgen import canvas
7 from reportlab.lib.pagesizes import A4, landscape
8 from reportlab.lib.utils import ImageReader
9 from ..models import Certificate, Course, Attendee
10 from ..forms import CertificateForm
11 from base.models.project import Project
12 
13 
14 class CertificateMixin(object):
15     """Mixin class to provide standard settings for Certificate."""
16 
17     model = Certificate
18     form_class = CertificateForm
19 
20 
21 class CertificateCreateView(
22         LoginRequiredMixin, CertificateMixin, CreateView):
23     """Create view for Certificate."""
24 
25     context_object_name = 'certificate'
26     template_name = 'certificate/create.html'
27 
28     def get_success_url(self):
29         """Define the redirect URL.
30 
31         After successful creation of the object, the User will be redirected
32         to the Course detail page.
33 
34        :returns: URL
35        :rtype: HttpResponse
36        """
37 
38         return reverse('course-detail', kwargs={
39             'project_slug': self.project_slug,
40             'organisation_slug': self.organisation_slug,
41             'slug': self.course_slug
42         })
43 
44     def get_context_data(self, **kwargs):
45         """Get the context data which is passed to a template.
46 
47         :param kwargs: Any arguments to pass to the superclass.
48         :type kwargs: dict
49 
50         :returns: Context data which will be passed to the template.
51         :rtype: dict
52         """
53 
54         context = super(
55             CertificateCreateView, self).get_context_data(**kwargs)
56         context['course'] = Course.objects.get(slug=self.course_slug)
57         context['attendee'] = Attendee.objects.get(pk=self.pk)
58         return context
59 
60     def get_form_kwargs(self):
61         """Get keyword arguments from form.
62 
63         :returns keyword argument from the form
64         :rtype: dict
65         """
66 
67         kwargs = super(CertificateCreateView, self).get_form_kwargs()
68         self.project_slug = self.kwargs.get('project_slug', None)
69         self.organisation_slug = self.kwargs.get('organisation_slug', None)
70         self.course_slug = self.kwargs.get('course_slug', None)
71         self.pk = self.kwargs.get('pk', None)
72         self.course = Course.objects.get(slug=self.course_slug)
73         self.attendee = Attendee.objects.get(pk=self.pk)
74         kwargs.update({
75             'user': self.request.user,
76             'course': self.course,
77             'attendee': self.attendee,
78         })
79         return kwargs
80 
81 
82 class CertificateDetailView(DetailView):
83     """Detail view for Certificate."""
84 
85     model = Certificate
86     context_object_name = 'certificate'
87     template_name = 'certificate/detail.html'
88 
89     def get_context_data(self, **kwargs):
90         """Get the context data which is passed to a template.
91 
92         :param kwargs: Any arguments to pass to the superclass.
93         :type kwargs: dict
94 
95         :returns: Context data which will be passed to the template.
96         :rtype: dict
97         """
98 
99         self.certificateID = self.kwargs.get('id', None)
100         self.project_slug = self.kwargs.get('project_slug', None)
101         context = super(
102             CertificateDetailView, self).get_context_data(**kwargs)
103         issued_id = \
104             Certificate.objects.all().values_list('certificateID', flat=True)
105         if self.certificateID in issued_id:
106             context['certificate'] = \
107                 Certificate.objects.get(certificateID=self.certificateID)
108         context['project_slug'] = self.project_slug
109         return context
110 
111     def get_queryset(self):
112         """Get the queryset for this view.
113 
114         :returns: Queryset which is all certificate in the
115             corresponding organisation.
116         :rtype: QuerySet
117         """
118 
119         qs = Certificate.objects.all()
120         return qs
121 
122     def get_object(self, queryset=None):
123         """Get the object for this view.
124 
125         :param queryset: A query set
126         :type queryset: QuerySet
127 
128         :returns: Queryset which is filtered to only show a certificate
129             depends on the input certificate ID.
130         :rtype: QuerySet
131         :raises: Http404
132         """
133 
134         if queryset is None:
135             queryset = self.get_queryset()
136             certificateID = self.kwargs.get('id', None)
137             if certificateID:
138                 try:
139                     obj = queryset.get(certificateID=certificateID)
140                     return obj
141                 except Certificate.DoesNotExist:
142                     return None
143             else:
144                 raise Http404('Sorry! Certificate by this ID is not exist.')
145 
146 
147 def certificate_pdf_view(request, **kwargs):
148 
149     project_slug = kwargs.pop('project_slug')
150     course_slug = kwargs.pop('course_slug')
151     pk = kwargs.pop('pk')
152     project = Project.objects.get(slug=project_slug)
153     course = Course.objects.get(slug=course_slug)
154     attendee = Attendee.objects.get(pk=pk)
155     certificate = Certificate.objects.get(course=course, attendee=attendee)
156 
157     # Create the HttpResponse object with the appropriate PDF headers.
158     response = HttpResponse(content_type='application/pdf')
159     response['Content-Disposition'] = 'filename="certificate.pdf"'
160 
161     # Create the PDF object, using the response object as its "file."
162     page = canvas.Canvas(response, pagesize=landscape(A4))
163     width, height = A4
164     center = height * 0.5
165 
166     if project.image_file:
167         project_logo = ImageReader(project.image_file)
168     else:
169         project_logo = None
170 
171     if course.certifying_organisation.logo:
172         organisation_logo = ImageReader(course.certifying_organisation.logo)
173     else:
174         organisation_logo = None
175 
176     if project.signature:
177         project_owner_signature = ImageReader(project.signature)
178     else:
179         project_owner_signature = None
180 
181     if course.course_convener.signature:
182         convener_signature = ImageReader(course.course_convener.signature)
183     else:
184         convener_signature = None
185 
186     if course.template_certificate:
187         background = ImageReader(course.template_certificate)
188     else:
189         background = None
190 
191     # Certificate margin.
192     margin_right = height - 50
193     margin_left = 50
194     margin_bottom = 50
195     max_left = margin_right - 50
196 
197     # Draw things on the PDF. Here's where the PDF generation happens.
198     # See the ReportLab documentation for the full list of functionality.
199     if background is not None:
200         page.drawImage(
201             background, 0, 0, height=width, width=height,
202             preserveAspectRatio=True, mask='auto')
203     page.setFillColorRGB(0.1, 0.1, 0.1)
204     page.setFont('Times-Roman', 18)
205     # page.drawString(margin_left, 480, project.name)
206     # page.drawRightString(
207     #     (margin_right), 480, course.certifying_organisation.name)
208 
209     if project_logo is not None:
210         page.drawImage(
211             project_logo, 50, 500, width=50, height=50,
212             preserveAspectRatio=True, mask='auto')
213 
214     if organisation_logo is not None:
215         page.drawImage(
216             organisation_logo, max_left, 500, height=50, width=50,
217             preserveAspectRatio=True, anchor='c', mask='auto')
218 
219     page.setFont('Times-Bold', 26)
220     page.drawCentredString(center, 480, 'Certificate of Completion')
221     page.drawCentredString(
222         center, 400, '%s %s' % (attendee.firstname, attendee.surname))
223     page.setFont('Times-Roman', 16)
224     page.drawCentredString(
225         center, 360, 'Has attended and completed the course:')
226     page.setFont('Times-Bold', 20)
227     page.drawCentredString(center, 300, course.course_type.name)
228     page.setFont('Times-Roman', 16)
229     page.drawCentredString(
230         center, 270,
231         'From %s %s %s to %s %s %s'
232         % (course.start_date.day, course.start_date.strftime('%B'),
233            course.start_date.year, course.end_date.day,
234            course.end_date.strftime('%B'), course.end_date.year))
235     page.setFillColorRGB(0.1, 0.1, 0.1)
236     page.drawCentredString(
237         center, 220, 'Convened by %s %s at %s' % (
238             course.course_convener.user.first_name,
239             course.course_convener.user.last_name, course.training_center))
240 
241     if project_owner_signature is not None:
242         page.drawImage(
243             project_owner_signature,
244             (margin_left + 100), (margin_bottom + 70), width=100, height=70,
245             preserveAspectRatio=True, anchor='s', mask='auto')
246 
247     if convener_signature is not None:
248         page.drawImage(
249             convener_signature, (margin_right - 200), (margin_bottom + 70),
250             width=100, height=70, preserveAspectRatio=True, anchor='s',
251             mask='auto')
252 
253     page.setFont('Times-Italic', 12)
254     page.drawCentredString(
255         (margin_left + 150), (margin_bottom + 60),
256         '%s %s' % (project.owner.first_name, project.owner.last_name))
257     page.drawCentredString(
258         (margin_right - 150), (margin_bottom + 60),
259         '%s %s' % (
260             course.course_convener.user.first_name,
261             course.course_convener.user.last_name))
262     page.line(
263         (margin_left + 70), (margin_bottom + 55),
264         (margin_left + 230), (margin_bottom + 55))
265     page.line(
266         (margin_right - 70), (margin_bottom + 55),
267         (margin_right - 230), (margin_bottom + 55))
268     page.setFont('Times-Roman', 13)
269     page.drawCentredString(
270         (margin_left + 150), (margin_bottom + 40), 'Project Owner')
271     page.drawCentredString(
272         (margin_right - 150), (margin_bottom + 40), 'Convener')
273 
274     # Footnotes.
275     page.setFont('Times-Roman', 14)
276     page.drawString(
277         margin_left, margin_bottom - 10, 'ID: %s' % certificate.certificateID)
278     page.setFont('Times-Roman', 8)
279     page.drawString(
280         margin_left, (margin_bottom - 20),
281         'You can verify this certificate by visiting /%s/certificate/%s/.'
282         % (project.slug, certificate.certificateID))
283 
284     # Close the PDF object cleanly.
285     page.showPage()
286     page.save()
287     return response
288
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -153,6 +153,7 @@
     course = Course.objects.get(slug=course_slug)
     attendee = Attendee.objects.get(pk=pk)
     certificate = Certificate.objects.get(course=course, attendee=attendee)
+    current_site = request.META['HTTP_HOST']
 
     # Create the HttpResponse object with the appropriate PDF headers.
     response = HttpResponse(content_type='application/pdf')
@@ -278,8 +279,9 @@
     page.setFont('Times-Roman', 8)
     page.drawString(
         margin_left, (margin_bottom - 20),
-        'You can verify this certificate by visiting /%s/certificate/%s/.'
-        % (project.slug, certificate.certificateID))
+        'You can verify this certificate by visiting '
+        'http://%s/en/%s/certificate/%s/.'
+        % (current_site, project.slug, certificate.certificateID))
 
     # Close the PDF object cleanly.
     page.showPage()

{"golden_diff": "diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py\n--- a/django_project/certification/views/certificate.py\n+++ b/django_project/certification/views/certificate.py\n@@ -153,6 +153,7 @@\n     course = Course.objects.get(slug=course_slug)\n     attendee = Attendee.objects.get(pk=pk)\n     certificate = Certificate.objects.get(course=course, attendee=attendee)\n+    current_site = request.META['HTTP_HOST']\n \n     # Create the HttpResponse object with the appropriate PDF headers.\n     response = HttpResponse(content_type='application/pdf')\n@@ -278,8 +279,9 @@\n     page.setFont('Times-Roman', 8)\n     page.drawString(\n         margin_left, (margin_bottom - 20),\n-        'You can verify this certificate by visiting /%s/certificate/%s/.'\n-        % (project.slug, certificate.certificateID))\n+        'You can verify this certificate by visiting '\n+        'http://%s/en/%s/certificate/%s/.'\n+        % (current_site, project.slug, certificate.certificateID))\n \n     # Close the PDF object cleanly.\n     page.showPage()\n", "issue": "Certificate URL needs to include domain\nSee the url below - it is not useful since it does not specify a domain.\r\n\r\n<img width=\"1285\" alt=\"screen shot 2017-07-24 at 10 52 15 pm\" src=\"https://user-images.githubusercontent.com/178003/28544268-e2f26940-70c2-11e7-8d08-d4c39b466600.png\">\r\n\n", "before_files": [{"content": "# coding=utf-8\nfrom django.http import Http404, HttpResponse\nfrom django.views.generic import CreateView, DetailView\nfrom django.core.urlresolvers import reverse\nfrom braces.views import LoginRequiredMixin\nfrom reportlab.pdfgen import canvas\nfrom reportlab.lib.pagesizes import A4, landscape\nfrom reportlab.lib.utils import ImageReader\nfrom ..models import Certificate, Course, Attendee\nfrom ..forms import CertificateForm\nfrom base.models.project import Project\n\n\nclass CertificateMixin(object):\n    \"\"\"Mixin class to provide standard settings for Certificate.\"\"\"\n\n    model = Certificate\n    form_class = CertificateForm\n\n\nclass CertificateCreateView(\n        LoginRequiredMixin, CertificateMixin, CreateView):\n    \"\"\"Create view for Certificate.\"\"\"\n\n    context_object_name = 'certificate'\n    template_name = 'certificate/create.html'\n\n    def get_success_url(self):\n        \"\"\"Define the redirect URL.\n\n        After successful creation of the object, the User will be redirected\n        to the Course detail page.\n\n       :returns: URL\n       :rtype: HttpResponse\n       \"\"\"\n\n        return reverse('course-detail', kwargs={\n            'project_slug': self.project_slug,\n            'organisation_slug': self.organisation_slug,\n            'slug': self.course_slug\n        })\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Get the context data which is passed to a template.\n\n        :param kwargs: Any arguments to pass to the superclass.\n        :type kwargs: dict\n\n        :returns: Context data which will be passed to the template.\n        :rtype: dict\n        \"\"\"\n\n        context = super(\n            CertificateCreateView, self).get_context_data(**kwargs)\n        context['course'] = Course.objects.get(slug=self.course_slug)\n        context['attendee'] = Attendee.objects.get(pk=self.pk)\n        return context\n\n    def get_form_kwargs(self):\n        \"\"\"Get keyword arguments from form.\n\n        :returns keyword argument from the form\n        :rtype: dict\n        \"\"\"\n\n        kwargs = super(CertificateCreateView, self).get_form_kwargs()\n        self.project_slug = self.kwargs.get('project_slug', None)\n        self.organisation_slug = self.kwargs.get('organisation_slug', None)\n        self.course_slug = self.kwargs.get('course_slug', None)\n        self.pk = self.kwargs.get('pk', None)\n        self.course = Course.objects.get(slug=self.course_slug)\n        self.attendee = Attendee.objects.get(pk=self.pk)\n        kwargs.update({\n            'user': self.request.user,\n            'course': self.course,\n            'attendee': self.attendee,\n        })\n        return kwargs\n\n\nclass CertificateDetailView(DetailView):\n    \"\"\"Detail view for Certificate.\"\"\"\n\n    model = Certificate\n    context_object_name = 'certificate'\n    template_name = 'certificate/detail.html'\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Get the context data which is passed to a template.\n\n        :param kwargs: Any arguments to pass to the superclass.\n        :type kwargs: dict\n\n        :returns: Context data which will be passed to the template.\n        :rtype: dict\n        \"\"\"\n\n        self.certificateID = self.kwargs.get('id', None)\n        self.project_slug = self.kwargs.get('project_slug', None)\n        context = super(\n            CertificateDetailView, self).get_context_data(**kwargs)\n        issued_id = \\\n            Certificate.objects.all().values_list('certificateID', flat=True)\n        if self.certificateID in issued_id:\n            context['certificate'] = \\\n                Certificate.objects.get(certificateID=self.certificateID)\n        context['project_slug'] = self.project_slug\n        return context\n\n    def get_queryset(self):\n        \"\"\"Get the queryset for this view.\n\n        :returns: Queryset which is all certificate in the\n            corresponding organisation.\n        :rtype: QuerySet\n        \"\"\"\n\n        qs = Certificate.objects.all()\n        return qs\n\n    def get_object(self, queryset=None):\n        \"\"\"Get the object for this view.\n\n        :param queryset: A query set\n        :type queryset: QuerySet\n\n        :returns: Queryset which is filtered to only show a certificate\n            depends on the input certificate ID.\n        :rtype: QuerySet\n        :raises: Http404\n        \"\"\"\n\n        if queryset is None:\n            queryset = self.get_queryset()\n            certificateID = self.kwargs.get('id', None)\n            if certificateID:\n                try:\n                    obj = queryset.get(certificateID=certificateID)\n                    return obj\n                except Certificate.DoesNotExist:\n                    return None\n            else:\n                raise Http404('Sorry! Certificate by this ID is not exist.')\n\n\ndef certificate_pdf_view(request, **kwargs):\n\n    project_slug = kwargs.pop('project_slug')\n    course_slug = kwargs.pop('course_slug')\n    pk = kwargs.pop('pk')\n    project = Project.objects.get(slug=project_slug)\n    course = Course.objects.get(slug=course_slug)\n    attendee = Attendee.objects.get(pk=pk)\n    certificate = Certificate.objects.get(course=course, attendee=attendee)\n\n    # Create the HttpResponse object with the appropriate PDF headers.\n    response = HttpResponse(content_type='application/pdf')\n    response['Content-Disposition'] = 'filename=\"certificate.pdf\"'\n\n    # Create the PDF object, using the response object as its \"file.\"\n    page = canvas.Canvas(response, pagesize=landscape(A4))\n    width, height = A4\n    center = height * 0.5\n\n    if project.image_file:\n        project_logo = ImageReader(project.image_file)\n    else:\n        project_logo = None\n\n    if course.certifying_organisation.logo:\n        organisation_logo = ImageReader(course.certifying_organisation.logo)\n    else:\n        organisation_logo = None\n\n    if project.signature:\n        project_owner_signature = ImageReader(project.signature)\n    else:\n        project_owner_signature = None\n\n    if course.course_convener.signature:\n        convener_signature = ImageReader(course.course_convener.signature)\n    else:\n        convener_signature = None\n\n    if course.template_certificate:\n        background = ImageReader(course.template_certificate)\n    else:\n        background = None\n\n    # Certificate margin.\n    margin_right = height - 50\n    margin_left = 50\n    margin_bottom = 50\n    max_left = margin_right - 50\n\n    # Draw things on the PDF. Here's where the PDF generation happens.\n    # See the ReportLab documentation for the full list of functionality.\n    if background is not None:\n        page.drawImage(\n            background, 0, 0, height=width, width=height,\n            preserveAspectRatio=True, mask='auto')\n    page.setFillColorRGB(0.1, 0.1, 0.1)\n    page.setFont('Times-Roman', 18)\n    # page.drawString(margin_left, 480, project.name)\n    # page.drawRightString(\n    #     (margin_right), 480, course.certifying_organisation.name)\n\n    if project_logo is not None:\n        page.drawImage(\n            project_logo, 50, 500, width=50, height=50,\n            preserveAspectRatio=True, mask='auto')\n\n    if organisation_logo is not None:\n        page.drawImage(\n            organisation_logo, max_left, 500, height=50, width=50,\n            preserveAspectRatio=True, anchor='c', mask='auto')\n\n    page.setFont('Times-Bold', 26)\n    page.drawCentredString(center, 480, 'Certificate of Completion')\n    page.drawCentredString(\n        center, 400, '%s %s' % (attendee.firstname, attendee.surname))\n    page.setFont('Times-Roman', 16)\n    page.drawCentredString(\n        center, 360, 'Has attended and completed the course:')\n    page.setFont('Times-Bold', 20)\n    page.drawCentredString(center, 300, course.course_type.name)\n    page.setFont('Times-Roman', 16)\n    page.drawCentredString(\n        center, 270,\n        'From %s %s %s to %s %s %s'\n        % (course.start_date.day, course.start_date.strftime('%B'),\n           course.start_date.year, course.end_date.day,\n           course.end_date.strftime('%B'), course.end_date.year))\n    page.setFillColorRGB(0.1, 0.1, 0.1)\n    page.drawCentredString(\n        center, 220, 'Convened by %s %s at %s' % (\n            course.course_convener.user.first_name,\n            course.course_convener.user.last_name, course.training_center))\n\n    if project_owner_signature is not None:\n        page.drawImage(\n            project_owner_signature,\n            (margin_left + 100), (margin_bottom + 70), width=100, height=70,\n            preserveAspectRatio=True, anchor='s', mask='auto')\n\n    if convener_signature is not None:\n        page.drawImage(\n            convener_signature, (margin_right - 200), (margin_bottom + 70),\n            width=100, height=70, preserveAspectRatio=True, anchor='s',\n            mask='auto')\n\n    page.setFont('Times-Italic', 12)\n    page.drawCentredString(\n        (margin_left + 150), (margin_bottom + 60),\n        '%s %s' % (project.owner.first_name, project.owner.last_name))\n    page.drawCentredString(\n        (margin_right - 150), (margin_bottom + 60),\n        '%s %s' % (\n            course.course_convener.user.first_name,\n            course.course_convener.user.last_name))\n    page.line(\n        (margin_left + 70), (margin_bottom + 55),\n        (margin_left + 230), (margin_bottom + 55))\n    page.line(\n        (margin_right - 70), (margin_bottom + 55),\n        (margin_right - 230), (margin_bottom + 55))\n    page.setFont('Times-Roman', 13)\n    page.drawCentredString(\n        (margin_left + 150), (margin_bottom + 40), 'Project Owner')\n    page.drawCentredString(\n        (margin_right - 150), (margin_bottom + 40), 'Convener')\n\n    # Footnotes.\n    page.setFont('Times-Roman', 14)\n    page.drawString(\n        margin_left, margin_bottom - 10, 'ID: %s' % certificate.certificateID)\n    page.setFont('Times-Roman', 8)\n    page.drawString(\n        margin_left, (margin_bottom - 20),\n        'You can verify this certificate by visiting /%s/certificate/%s/.'\n        % (project.slug, certificate.certificateID))\n\n    # Close the PDF object cleanly.\n    page.showPage()\n    page.save()\n    return response\n", "path": "django_project/certification/views/certificate.py"}], "after_files": [{"content": "# coding=utf-8\nfrom django.http import Http404, HttpResponse\nfrom django.views.generic import CreateView, DetailView\nfrom django.core.urlresolvers import reverse\nfrom braces.views import LoginRequiredMixin\nfrom reportlab.pdfgen import canvas\nfrom reportlab.lib.pagesizes import A4, landscape\nfrom reportlab.lib.utils import ImageReader\nfrom ..models import Certificate, Course, Attendee\nfrom ..forms import CertificateForm\nfrom base.models.project import Project\n\n\nclass CertificateMixin(object):\n    \"\"\"Mixin class to provide standard settings for Certificate.\"\"\"\n\n    model = Certificate\n    form_class = CertificateForm\n\n\nclass CertificateCreateView(\n        LoginRequiredMixin, CertificateMixin, CreateView):\n    \"\"\"Create view for Certificate.\"\"\"\n\n    context_object_name = 'certificate'\n    template_name = 'certificate/create.html'\n\n    def get_success_url(self):\n        \"\"\"Define the redirect URL.\n\n        After successful creation of the object, the User will be redirected\n        to the Course detail page.\n\n       :returns: URL\n       :rtype: HttpResponse\n       \"\"\"\n\n        return reverse('course-detail', kwargs={\n            'project_slug': self.project_slug,\n            'organisation_slug': self.organisation_slug,\n            'slug': self.course_slug\n        })\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Get the context data which is passed to a template.\n\n        :param kwargs: Any arguments to pass to the superclass.\n        :type kwargs: dict\n\n        :returns: Context data which will be passed to the template.\n        :rtype: dict\n        \"\"\"\n\n        context = super(\n            CertificateCreateView, self).get_context_data(**kwargs)\n        context['course'] = Course.objects.get(slug=self.course_slug)\n        context['attendee'] = Attendee.objects.get(pk=self.pk)\n        return context\n\n    def get_form_kwargs(self):\n        \"\"\"Get keyword arguments from form.\n\n        :returns keyword argument from the form\n        :rtype: dict\n        \"\"\"\n\n        kwargs = super(CertificateCreateView, self).get_form_kwargs()\n        self.project_slug = self.kwargs.get('project_slug', None)\n        self.organisation_slug = self.kwargs.get('organisation_slug', None)\n        self.course_slug = self.kwargs.get('course_slug', None)\n        self.pk = self.kwargs.get('pk', None)\n        self.course = Course.objects.get(slug=self.course_slug)\n        self.attendee = Attendee.objects.get(pk=self.pk)\n        kwargs.update({\n            'user': self.request.user,\n            'course': self.course,\n            'attendee': self.attendee,\n        })\n        return kwargs\n\n\nclass CertificateDetailView(DetailView):\n    \"\"\"Detail view for Certificate.\"\"\"\n\n    model = Certificate\n    context_object_name = 'certificate'\n    template_name = 'certificate/detail.html'\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Get the context data which is passed to a template.\n\n        :param kwargs: Any arguments to pass to the superclass.\n        :type kwargs: dict\n\n        :returns: Context data which will be passed to the template.\n        :rtype: dict\n        \"\"\"\n\n        self.certificateID = self.kwargs.get('id', None)\n        self.project_slug = self.kwargs.get('project_slug', None)\n        context = super(\n            CertificateDetailView, self).get_context_data(**kwargs)\n        issued_id = \\\n            Certificate.objects.all().values_list('certificateID', flat=True)\n        if self.certificateID in issued_id:\n            context['certificate'] = \\\n                Certificate.objects.get(certificateID=self.certificateID)\n        context['project_slug'] = self.project_slug\n        return context\n\n    def get_queryset(self):\n        \"\"\"Get the queryset for this view.\n\n        :returns: Queryset which is all certificate in the\n            corresponding organisation.\n        :rtype: QuerySet\n        \"\"\"\n\n        qs = Certificate.objects.all()\n        return qs\n\n    def get_object(self, queryset=None):\n        \"\"\"Get the object for this view.\n\n        :param queryset: A query set\n        :type queryset: QuerySet\n\n        :returns: Queryset which is filtered to only show a certificate\n            depends on the input certificate ID.\n        :rtype: QuerySet\n        :raises: Http404\n        \"\"\"\n\n        if queryset is None:\n            queryset = self.get_queryset()\n            certificateID = self.kwargs.get('id', None)\n            if certificateID:\n                try:\n                    obj = queryset.get(certificateID=certificateID)\n                    return obj\n                except Certificate.DoesNotExist:\n                    return None\n            else:\n                raise Http404('Sorry! Certificate by this ID is not exist.')\n\n\ndef certificate_pdf_view(request, **kwargs):\n\n    project_slug = kwargs.pop('project_slug')\n    course_slug = kwargs.pop('course_slug')\n    pk = kwargs.pop('pk')\n    project = Project.objects.get(slug=project_slug)\n    course = Course.objects.get(slug=course_slug)\n    attendee = Attendee.objects.get(pk=pk)\n    certificate = Certificate.objects.get(course=course, attendee=attendee)\n    current_site = request.META['HTTP_HOST']\n\n    # Create the HttpResponse object with the appropriate PDF headers.\n    response = HttpResponse(content_type='application/pdf')\n    response['Content-Disposition'] = 'filename=\"certificate.pdf\"'\n\n    # Create the PDF object, using the response object as its \"file.\"\n    page = canvas.Canvas(response, pagesize=landscape(A4))\n    width, height = A4\n    center = height * 0.5\n\n    if project.image_file:\n        project_logo = ImageReader(project.image_file)\n    else:\n        project_logo = None\n\n    if course.certifying_organisation.logo:\n        organisation_logo = ImageReader(course.certifying_organisation.logo)\n    else:\n        organisation_logo = None\n\n    if project.signature:\n        project_owner_signature = ImageReader(project.signature)\n    else:\n        project_owner_signature = None\n\n    if course.course_convener.signature:\n        convener_signature = ImageReader(course.course_convener.signature)\n    else:\n        convener_signature = None\n\n    if course.template_certificate:\n        background = ImageReader(course.template_certificate)\n    else:\n        background = None\n\n    # Certificate margin.\n    margin_right = height - 50\n    margin_left = 50\n    margin_bottom = 50\n    max_left = margin_right - 50\n\n    # Draw things on the PDF. Here's where the PDF generation happens.\n    # See the ReportLab documentation for the full list of functionality.\n    if background is not None:\n        page.drawImage(\n            background, 0, 0, height=width, width=height,\n            preserveAspectRatio=True, mask='auto')\n    page.setFillColorRGB(0.1, 0.1, 0.1)\n    page.setFont('Times-Roman', 18)\n    # page.drawString(margin_left, 480, project.name)\n    # page.drawRightString(\n    #     (margin_right), 480, course.certifying_organisation.name)\n\n    if project_logo is not None:\n        page.drawImage(\n            project_logo, 50, 500, width=50, height=50,\n            preserveAspectRatio=True, mask='auto')\n\n    if organisation_logo is not None:\n        page.drawImage(\n            organisation_logo, max_left, 500, height=50, width=50,\n            preserveAspectRatio=True, anchor='c', mask='auto')\n\n    page.setFont('Times-Bold', 26)\n    page.drawCentredString(center, 480, 'Certificate of Completion')\n    page.drawCentredString(\n        center, 400, '%s %s' % (attendee.firstname, attendee.surname))\n    page.setFont('Times-Roman', 16)\n    page.drawCentredString(\n        center, 360, 'Has attended and completed the course:')\n    page.setFont('Times-Bold', 20)\n    page.drawCentredString(center, 300, course.course_type.name)\n    page.setFont('Times-Roman', 16)\n    page.drawCentredString(\n        center, 270,\n        'From %s %s %s to %s %s %s'\n        % (course.start_date.day, course.start_date.strftime('%B'),\n           course.start_date.year, course.end_date.day,\n           course.end_date.strftime('%B'), course.end_date.year))\n    page.setFillColorRGB(0.1, 0.1, 0.1)\n    page.drawCentredString(\n        center, 220, 'Convened by %s %s at %s' % (\n            course.course_convener.user.first_name,\n            course.course_convener.user.last_name, course.training_center))\n\n    if project_owner_signature is not None:\n        page.drawImage(\n            project_owner_signature,\n            (margin_left + 100), (margin_bottom + 70), width=100, height=70,\n            preserveAspectRatio=True, anchor='s', mask='auto')\n\n    if convener_signature is not None:\n        page.drawImage(\n            convener_signature, (margin_right - 200), (margin_bottom + 70),\n            width=100, height=70, preserveAspectRatio=True, anchor='s',\n            mask='auto')\n\n    page.setFont('Times-Italic', 12)\n    page.drawCentredString(\n        (margin_left + 150), (margin_bottom + 60),\n        '%s %s' % (project.owner.first_name, project.owner.last_name))\n    page.drawCentredString(\n        (margin_right - 150), (margin_bottom + 60),\n        '%s %s' % (\n            course.course_convener.user.first_name,\n            course.course_convener.user.last_name))\n    page.line(\n        (margin_left + 70), (margin_bottom + 55),\n        (margin_left + 230), (margin_bottom + 55))\n    page.line(\n        (margin_right - 70), (margin_bottom + 55),\n        (margin_right - 230), (margin_bottom + 55))\n    page.setFont('Times-Roman', 13)\n    page.drawCentredString(\n        (margin_left + 150), (margin_bottom + 40), 'Project Owner')\n    page.drawCentredString(\n        (margin_right - 150), (margin_bottom + 40), 'Convener')\n\n    # Footnotes.\n    page.setFont('Times-Roman', 14)\n    page.drawString(\n        margin_left, margin_bottom - 10, 'ID: %s' % certificate.certificateID)\n    page.setFont('Times-Roman', 8)\n    page.drawString(\n        margin_left, (margin_bottom - 20),\n        'You can verify this certificate by visiting '\n        'http://%s/en/%s/certificate/%s/.'\n        % (current_site, project.slug, certificate.certificateID))\n\n    # Close the PDF object cleanly.\n    page.showPage()\n    page.save()\n    return response\n", "path": "django_project/certification/views/certificate.py"}]}