From f38664721ed117f445b27af839fe41898ed90a47 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 24 Mar 2021 12:56:33 +0530 Subject: Modify QR code functionality, courtesy @adityacp --- yaksh/models.py | 6 ++- yaksh/templates/yaksh/question.html | 9 +++-- yaksh/templates/yaksh/upload_file.html | 72 ++++++++++++++++++++++++++++------ yaksh/views.py | 58 ++++++++++++++------------- 4 files changed, 98 insertions(+), 47 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index d792205..efe772c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -3360,8 +3360,10 @@ class QRcode(models.Model): def generate_image(self, content): img = qrcode.make(content) - path = os.path.join(settings.MEDIA_ROOT, 'qrcode', - '{0}.png'.format(self.short_key)) + qr_dir = os.path.join(settings.MEDIA_ROOT, 'qrcode') + if not os.path.exists(qr_dir): + os.makedirs(qr_dir) + path = os.path.join(qr_dir, f'{self.short_key}.png') img.save(path) self.image = os.path.join('qrcode', '{0}.png'.format(self.short_key)) self.activate() diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 3b73781..17305b6 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -290,12 +290,13 @@ question_type = "{{ question.type }}"; {% endif %} +
{% if qrcode %} - + {% else %} - Generate QR Code +
+ Generate QR Code {% endif %}

{% endif %} diff --git a/yaksh/templates/yaksh/upload_file.html b/yaksh/templates/yaksh/upload_file.html index 04d8b09..e25e8e7 100644 --- a/yaksh/templates/yaksh/upload_file.html +++ b/yaksh/templates/yaksh/upload_file.html @@ -1,16 +1,10 @@ +{% load static %} Upload File - - + + + +