diff options
author | Prathamesh | 2023-12-27 15:54:09 +0530 |
---|---|---|
committer | Prathamesh | 2023-12-27 15:54:09 +0530 |
commit | 89074201d04bfa3b0d0a36abd104e4464a99847d (patch) | |
tree | d6fa36479ea254b0e69ec9322a16be368b485a8f | |
parent | fa1e7cf9320d8124efe70a9f4ab093d314acf178 (diff) | |
download | certificate-generation-89074201d04bfa3b0d0a36abd104e4464a99847d.tar.gz certificate-generation-89074201d04bfa3b0d0a36abd104e4464a99847d.tar.bz2 certificate-generation-89074201d04bfa3b0d0a36abd104e4464a99847d.zip |
Allow organiser to Download all the certificates
-rw-r--r-- | website/cgen/templates/download_all.html | 29 | ||||
-rw-r--r-- | website/cgen/views.py | 35 | ||||
-rw-r--r-- | website/website/urls.py | 4 |
3 files changed, 58 insertions, 10 deletions
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 %} + <table class="table table-bordered"> + <thead> + <tr> + <th scope="col">#</th> + <th scope="col">Name</th> + <th scope="col">Download</th> + </tr> + </thead> + <tbody class="table-group-divider"> + {% for email, name in details.items %} + <tr> + <th scope="row">{{ forloop.counter }}</th> + <td> {{ name | title }} </td> + <td><a class="btn btn-primary btn-lg" href="{% url 'certificate_download' certificate.id email %}" role="button"> Download </a></td> + </tr> + {% endfor %} + </tbody> + + + </table> + + +{% 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/<int:certificate_id>/', views.certificate_download, name="certificate_download"), + path('certificate/download/<int:certificate_id>/<str:email>/', + views.certificate_download, name="certificate_download"), + path('certificate/download_all/<int:certificate_id>/', + views.certificate_download_all, name="certificate_download_all"), path('certificate/verify/', views.verify, name="verify"), path('certificate/verify/<str:key>/', views.verify, name="verify"), path('certificate/upload/<int:certificate_id>/', |