diff --git a/src/shop/admin.py b/src/shop/admin.py index cb600227..f264f62a 100644 --- a/src/shop/admin.py +++ b/src/shop/admin.py @@ -49,11 +49,6 @@ class ProductInline(admin.TabularInline): model = models.OrderProductRelation -class TicketInline(admin.TabularInline): - model = models.Ticket - exclude = ['qrcode_base64'] - - @admin.register(models.Order) class OrderAdmin(admin.ModelAdmin): change_form_template = 'admin/change_order_form.html' @@ -91,7 +86,7 @@ class OrderAdmin(admin.ModelAdmin): exclude = ['products'] - inlines = [ProductInline, TicketInline] + inlines = [ProductInline] actions = ['mark_order_as_paid', 'mark_order_as_refunded'] @@ -109,24 +104,3 @@ class OrderAdmin(admin.ModelAdmin): def get_user_email(obj): return obj.order.user.email - -@admin.register(models.Ticket) -class TicketModelAdmin(admin.ModelAdmin): - list_display = [ - 'order', - 'product', - 'name', - 'email', - get_user_email, - 'get_token', - 'checked_in' - ] - - list_filter = ['product', 'checked_in'] - - actions = ['mark_as_arrived'] - - def mark_as_arrived(self, request, queryset): - queryset.update(checked_in=True) - - diff --git a/src/shop/apps.py b/src/shop/apps.py index 9f11a60d..5edbc95c 100644 --- a/src/shop/apps.py +++ b/src/shop/apps.py @@ -1,12 +1,7 @@ from django.apps import AppConfig -from .signal_handlers import ticket_created -from django.db.models.signals import post_save import logging logger = logging.getLogger("bornhack.%s" % __name__) class ShopConfig(AppConfig): name = 'shop' - def ready(self): - post_save.connect(ticket_created, sender='shop.Ticket') - diff --git a/src/shop/migrations/0052_auto_20171004_0005.py b/src/shop/migrations/0052_auto_20171004_0005.py new file mode 100644 index 00000000..92f85171 --- /dev/null +++ b/src/shop/migrations/0052_auto_20171004_0005.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-10-03 22:05 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0051_creditnote_danish_vat'), + ] + + operations = [ + migrations.RemoveField( + model_name='ticket', + name='order', + ), + migrations.RemoveField( + model_name='ticket', + name='product', + ), + migrations.DeleteModel( + name='Ticket', + ), + ] diff --git a/src/shop/models.py b/src/shop/models.py index 5620b5d6..4ebcc7c8 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -534,62 +534,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})) diff --git a/src/shop/views.py b/src/shop/views.py index 5d09e353..0ff51a4e 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -29,7 +29,6 @@ from shop.models import ( EpayPayment, CoinifyAPIInvoice, CoinifyAPICallback, - Ticket, CreditNote, ) from .forms import AddToOrderForm diff --git a/src/tickets/apps.py b/src/tickets/apps.py index 3ea742ac..307172a7 100644 --- a/src/tickets/apps.py +++ b/src/tickets/apps.py @@ -1,5 +1,13 @@ from django.apps import AppConfig +from .signal_handlers import ticket_created +from django.db.models.signals import post_save +import logging +logger = logging.getLogger("bornhack.%s" % __name__) class TicketsConfig(AppConfig): name = 'tickets' + + def ready(self): + post_save.connect(ticket_created, sender='tickets.ShopTicket') + diff --git a/src/shop/signal_handlers.py b/src/tickets/signal_handlers.py similarity index 84% rename from src/shop/signal_handlers.py rename to src/tickets/signal_handlers.py index 6eefc1bb..de588c60 100644 --- a/src/shop/signal_handlers.py +++ b/src/tickets/signal_handlers.py @@ -15,8 +15,8 @@ def ticket_created(sender, instance, created, **kwargs): target = settings.IRCBOT_CHANNELS['orga'] if 'orga' in settings.IRCBOT_CHANNELS else settings.IRCBOT_CHANNELS['default'] # get ticket stats, FIXME: Camp name is hardcoded here for now - from shop.models import Ticket - stats = ", ".join(["%s: %s" % (tickettype['product__name'].replace("BornHack 2017 ", ""), tickettype['total']) for tickettype in Ticket.objects.filter(product__name__startswith="BornHack 2017").exclude(product__name__startswith="BornHack 2017 One Day").values('product__name').annotate(total=Count('product__name')).order_by('-total')]) + from tickets.models import ShopTicket + stats = ", ".join(["%s: %s" % (tickettype['product__name'].replace("BornHack 2017 ", ""), tickettype['total']) for tickettype in ShopTicket.objects.filter(product__name__startswith="BornHack 2017").exclude(product__name__startswith="BornHack 2017 One Day").values('product__name').annotate(total=Count('product__name')).order_by('-total')]) onedaystats = Ticket.objects.filter(product__name__startswith="BornHack 2017 One Day Ticket").count() onedaychildstats = Ticket.objects.filter(product__name__startswith="BornHack 2017 One Day Children").count()