Skip to content

Commit

Permalink
Add UUID fields to reservation models for future "keyless entry"
Browse files Browse the repository at this point in the history
- Rename recurring reservation `uuid` -> `ext_uuid`
- Add `ext_uuid` field to reservation
- Add `reservation_uuid` field to statistics
- Add `ext_uuid` fields to graphql schema
  • Loading branch information
matti-lamppu committed Nov 29, 2024
1 parent 563e472 commit 9594185
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 4 deletions.
8 changes: 8 additions & 0 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,10 @@ msgstr "Ei"
msgid "Paid reservation"
msgstr "Maksullinen varaus"

#: tilavarauspalvelu/admin/reservation/form.py
msgid "External UUID"
msgstr "Ulkoinen UUID"

#: tilavarauspalvelu/admin/reservation/form.py
#: tilavarauspalvelu/admin/reservation_unit/form.py
msgid "SKU"
Expand Down Expand Up @@ -1348,6 +1352,10 @@ msgstr "Syy hylkäämiselle"
msgid "Reason for cancellation"
msgstr "Syy perumiselle"

#: tilavarauspalvelu/admin/reservation/form.py
msgid "ID for external systems to use"
msgstr "Tunniste ulkoisten järjestelmien käyttöön"

#: tilavarauspalvelu/admin/reservation/form.py
msgid "SKU for this particular reservation"
msgstr "Tämän varauksen SKU"
Expand Down
8 changes: 8 additions & 0 deletions locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,10 @@ msgstr ""
msgid "Paid reservation"
msgstr ""

#: tilavarauspalvelu/admin/reservation/form.py
msgid "External UUID"
msgstr ""

#: tilavarauspalvelu/admin/reservation/form.py
#: tilavarauspalvelu/admin/reservation_unit/form.py
msgid "SKU"
Expand Down Expand Up @@ -1305,6 +1309,10 @@ msgstr ""
msgid "Reason for cancellation"
msgstr ""

#: tilavarauspalvelu/admin/reservation/form.py
msgid "ID for external systems to use"
msgstr ""

#: tilavarauspalvelu/admin/reservation/form.py
msgid "SKU for this particular reservation"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_reservation_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_statistics__create__reservation_creation_creates_statistics(settings):
assert stat.purpose_name == reservation.purpose.name
assert stat.recurrence_begin_date == recurring.begin_date
assert stat.recurrence_end_date == recurring.end_date
assert stat.recurrence_uuid == str(recurring.uuid)
assert stat.recurrence_uuid == str(recurring.ext_uuid)
assert stat.reservation == reservation
assert stat.reservation_confirmed_at == reservation.confirmed_at
assert stat.reservation_created_at == reservation.created_at
Expand Down
4 changes: 4 additions & 0 deletions tilavarauspalvelu/admin/recurring_reservation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
class RecurringReservationAdmin(admin.ModelAdmin):
# List
list_display = [
"ext_uuid",
"name",
"reservation_unit",
"allocated_time_slot",
"begin_date",
"end_date",
"recurrence_in_days",
]
readonly_fields = [
"ext_uuid",
]

