Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UUID to application section #1460

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/test_graphql_api/test_application_section/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_application_section__query__all_fields(graphql):

fields = """
pk
extUuid
name
numPersons
reservationsBeginDate
Expand Down Expand Up @@ -64,6 +65,7 @@ def test_application_section__query__all_fields(graphql):
assert len(response.edges) == 2, response
assert response.node(0) == {
"pk": section.pk,
"extUuid": str(section.ext_uuid),
"name": section.name,
"numPersons": section.num_persons,
"reservationsBeginDate": section.reservations_begin_date.isoformat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_recurring_reservations__query(graphql):

fields = """
pk
extUuid
name
description
beginDate
Expand Down Expand Up @@ -78,6 +79,7 @@ def test_recurring_reservations__query(graphql):
assert len(response.edges) == 1
assert response.node(0) == {
"pk": recurring_reservation.pk,
"extUuid": str(recurring_reservation.ext_uuid),
"name": recurring_reservation.name,
"description": recurring_reservation.description,
"beginDate": recurring_reservation.begin_date.isoformat(),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_graphql_api/test_reservation/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_reservation__query__all_fields(graphql):
denyReason { reason }
description
end
extUuid
freeOfChargeReason
handledAt
handlingDetails
Expand Down Expand Up @@ -117,6 +118,7 @@ def test_reservation__query__all_fields(graphql):
"denyReason": None,
"description": reservation.description,
"end": reservation.end.isoformat(),
"extUuid": str(reservation.ext_uuid),
"freeOfChargeReason": reservation.free_of_charge_reason,
"handledAt": reservation.handled_at,
"handlingDetails": reservation.handling_details,
Expand Down
6 changes: 5 additions & 1 deletion tilavarauspalvelu/admin/application_section/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ApplicationSectionAdmin(admin.ModelAdmin):
{
"fields": [
"id",
"ext_uuid",
"name",
"status",
"application",
Expand All @@ -114,7 +115,10 @@ class ApplicationSectionAdmin(admin.ModelAdmin):
},
],
]
readonly_fields = ["id"]
readonly_fields = [
"id",
"ext_uuid",
]
inlines = [
SuitableTimeRangeInline,
ReservationUnitOptionInline,
Expand Down
2 changes: 2 additions & 0 deletions tilavarauspalvelu/admin/application_section/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Meta:
model = ApplicationSection
fields = [] # Use fields from ModelAdmin
labels = {
"ext_uuid": _("External UUID"),
"name": _("Name"),
"status": _("Status"),
"num_persons": _("Number of persons"),
Expand All @@ -138,6 +139,7 @@ class Meta:
"purpose": _("Purpose"),
}
help_texts = {
"ext_uuid": _("ID for external systems to use"),
"name": _("Name that describes this section."),
"num_persons": _("Number of persons that are excepted to attend this section."),
"reservation_min_duration": _("Minimum duration that should be allocated for this section."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Meta:
model = ApplicationSection
fields = [
"pk",
"ext_uuid",
"name",
"num_persons",
"reservations_begin_date",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.3 on 2024-12-10 07:58
from __future__ import annotations

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0050_change_reservation_unit_vectors_to_non_null"),
]

operations = [
migrations.AddField(
model_name="applicationsection",
name="ext_uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.3 on 2024-12-10 07:58
from __future__ import annotations

import uuid

from django.db import migrations


def gen_uuid(apps, schema_editor) -> None:
"""See. https://docs.djangoproject.com/en/5.1/howto/writing-migrations/#migrations-that-add-unique-fields"""
ApplicationSection = apps.get_model("tilavarauspalvelu", "ApplicationSection")

# Should be fine, since there aren't that many application sections yet (~1000 in production)
rows = list(ApplicationSection.objects.all())
for row in rows:
row.ext_uuid = uuid.uuid4()
ApplicationSection.objects.bulk_update(rows, ["ext_uuid"])


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0051_add_application_section_ext_uuid"),
]

operations = [migrations.RunPython(gen_uuid, migrations.RunPython.noop)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.3 on 2024-12-10 07:58
from __future__ import annotations

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tilavarauspalvelu", "0052_populate_application_section_ext_uuid"),
]

operations = [
migrations.AlterField(
model_name="applicationsection",
name="ext_uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
),
]
3 changes: 3 additions & 0 deletions tilavarauspalvelu/models/application_section/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 functools import cached_property
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -34,6 +35,8 @@ class ApplicationSection(SerializableMixin, models.Model):
and suitable time ranges that can be used fulfill the slot request included in it.
"""

ext_uuid: uuid.UUID = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # ID for external systems

name: str = models.CharField(max_length=100)
num_persons: int = models.PositiveIntegerField()
reservations_begin_date: datetime.date = models.DateField()
Expand Down
Loading