From 89074201d04bfa3b0d0a36abd104e4464a99847d Mon Sep 17 00:00:00 2001 From: Prathamesh Date: Wed, 27 Dec 2023 15:54:09 +0530 Subject: Allow organiser to Download all the certificates --- website/cgen/templates/download_all.html | 29 ++++++++++++++++++++++++++ website/cgen/views.py | 35 +++++++++++++++++++++++--------- website/website/urls.py | 4 ++++ 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 website/cgen/templates/download_all.html diff --git a/website/cgen/templates/download_all.html b/website/cgen/templates/download_all.html new file mode 100644 index 0000000..bcadf04 --- /dev/null +++ b/website/cgen/templates/download_all.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} +{% block header%} + {{ certificate.event.name }} Certificates +{% endblock %} +{% block content %} + + + + + + + + + + {% for email, name in details.items %} + + + + + + {% endfor %} + + + +
#NameDownload
{{ forloop.counter }} {{ name | title }} Download
+ + +{% endblock %} + diff --git a/website/cgen/views.py b/website/cgen/views.py index 1343312..68623cb 100644 --- a/website/cgen/views.py +++ b/website/cgen/views.py @@ -15,23 +15,38 @@ def events(request): context = {'events': events} return render(request, 'index.html', context) +def certificate_download_all(request, certificate_id): + certificate = get_object_or_404(Certificate, id=certificate_id) + context = {'certificate': certificate} + participants = certificate.participant_set.all() + details = {} + for participant in participants: + info = eval(f'{participant.details}') + details[participant.email] = info['name'] + context['details'] = details + return render(request, 'download_all.html', context) + + # Create your views here. -def certificate_download(request, certificate_id): +def certificate_download(request, certificate_id, email=None): context= {} certificate = get_object_or_404(Certificate, id=certificate_id) context['certificate'] = certificate ci = RequestContext(request) if request.method == 'POST': email = request.POST.get('email').strip() - cm, s = generator.get_certificate(certificate_id, email) - if not s: - context["notregistered"] = 1 - return render(request, 'download.html', context) - if s: - response = HttpResponse(cm.certificate_file, content_type="application/pdf") - response['Content-Disposition'] = 'attachment; filename="certificate.pdf"' - return response - return render(request, 'download.html', context) + elif email is not None: + email = email + else: + return render(request, 'download.html', context) + cm, s = generator.get_certificate(certificate_id, email) + if not s: + context["notregistered"] = 1 + return render(request, 'download.html', context) + if s: + response = HttpResponse(cm.certificate_file, content_type="application/pdf") + response['Content-Disposition'] = 'attachment; filename="certificate.pdf"' + return response def verify(request, key=None): diff --git a/website/website/urls.py b/website/website/urls.py index dec738e..4bf9ff6 100644 --- a/website/website/urls.py +++ b/website/website/urls.py @@ -23,6 +23,10 @@ urlpatterns = [ path('certificate/events/', views.events, name="events"), path('certificate/download//', views.certificate_download, name="certificate_download"), + path('certificate/download///', + views.certificate_download, name="certificate_download"), + path('certificate/download_all//', + views.certificate_download_all, name="certificate_download_all"), path('certificate/verify/', views.verify, name="verify"), path('certificate/verify//', views.verify, name="verify"), path('certificate/upload//', -- cgit