From 48952c546325558922bee8afc917f6f347171b04 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 2 Aug 2021 20:11:36 +0200 Subject: [PATCH] add used_time to BaseTicket model so we know when tickets were checked in/used --- src/backoffice/views/infodesk.py | 2 ++ .../migrations/0019_auto_20210802_1756.py | 28 +++++++++++++++++ .../0020_populate_ticket_used_when.py | 30 +++++++++++++++++++ src/tickets/models.py | 1 + 4 files changed, 61 insertions(+) create mode 100644 src/tickets/migrations/0019_auto_20210802_1756.py create mode 100644 src/tickets/migrations/0020_populate_ticket_used_when.py diff --git a/src/backoffice/views/infodesk.py b/src/backoffice/views/infodesk.py index 439a4504..3de60968 100644 --- a/src/backoffice/views/infodesk.py +++ b/src/backoffice/views/infodesk.py @@ -3,6 +3,7 @@ from itertools import chain from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin +from django.utils import timezone from django.views.generic import ListView, TemplateView from camps.mixins import CampViewMixin @@ -121,6 +122,7 @@ class ScanTicketsView( check_in_ticket_id = request.POST.get("check_in_ticket_id") ticket_to_check_in = _ticket_getter_by_pk(check_in_ticket_id) ticket_to_check_in.used = True + ticket_to_check_in.used_time = timezone.now() ticket_to_check_in.save() messages.info(request, "Ticket checked-in!") return ticket_to_check_in diff --git a/src/tickets/migrations/0019_auto_20210802_1756.py b/src/tickets/migrations/0019_auto_20210802_1756.py new file mode 100644 index 00000000..40b68d86 --- /dev/null +++ b/src/tickets/migrations/0019_auto_20210802_1756.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.5 on 2021-08-02 17:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("tickets", "0018_remove_shopticket_order"), + ] + + operations = [ + migrations.AddField( + model_name="discountticket", + name="used_time", + field=models.DateTimeField(null=True), + ), + migrations.AddField( + model_name="shopticket", + name="used_time", + field=models.DateTimeField(null=True), + ), + migrations.AddField( + model_name="sponsorticket", + name="used_time", + field=models.DateTimeField(null=True), + ), + ] diff --git a/src/tickets/migrations/0020_populate_ticket_used_when.py b/src/tickets/migrations/0020_populate_ticket_used_when.py new file mode 100644 index 00000000..453cadad --- /dev/null +++ b/src/tickets/migrations/0020_populate_ticket_used_when.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.5 on 2021-08-02 17:56 + +from django.db import migrations + + +def populate_ticket_used_when(apps, schema_editor): + ShopTicket = apps.get_model("tickets", "ShopTicket") + SponsorTicket = apps.get_model("tickets", "SponsorTicket") + DiscountTicket = apps.get_model("tickets", "DiscountTicket") + + for st in ShopTicket.objects.filter(used_time__isnull=True, used=True): + st.used_when = st.updated + st.save() + + for st in SponsorTicket.objects.filter(used_time__isnull=True, used=True): + st.used_when = st.updated + st.save() + + for dt in DiscountTicket.objects.filter(used_time__isnull=True, used=True): + st.used_when = st.updated + st.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("tickets", "0019_auto_20210802_1756"), + ] + + operations = [migrations.RunPython(populate_ticket_used_when)] diff --git a/src/tickets/models.py b/src/tickets/models.py index 5e2035be..47a690fa 100644 --- a/src/tickets/models.py +++ b/src/tickets/models.py @@ -98,6 +98,7 @@ def qr_code_base64(token): class BaseTicket(CampRelatedModel, UUIDModel): ticket_type = models.ForeignKey("TicketType", on_delete=models.PROTECT) used = models.BooleanField(default=False) + used_time = models.DateTimeField(null=True) badge_handed_out = models.BooleanField(default=False) token = models.CharField(max_length=64, blank=True) badge_token = models.CharField(max_length=64, blank=True)