# Form
inlines = [ReservationInline]
2 changes: 2 additions & 0 deletions tilavarauspalvelu/admin/reservation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ReservationAdmin(admin.ModelAdmin):
{
"fields": [
"id",
"ext_uuid",
"sku",
"name",
"description",
Expand Down Expand Up @@ -197,6 +198,7 @@ class ReservationAdmin(admin.ModelAdmin):
]
readonly_fields = [
"id",
"ext_uuid",
"handled_at",
"confirmed_at",
"created_at",
Expand Down
2 changes: 2 additions & 0 deletions tilavarauspalvelu/admin/reservation/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Meta:
fields = [] # Use fields from ModelAdmin
labels = {
#
"ext_uuid": _("External UUID"),
"sku": _("SKU"),
"name": _("Name"),
"description": _("Description"),
Expand Down Expand Up @@ -71,6 +72,7 @@ class Meta:
}
help_texts = {
#
"ext_uuid": _("ID for external systems to use"),
"sku": _("SKU for this particular reservation"),
"name": _("Name of the reservation"),
"description": _("Description of the reservation"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Meta:
model = RecurringReservation
fields = [
"pk",
"ext_uuid",
"user",
"age_group",
"ability_group",
Expand Down
1 change: 1 addition & 0 deletions tilavarauspalvelu/api/graphql/types/reservation/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Meta:
fields = [
#
"pk",
"ext_uuid",
"name",
"description",
"num_persons",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.3 on 2024-11-28 07:23
from __future__ import annotations

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0040_alter_reservationstatisticsreservationunit_unit_tprek_id"),
]

operations = [
migrations.RenameField(
model_name="recurringreservation",
old_name="uuid",
new_name="ext_uuid",
),
]
20 changes: 20 additions & 0 deletions tilavarauspalvelu/migrations/0042_add_reservation_uuids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.3 on 2024-11-28 07:23
from __future__ import annotations

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0041_rename_recurring_reservation_uuid_to_ext_uuid"),
]

operations = [
migrations.AddField(
model_name="reservation",
name="ext_uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
]
22 changes: 22 additions & 0 deletions tilavarauspalvelu/migrations/0043_populate_uuid_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.1.3 on 2024-11-28 07:30
from __future__ import annotations

import uuid

from django.db import migrations


def gen_uuid(apps, schema_editor) -> None:
Reservation = apps.get_model("tilavarauspalvelu", "Reservation")
rows = list(Reservation.objects.all())
for row in rows:
row.ext_uuid = uuid.uuid4()
Reservation.objects.bulk_update(rows, ["ext_uuid"])


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0042_add_reservation_uuids"),
]

operations = [migrations.RunPython(gen_uuid, migrations.RunPython.noop)]
20 changes: 20 additions & 0 deletions tilavarauspalvelu/migrations/0044_change_uuid_to_unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.3 on 2024-11-28 07:31
from __future__ import annotations

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0043_populate_uuid_values"),
]

operations = [
migrations.AlterField(
model_name="reservation",
name="ext_uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.3 on 2024-11-28 07:48
from __future__ import annotations

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0044_change_uuid_to_unique"),
]

operations = [
migrations.AddField(
model_name="reservationstatistic",
name="reservation_uuid",
field=models.CharField(blank=True, default="", max_length=255),
),
]
4 changes: 2 additions & 2 deletions tilavarauspalvelu/models/recurring_reservation/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import uuid as uuid_
import uuid
from functools import cached_property
from typing import TYPE_CHECKING

Expand All @@ -27,9 +27,9 @@


class RecurringReservation(models.Model):
ext_uuid: uuid.UUID = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # ID for external systems
name: str = models.CharField(max_length=255, blank=True, default="")
description: str = models.CharField(max_length=500, blank=True, default="")
uuid: uuid_.UUID = models.UUIDField(default=uuid_.uuid4, editable=False, unique=True)
created: datetime.datetime = models.DateTimeField(auto_now_add=True)

begin_date: datetime.date | None = models.DateField(null=True)
Expand Down
2 changes: 2 additions & 0 deletions tilavarauspalvelu/models/reservation/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import datetime
import uuid
from decimal import Decimal
from functools import cached_property
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -46,6 +47,7 @@

class Reservation(SerializableMixin, models.Model):
# Basic information
ext_uuid: uuid.UUID = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # ID for external systems
sku: str = models.CharField(max_length=255, blank=True, default="")
name: str = models.CharField(max_length=255, blank=True, default="")
description: str = models.CharField(max_length=255, blank=True, default="")
Expand Down
4 changes: 3 additions & 1 deletion tilavarauspalvelu/models/reservation_statistic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class ReservationStatistic(models.Model):
recurrence_begin_date: datetime.date | None = models.DateField(null=True)
recurrence_end_date: datetime.date | None = models.DateField(null=True)
recurrence_uuid: str = models.CharField(max_length=255, default="", blank=True)
reservation_uuid: str = models.CharField(max_length=255, default="", blank=True)
reservee_uuid: str = models.CharField(max_length=255, default="", blank=True)
reservee_used_ad_login: bool = models.BooleanField(default=False, blank=True)
is_applied: bool = models.BooleanField(default=False, blank=True)
Expand Down Expand Up @@ -204,7 +205,8 @@ def for_reservation(cls, reservation: Reservation, *, save: bool = True) -> Rese
statistic.purpose_name = reservation.purpose.name if reservation.purpose else ""
statistic.recurrence_begin_date = getattr(recurring_reservation, "begin_date", None)
statistic.recurrence_end_date = getattr(recurring_reservation, "end_date", None)
statistic.recurrence_uuid = getattr(recurring_reservation, "uuid", "")
statistic.recurrence_uuid = str(getattr(recurring_reservation, "ext_uuid", ""))
statistic.reservation_uuid = str(reservation.ext_uuid)
statistic.reservation = reservation
statistic.reservation_confirmed_at = reservation.confirmed_at
statistic.reservation_created_at = reservation.created_at
Expand Down

0 comments on commit 9594185

Please sign in to comment.