remove imports and ticket class from shop
This commit is contained in:
parent
477b1b85de
commit
c04838377b
|
@ -3,19 +3,16 @@ from django.db import models
|
|||
from django.db.models.aggregates import Sum
|
||||
from django.contrib import messages
|
||||
from django.contrib.postgres.fields import DateTimeRangeField, JSONField
|
||||
from django.http import HttpResponse
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from utils.models import UUIDModel, CreatedUpdatedModel
|
||||
from .managers import ProductQuerySet, OrderQuerySet
|
||||
import hashlib, io, base64, qrcode
|
||||
from decimal import Decimal
|
||||
from datetime import timedelta
|
||||
from unidecode import unidecode
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class CustomOrder(CreatedUpdatedModel):
|
||||
|
@ -454,64 +451,3 @@ class CoinifyAPIRequest(CreatedUpdatedModel):
|
|||
|
||||
def __str__(self):
|
||||
return 'order %s api request %s' % (self.order.id, self.method)
|
||||
|
||||
|
||||
class Ticket(CreatedUpdatedModel, UUIDModel):
|
||||
order = models.ForeignKey('shop.Order', related_name='tickets')
|
||||
product = models.ForeignKey('shop.Product', related_name='tickets')
|
||||
qrcode_base64 = models.TextField(null=True, blank=True)
|
||||
|
||||
name = models.CharField(
|
||||
max_length=100,
|
||||
help_text=(
|
||||
'Name of the person this ticket belongs to. '
|
||||
'This can be different from the buying user.'
|
||||
),
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
email = models.EmailField(
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
checked_in = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return 'Ticket {user} {product}'.format(
|
||||
user=self.order.user,
|
||||
product=self.product
|
||||
)
|
||||
|
||||
def save(self, **kwargs):
|
||||
super(Ticket, self).save(**kwargs)
|
||||
self.qrcode_base64 = self.get_qr_code()
|
||||
super(Ticket, self).save(**kwargs)
|
||||
|
||||
def get_token(self):
|
||||
return hashlib.sha256(
|
||||
'{ticket_id}{user_id}{secret_key}'.format(
|
||||
ticket_id=self.pk,
|
||||
user_id=self.order.user.pk,
|
||||
secret_key=settings.SECRET_KEY,
|
||||
).encode('utf-8')
|
||||
).hexdigest()
|
||||
|
||||
def get_qr_code(self):
|
||||
qr = qrcode.make(
|
||||
self.get_token(),
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_H
|
||||
).resize((250,250))
|
||||
file_like = io.BytesIO()
|
||||
qr.save(file_like, format='png')
|
||||
qrcode_base64 = base64.b64encode(file_like.getvalue())
|
||||
return qrcode_base64
|
||||
|
||||
def get_qr_code_url(self):
|
||||
return 'data:image/png;base64,{}'.format(self.qrcode_base64)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return str(reverse_lazy('shop:ticket_detail', kwargs={'pk': self.pk}))
|
||||
|
||||
|
|
Loading…
Reference in a new issue