diff --git a/common/management/commands/data_creation/create_reservables.py b/common/management/commands/data_creation/create_reservables.py index 5b319a4c9..be70d0297 100644 --- a/common/management/commands/data_creation/create_reservables.py +++ b/common/management/commands/data_creation/create_reservables.py @@ -4,11 +4,9 @@ from datetime import timedelta from reservation_units.models import Equipment, EquipmentCategory, Purpose, Qualifier -from resources.enums import ResourceLocationType -from resources.models import Resource from spaces.models import Space, Unit -from tilavarauspalvelu.enums import ServiceTypeChoices -from tilavarauspalvelu.models import Service +from tilavarauspalvelu.enums import ResourceLocationType, ServiceTypeChoices +from tilavarauspalvelu.models import Resource, Service from .utils import weighted_choice, with_logs diff --git a/common/management/commands/data_creation/create_reservation_units.py b/common/management/commands/data_creation/create_reservation_units.py index 9118f8de4..8814eb862 100644 --- a/common/management/commands/data_creation/create_reservation_units.py +++ b/common/management/commands/data_creation/create_reservation_units.py @@ -28,10 +28,9 @@ TaxPercentage, ) from reservations.models import ReservationMetadataSet -from resources.models import Resource from spaces.models import Unit from tilavarauspalvelu.enums import TermsOfUseTypeChoices -from tilavarauspalvelu.models import Service, TermsOfUse +from tilavarauspalvelu.models import Resource, Service, TermsOfUse from .create_seasonal_booking import _create_application_round_time_slots from .utils import ( diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index 819eff30c..69b4eb917 100644 --- a/locale/fi/LC_MESSAGES/django.po +++ b/locale/fi/LC_MESSAGES/django.po @@ -385,7 +385,7 @@ msgstr "" #: reservation_units/models/equipment.py reservation_units/models/keyword.py #: reservation_units/models/reservation_unit_type.py #: reservations/admin/reservation/form.py -#: reservations/models/reservation_metadata.py resources/models.py +#: reservations/models/reservation_metadata.py msgid "Name" msgstr "Nimi" @@ -1752,12 +1752,12 @@ msgid "Surface area" msgstr "Pinta-ala" #: reservation_units/admin/reservation_unit/form.py -#: reservations/admin/reservation/form.py resources/models.py +#: reservations/admin/reservation/form.py msgid "Buffer time before" msgstr "Tauko ennen varausta" #: reservation_units/admin/reservation_unit/form.py -#: reservations/admin/reservation/form.py resources/models.py +#: reservations/admin/reservation/form.py msgid "Buffer time after" msgstr "Tauko varauksen jälkeen" @@ -2837,16 +2837,6 @@ msgstr "Vaaditut kentät" msgid "Reservation metadata sets" msgstr "Varauslomakkeet" -#: resources/enums.py -msgctxt "ResourceLocationType" -msgid "Fixed" -msgstr "Kiinteä" - -#: resources/enums.py -msgctxt "ResourceLocationType" -msgid "Movable" -msgstr "Siirrettävä" - #: spaces/admin/space.py msgid "Search by name or unit name" msgstr "Etsi nimellä tai toimipisteen nimellä" @@ -3113,6 +3103,17 @@ msgctxt "OrderStatus" msgid "Free" msgstr "Maksuton" +#: tilavarauspalvelu/enums.py + +msgctxt "ResourceLocationType" +msgid "Fixed" +msgstr "Kiinteä" + +#: tilavarauspalvelu/enums.py +msgctxt "ResourceLocationType" +msgid "Movable" +msgstr "Siirrettävä" + #: tilavarauspalvelu/models/payment_accounting/model.py msgid "" "One of the following fields must be given: internal_order, profit_center, " diff --git a/locale/sv/LC_MESSAGES/django.po b/locale/sv/LC_MESSAGES/django.po index 59abfc0a3..8fbe9eb8b 100644 --- a/locale/sv/LC_MESSAGES/django.po +++ b/locale/sv/LC_MESSAGES/django.po @@ -374,7 +374,7 @@ msgstr "" #: reservation_units/models/equipment.py reservation_units/models/keyword.py #: reservation_units/models/reservation_unit_type.py #: reservations/admin/reservation/form.py -#: reservations/models/reservation_metadata.py resources/models.py +#: reservations/models/reservation_metadata.py msgid "Name" msgstr "" @@ -1700,12 +1700,12 @@ msgid "Surface area" msgstr "" #: reservation_units/admin/reservation_unit/form.py -#: reservations/admin/reservation/form.py resources/models.py +#: reservations/admin/reservation/form.py msgid "Buffer time before" msgstr "" #: reservation_units/admin/reservation_unit/form.py -#: reservations/admin/reservation/form.py resources/models.py +#: reservations/admin/reservation/form.py msgid "Buffer time after" msgstr "" @@ -2217,12 +2217,16 @@ msgid "Keyword group" msgstr "" #: reservation_units/models/reservation_unit.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation Unit" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservation_units/models/reservation_unit.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation Units" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservation_units/models/reservation_unit_cancellation_rule.py msgid "Name for the rule" @@ -2274,8 +2278,10 @@ msgid "Tax percentage" msgstr "" #: reservations/admin/reservation/admin.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Search by Reservation ID or name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/admin.py #: reservations/admin/reservation/form.py @@ -2340,16 +2346,22 @@ msgid "State" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation type" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Booking details" msgid "Cancel details" -msgstr "" +msgstr "Uppgifter om bokningen" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Booking details" msgid "Handling details" -msgstr "" +msgstr "Uppgifter om bokningen" #: reservations/admin/reservation/form.py msgid "Handled at" @@ -2392,12 +2404,16 @@ msgid "Reservee ID" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservee first name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservee last name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py msgid "Reservee email" @@ -2408,8 +2424,10 @@ msgid "Reservee phone" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservee organisation name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py msgid "Reservee address street" @@ -2444,8 +2462,10 @@ msgid "Billing last name" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Booking details" msgid "Billing email" -msgstr "" +msgstr "Uppgifter om bokningen" #: reservations/admin/reservation/form.py msgid "Billing phone" @@ -2512,8 +2532,10 @@ msgid "Reservation begin date and time" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation end date and time" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py msgid "When this reservation was handled" @@ -2564,8 +2586,10 @@ msgid "Reservee's business or association identity code" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservee's first name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py msgid "Reservee's last name" @@ -2580,8 +2604,10 @@ msgid "Reservee's phone number" msgstr "" #: reservations/admin/reservation/form.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservee's organisation name" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: reservations/admin/reservation/form.py msgid "Reservee's street address" @@ -2768,18 +2794,10 @@ msgid "Required fields" msgstr "" #: reservations/models/reservation_metadata.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation metadata sets" -msgstr "" - -#: resources/enums.py -msgctxt "ResourceLocationType" -msgid "Fixed" -msgstr "" - -#: resources/enums.py -msgctxt "ResourceLocationType" -msgid "Movable" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: spaces/admin/space.py msgid "Search by name or unit name" @@ -2880,8 +2898,10 @@ msgid "Value comes from the Merchant Experience API" msgstr "" #: tilavarauspalvelu/admin/payment_order/admin.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: tilavarauspalvelu/admin/payment_order/admin.py msgid "Remote order ID" @@ -2924,8 +2944,10 @@ msgid "Language" msgstr "" #: tilavarauspalvelu/admin/payment_order/admin.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation user UUID" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: tilavarauspalvelu/admin/payment_order/admin.py msgid "Checkout URL" @@ -3043,6 +3065,16 @@ msgctxt "OrderStatus" msgid "Free" msgstr "" +#: tilavarauspalvelu/enums.py +msgctxt "ResourceLocationType" +msgid "Fixed" +msgstr "" + +#: tilavarauspalvelu/enums.py +msgctxt "ResourceLocationType" +msgid "Movable" +msgstr "" + #: tilavarauspalvelu/models/payment_accounting/model.py msgid "" "One of the following fields must be given: internal_order, profit_center, " @@ -3092,8 +3124,10 @@ msgid "Preferred UI language" msgstr "" #: users/models.py +#, fuzzy +#| msgid "Reservation for %(name)s" msgid "Reservation notification" -msgstr "" +msgstr "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: users/models.py msgid "Date of birth" diff --git a/reservation_units/migrations/0108_alter_reservationunit_resources.py b/reservation_units/migrations/0108_alter_reservationunit_resources.py new file mode 100644 index 000000000..d12c42a3a --- /dev/null +++ b/reservation_units/migrations/0108_alter_reservationunit_resources.py @@ -0,0 +1,27 @@ +# Generated by Django 5.1.1 on 2024-09-19 04:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("reservation_units", "0107_alter_reservationunit_payment_accounting_and_more"), + ("tilavarauspalvelu", "0006_migrate_resources"), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterField( + model_name="reservationunit", + name="resources", + field=models.ManyToManyField( + blank=True, + related_name="reservation_units", + to="tilavarauspalvelu.resource", + ), + ), + ], + database_operations=[], + ), + ] diff --git a/reservation_units/models/reservation_unit.py b/reservation_units/models/reservation_unit.py index 4d3c581af..dba4e11d1 100644 --- a/reservation_units/models/reservation_unit.py +++ b/reservation_units/models/reservation_unit.py @@ -205,7 +205,7 @@ class ReservationUnit(SearchDocumentMixin, models.Model): blank=True, ) resources = models.ManyToManyField( - "resources.Resource", + "tilavarauspalvelu.Resource", related_name="reservation_units", blank=True, ) diff --git a/reservation_units/querysets.py b/reservation_units/querysets.py index fa21e825d..c9f7de9ee 100644 --- a/reservation_units/querysets.py +++ b/reservation_units/querysets.py @@ -11,8 +11,8 @@ from common.date_utils import local_datetime from common.db import ArrayUnnest, SubqueryArray from reservation_units.utils.first_reservable_time_helper.first_reservable_time_helper import FirstReservableTimeHelper -from resources.models import Resource from spaces.models import Space +from tilavarauspalvelu.models import Resource if TYPE_CHECKING: from collections.abc import Callable, Generator diff --git a/resources/admin.py b/resources/admin.py deleted file mode 100644 index 3bb34812e..000000000 --- a/resources/admin.py +++ /dev/null @@ -1,21 +0,0 @@ -from django.contrib import admin -from modeltranslation.admin import TranslationAdmin - -from resources.models import Resource - -__all__ = [ - "ResourceAdmin", -] - - -@admin.register(Resource) -class ResourceAdmin(TranslationAdmin): - # List - list_display = [ - "name", - "space", - "location_type", - "buffer_time_before", - "buffer_time_after", - ] - list_filter = ["location_type"] diff --git a/resources/apps.py b/resources/apps.py deleted file mode 100644 index cbf046b2c..000000000 --- a/resources/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class ResourcesConfig(AppConfig): - name = "resources" diff --git a/resources/enums.py b/resources/enums.py deleted file mode 100644 index 92bdad9a5..000000000 --- a/resources/enums.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.db import models -from django.utils.translation import pgettext_lazy - -__all__ = [ - "ResourceLocationType", -] - - -class ResourceLocationType(models.TextChoices): - FIXED = "fixed", pgettext_lazy("ResourceLocationType", "Fixed") - MOVABLE = "movable", pgettext_lazy("ResourceLocationType", "Movable") diff --git a/resources/migrations/0011_delete_resource.py b/resources/migrations/0011_delete_resource.py new file mode 100644 index 000000000..e6ae67ec8 --- /dev/null +++ b/resources/migrations/0011_delete_resource.py @@ -0,0 +1,21 @@ +# Generated by Django 5.1.1 on 2024-09-19 04:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("reservation_units", "0107_alter_reservationunit_payment_accounting_and_more"), + ("resources", "0010_alter_resource_options"), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.DeleteModel( + name="Resource", + ), + ], + database_operations=[], + ), + ] diff --git a/resources/models.py b/resources/models.py deleted file mode 100644 index 66908f4e0..000000000 --- a/resources/models.py +++ /dev/null @@ -1,39 +0,0 @@ -from django.db import models -from django.utils.translation import gettext_lazy as _ - -from resources.enums import ResourceLocationType -from spaces.models import Space - -__all__ = [ - "Resource", -] - - -class Resource(models.Model): - location_type = models.CharField( - max_length=20, - choices=ResourceLocationType.choices, - default=ResourceLocationType.FIXED.value, - ) - name = models.CharField(verbose_name=_("Name"), max_length=255) - space = models.ForeignKey(Space, verbose_name="Space", on_delete=models.SET_NULL, null=True, blank=True) - buffer_time_before = models.DurationField(verbose_name=_("Buffer time before"), blank=True, null=True) - buffer_time_after = models.DurationField(verbose_name=_("Buffer time after"), blank=True, null=True) - - # Translated field hints - name_fi: str | None - name_sv: str | None - name_en: str | None - - class Meta: - db_table = "resource" - base_manager_name = "objects" - ordering = [ - "pk", - ] - - def __str__(self) -> str: - value = self.name - if self.space is not None: - value += f" ({self.space!s})" - return value diff --git a/resources/translation.py b/resources/translation.py deleted file mode 100644 index 9606c3cc6..000000000 --- a/resources/translation.py +++ /dev/null @@ -1,8 +0,0 @@ -from modeltranslation.translator import TranslationOptions, register - -from resources.models import Resource - - -@register(Resource) -class ResourceTranslationOptions(TranslationOptions): - fields = ["name"] diff --git a/tests/factories/resource.py b/tests/factories/resource.py index 4e39d9866..3ad57d51b 100644 --- a/tests/factories/resource.py +++ b/tests/factories/resource.py @@ -1,8 +1,8 @@ import factory from factory import fuzzy -from resources.enums import ResourceLocationType -from resources.models import Resource +from tilavarauspalvelu.enums import ResourceLocationType +from tilavarauspalvelu.models import Resource from ._base import GenericDjangoModelFactory diff --git a/tests/test_graphql_api/test_resource/test_create.py b/tests/test_graphql_api/test_resource/test_create.py index d22f9ede6..2ce2a6ba6 100644 --- a/tests/test_graphql_api/test_resource/test_create.py +++ b/tests/test_graphql_api/test_resource/test_create.py @@ -1,8 +1,8 @@ import pytest -from resources.enums import ResourceLocationType -from resources.models import Resource from tests.factories import SpaceFactory +from tilavarauspalvelu.enums import ResourceLocationType +from tilavarauspalvelu.models import Resource from .helpers import CREATE_MUTATION diff --git a/tests/test_graphql_api/test_resource/test_create_permissions.py b/tests/test_graphql_api/test_resource/test_create_permissions.py index 8f1647c68..1b982a6c7 100644 --- a/tests/test_graphql_api/test_resource/test_create_permissions.py +++ b/tests/test_graphql_api/test_resource/test_create_permissions.py @@ -1,8 +1,8 @@ import pytest -from resources.enums import ResourceLocationType -from resources.models import Resource from tests.factories import SpaceFactory, UnitGroupFactory, UserFactory +from tilavarauspalvelu.enums import ResourceLocationType +from tilavarauspalvelu.models import Resource from .helpers import CREATE_MUTATION diff --git a/tests/test_graphql_api/test_resource/test_delete.py b/tests/test_graphql_api/test_resource/test_delete.py index deb1311ff..a1fb79e68 100644 --- a/tests/test_graphql_api/test_resource/test_delete.py +++ b/tests/test_graphql_api/test_resource/test_delete.py @@ -1,7 +1,7 @@ import pytest -from resources.models import Resource from tests.factories import ResourceFactory +from tilavarauspalvelu.models import Resource from .helpers import DELETE_MUTATION diff --git a/tests/test_graphql_api/test_resource/test_update.py b/tests/test_graphql_api/test_resource/test_update.py index 43e41cb48..ac51ebeee 100644 --- a/tests/test_graphql_api/test_resource/test_update.py +++ b/tests/test_graphql_api/test_resource/test_update.py @@ -1,7 +1,7 @@ import pytest -from resources.enums import ResourceLocationType from tests.factories import ResourceFactory +from tilavarauspalvelu.enums import ResourceLocationType from .helpers import UPDATE_MUTATION diff --git a/tilavarauspalvelu/admin/__init__.py b/tilavarauspalvelu/admin/__init__.py index 75f247ab6..1d43f8ff8 100644 --- a/tilavarauspalvelu/admin/__init__.py +++ b/tilavarauspalvelu/admin/__init__.py @@ -1,6 +1,7 @@ from .payment_accounting.admin import PaymentAccountingAdmin from .payment_merchant.admin import PaymentMerchantAdmin from .payment_order.admin import PaymentOrderAdmin +from .resource.admin import ResourceAdmin from .service.admin import ServiceAdmin from .terms_of_use.admin import TermsOfUseAdmin from .user.admin import UserAdmin @@ -9,6 +10,7 @@ "PaymentAccountingAdmin", "PaymentMerchantAdmin", "PaymentOrderAdmin", + "ResourceAdmin", "ServiceAdmin", "TermsOfUseAdmin", "UserAdmin", diff --git a/tilavarauspalvelu/admin/resource/admin.py b/tilavarauspalvelu/admin/resource/admin.py index e69de29bb..5da868566 100644 --- a/tilavarauspalvelu/admin/resource/admin.py +++ b/tilavarauspalvelu/admin/resource/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin +from modeltranslation.admin import TranslationAdmin + +from tilavarauspalvelu.models import Resource + + +@admin.register(Resource) +class ResourceAdmin(TranslationAdmin): + # List + list_display = [ + "name", + "space", + "location_type", + "buffer_time_before", + "buffer_time_after", + ] + list_filter = ["location_type"] diff --git a/tilavarauspalvelu/api/graphql/types/resource/filtersets.py b/tilavarauspalvelu/api/graphql/types/resource/filtersets.py index cd03a6a0c..bb0c52efd 100644 --- a/tilavarauspalvelu/api/graphql/types/resource/filtersets.py +++ b/tilavarauspalvelu/api/graphql/types/resource/filtersets.py @@ -6,8 +6,8 @@ from graphene_django_extensions.filters import IntMultipleChoiceFilter from permissions.enums import UserRoleChoice -from resources.models import Resource from spaces.models import Space +from tilavarauspalvelu.models import Resource if TYPE_CHECKING: from common.typing import AnyUser diff --git a/tilavarauspalvelu/api/graphql/types/resource/mutations.py b/tilavarauspalvelu/api/graphql/types/resource/mutations.py index 71ea6fe68..26139d64b 100644 --- a/tilavarauspalvelu/api/graphql/types/resource/mutations.py +++ b/tilavarauspalvelu/api/graphql/types/resource/mutations.py @@ -1,6 +1,6 @@ from graphene_django_extensions import CreateMutation, DeleteMutation, UpdateMutation -from resources.models import Resource +from tilavarauspalvelu.models import Resource from .permissions import ResourcePermission from .serializers import ResourceSerializer diff --git a/tilavarauspalvelu/api/graphql/types/resource/permissions.py b/tilavarauspalvelu/api/graphql/types/resource/permissions.py index 3e3025ab3..76b94f48f 100644 --- a/tilavarauspalvelu/api/graphql/types/resource/permissions.py +++ b/tilavarauspalvelu/api/graphql/types/resource/permissions.py @@ -3,8 +3,8 @@ from graphene_django_extensions.permissions import BasePermission from common.typing import AnyUser -from resources.models import Resource from spaces.models import Space +from tilavarauspalvelu.models import Resource __all__ = [ "ResourcePermission", diff --git a/tilavarauspalvelu/api/graphql/types/resource/serializers.py b/tilavarauspalvelu/api/graphql/types/resource/serializers.py index 2248bbbd3..7c5a8e6f5 100644 --- a/tilavarauspalvelu/api/graphql/types/resource/serializers.py +++ b/tilavarauspalvelu/api/graphql/types/resource/serializers.py @@ -3,8 +3,8 @@ from graphene_django_extensions import NestingModelSerializer from graphql import GraphQLError -from resources.enums import ResourceLocationType -from resources.models import Resource +from tilavarauspalvelu.enums import ResourceLocationType +from tilavarauspalvelu.models import Resource __all__ = [ "ResourceSerializer", diff --git a/tilavarauspalvelu/api/graphql/types/resource/types.py b/tilavarauspalvelu/api/graphql/types/resource/types.py index 1d7822305..db42f2e31 100644 --- a/tilavarauspalvelu/api/graphql/types/resource/types.py +++ b/tilavarauspalvelu/api/graphql/types/resource/types.py @@ -1,8 +1,8 @@ import graphene from graphene_django_extensions import DjangoNode -from resources.enums import ResourceLocationType -from resources.models import Resource +from tilavarauspalvelu.enums import ResourceLocationType +from tilavarauspalvelu.models import Resource from .filtersets import ResourceFilterSet from .permissions import ResourcePermission diff --git a/tilavarauspalvelu/enums.py b/tilavarauspalvelu/enums.py index 2676a051f..4751805ee 100644 --- a/tilavarauspalvelu/enums.py +++ b/tilavarauspalvelu/enums.py @@ -11,6 +11,7 @@ "OrderStatusWithFree", "PaymentType", "ReservationNotification", + "ResourceLocationType", "ServiceTypeChoices", "TermsOfUseTypeChoices", ] @@ -85,3 +86,8 @@ class PaymentType(models.TextChoices): ON_SITE = "ON_SITE", pgettext_lazy("PaymentType", "On site") ONLINE = "ONLINE", pgettext_lazy("PaymentType", "Online") INVOICE = "INVOICE", pgettext_lazy("PaymentType", "Invoice") + + +class ResourceLocationType(models.TextChoices): + FIXED = "fixed", pgettext_lazy("ResourceLocationType", "Fixed") + MOVABLE = "movable", pgettext_lazy("ResourceLocationType", "Movable") diff --git a/tilavarauspalvelu/migrations/0006_migrate_resources.py b/tilavarauspalvelu/migrations/0006_migrate_resources.py new file mode 100644 index 000000000..d95afe17b --- /dev/null +++ b/tilavarauspalvelu/migrations/0006_migrate_resources.py @@ -0,0 +1,61 @@ +# Generated by Django 5.1.1 on 2024-09-19 04:54 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("spaces", "0040_alter_unit_payment_accounting_and_more"), + ("tilavarauspalvelu", "0005_migrate_merchants"), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.CreateModel( + name="Resource", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "location_type", + models.CharField( + choices=[("fixed", "Fixed"), ("movable", "Movable")], + default="fixed", + max_length=20, + ), + ), + ("name", models.CharField(max_length=255)), + ("name_fi", models.CharField(max_length=255, null=True)), + ("name_en", models.CharField(max_length=255, null=True)), + ("name_sv", models.CharField(max_length=255, null=True)), + ("buffer_time_before", models.DurationField(blank=True, null=True)), + ("buffer_time_after", models.DurationField(blank=True, null=True)), + ( + "space", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="spaces.space", + ), + ), + ], + options={ + "db_table": "resource", + "ordering": ["pk"], + "base_manager_name": "objects", + }, + ), + ], + database_operations=[], + ), + ] diff --git a/tilavarauspalvelu/models/__init__.py b/tilavarauspalvelu/models/__init__.py index e7162af0a..e212675b6 100644 --- a/tilavarauspalvelu/models/__init__.py +++ b/tilavarauspalvelu/models/__init__.py @@ -3,6 +3,7 @@ from .payment_order.model import PaymentOrder from .payment_product.model import PaymentProduct from .personal_info_view_log.model import PersonalInfoViewLog +from .resource.model import Resource from .service.model import Service from .terms_of_use.model import TermsOfUse from .user.model import ProfileUser, User @@ -14,6 +15,7 @@ "PaymentProduct", "PersonalInfoViewLog", "ProfileUser", + "Resource", "Service", "TermsOfUse", "User", diff --git a/tilavarauspalvelu/models/resource/actions.py b/tilavarauspalvelu/models/resource/actions.py index e69de29bb..0405f525d 100644 --- a/tilavarauspalvelu/models/resource/actions.py +++ b/tilavarauspalvelu/models/resource/actions.py @@ -0,0 +1,9 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from .model import Resource + + +class ResourceActions: + def __init__(self, resource: "Resource") -> None: + self.resource = resource diff --git a/tilavarauspalvelu/models/resource/model.py b/tilavarauspalvelu/models/resource/model.py index e69de29bb..e061adfda 100644 --- a/tilavarauspalvelu/models/resource/model.py +++ b/tilavarauspalvelu/models/resource/model.py @@ -0,0 +1,60 @@ +from __future__ import annotations + +from functools import cached_property +from typing import TYPE_CHECKING + +from django.db import models + +from tilavarauspalvelu.enums import ResourceLocationType + +from .queryset import ResourceManager + +if TYPE_CHECKING: + import datetime + + from spaces.models import Space + + from .actions import ResourceActions + + +__all__ = [ + "Resource", +] + + +class Resource(models.Model): + location_type: str = models.CharField( + max_length=20, + choices=ResourceLocationType.choices, + default=ResourceLocationType.FIXED.value, + ) + name: str = models.CharField(max_length=255) + space: Space | None = models.ForeignKey("spaces.Space", on_delete=models.SET_NULL, null=True, blank=True) + buffer_time_before: datetime.timedelta | None = models.DurationField(blank=True, null=True) + buffer_time_after: datetime.timedelta | None = models.DurationField(blank=True, null=True) + + # Translated field hints + name_fi: str | None + name_sv: str | None + name_en: str | None + + objects = ResourceManager() + + class Meta: + db_table = "resource" + base_manager_name = "objects" + ordering = ["pk"] + + def __str__(self) -> str: + value = self.name + if self.space is not None: + value += f" ({self.space!s})" + return value + + @cached_property + def actions(self) -> ResourceActions: + # Import actions inline to defer loading them. + # This allows us to avoid circular imports. + from .actions import ResourceActions + + return ResourceActions(self) diff --git a/tilavarauspalvelu/models/resource/queryset.py b/tilavarauspalvelu/models/resource/queryset.py index e69de29bb..09faec323 100644 --- a/tilavarauspalvelu/models/resource/queryset.py +++ b/tilavarauspalvelu/models/resource/queryset.py @@ -0,0 +1,14 @@ +from __future__ import annotations + +from django.db import models + +__all__ = [ + "ResourceManager", + "ResourceQuerySet", +] + + +class ResourceQuerySet(models.QuerySet): ... + + +class ResourceManager(models.Manager.from_queryset(ResourceQuerySet)): ... diff --git a/tilavarauspalvelu/translation.py b/tilavarauspalvelu/translation.py index d9cbdfadd..5c8ffbf6a 100644 --- a/tilavarauspalvelu/translation.py +++ b/tilavarauspalvelu/translation.py @@ -2,6 +2,7 @@ from modeltranslation.translator import TranslationOptions from .models import Service, TermsOfUse +from .models.resource.model import Resource @register(Service) @@ -12,3 +13,8 @@ class ServiceTranslationOptions(TranslationOptions): @register(TermsOfUse) class TermsOfUseTranslationOptions(TranslationOptions): fields = ["name", "text"] + + +@register(Resource) +class ResourceTranslationOptions(TranslationOptions): + fields = ["name"]