From e6ca8a5c713f0c8a5cdf70b77ecc0cb114913782 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sat, 19 Aug 2017 23:10:13 +0200 Subject: [PATCH] calculate qrcode_base64 on the fly --- .../migrations/0003_auto_20170819_2309.py | 27 +++++++++++++++++++ src/tickets/models.py | 9 ++----- 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/tickets/migrations/0003_auto_20170819_2309.py diff --git a/src/tickets/migrations/0003_auto_20170819_2309.py b/src/tickets/migrations/0003_auto_20170819_2309.py new file mode 100644 index 00000000..64a1cef1 --- /dev/null +++ b/src/tickets/migrations/0003_auto_20170819_2309.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-08-19 21:09 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tickets', '0002_auto_20170819_2222'), + ] + + operations = [ + migrations.RemoveField( + model_name='discountticket', + name='qrcode_base64', + ), + migrations.RemoveField( + model_name='shopticket', + name='qrcode_base64', + ), + migrations.RemoveField( + model_name='sponsorticket', + name='qrcode_base64', + ), + ] diff --git a/src/tickets/models.py b/src/tickets/models.py index 0919d7e5..dac2169f 100644 --- a/src/tickets/models.py +++ b/src/tickets/models.py @@ -28,17 +28,12 @@ class TicketType(CreatedUpdatedModel, UUIDModel): class BaseTicket(CreatedUpdatedModel, UUIDModel): - qrcode_base64 = models.TextField(null=True, blank=True) ticket_type = models.ForeignKey('TicketType') checked_in = models.BooleanField(default=False) class Meta: abstract = True - def save(self, **kwargs): - self.qrcode_base64 = self.get_qr_code() - super().save(**kwargs) - def _get_token(self): return hashlib.sha256( '{_id}{secret_key}'.format( @@ -47,7 +42,7 @@ class BaseTicket(CreatedUpdatedModel, UUIDModel): ).encode('utf-8') ).hexdigest() - def get_qr_code(self): + def get_qr_code_base64(self): qr = qrcode.make( self._get_token(), version=1, @@ -59,7 +54,7 @@ class BaseTicket(CreatedUpdatedModel, UUIDModel): return qrcode_base64 def get_qr_code_url(self): - return 'data:image/png;base64,{}'.format(self.qrcode_base64) + return 'data:image/png;base64,{}'.format(self.get_qr_code_base64) def generate_pdf(self): generate_pdf_letter(