Skip to content

Commit

Permalink
Migrate spaces models to the new app
Browse files Browse the repository at this point in the history
  • Loading branch information
matti-lamppu committed Sep 19, 2024
1 parent cbbc145 commit 4b0296f
Show file tree
Hide file tree
Showing 113 changed files with 1,301 additions and 824 deletions.
2 changes: 1 addition & 1 deletion actions/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from common.typing import Lang
from reservation_units.models import ReservationUnit
from reservations.models import Reservation
from spaces.models import Location, Unit
from tilavarauspalvelu.models import Location, Unit


class ReservationActions:
Expand Down
2 changes: 1 addition & 1 deletion actions/reservation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from reservation_units.models import ReservationUnit
from reservations.models import Reservation
from spaces.models import Building, Location
from tilavarauspalvelu.models import Building, Location

__all__ = [
"ReservationUnitActions",
Expand Down
5 changes: 4 additions & 1 deletion applications/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from applications.querysets.application import ApplicationQuerySet
from common.connectors import ApplicationActionsConnector
from common.fields.model import StrChoiceField
from spaces.models import Unit

if TYPE_CHECKING:
from datetime import datetime

from tilavarauspalvelu.models import Unit


__all__ = [
"Application",
Expand Down Expand Up @@ -282,6 +283,8 @@ def applicant_type_sort_order() -> int:

@property
def units_for_permissions(self) -> list[Unit]:
from tilavarauspalvelu.models import Unit

if hasattr(self, "_units_for_permissions"):
return self._units_for_permissions

Expand Down
5 changes: 2 additions & 3 deletions applications/models/application_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from common.date_utils import local_datetime

if TYPE_CHECKING:
from spaces.models import Unit

from tilavarauspalvelu.models import Unit

__all__ = [
"ApplicationRound",
Expand Down Expand Up @@ -265,7 +264,7 @@ def _(self) -> ApplicationRoundReservationCreationStatusChoice:

@property
def units_for_permissions(self) -> list[Unit]:
from spaces.models import Unit
from tilavarauspalvelu.models import Unit

if hasattr(self, "_units_for_permissions"):
return self._units_for_permissions
Expand Down
2 changes: 1 addition & 1 deletion applications/querysets/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _add_units_for_permissions(self) -> None:
# This works sort of like a 'prefetch_related', since it makes another query
# to fetch units and unit groups for the permission checks when the queryset is evaluated,
# and 'joins' them to the correct model instances in python.
from spaces.models import Unit
from tilavarauspalvelu.models import Unit

items: list[Application] = list(self)
if not items:
Expand Down
2 changes: 1 addition & 1 deletion applications/querysets/application_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _add_units_for_permissions(self) -> None:
# This works sort of like a 'prefetch_related', since it makes another query
# to fetch units and unit groups for the permission checks when the queryset is evaluated,
# and 'joins' them to the correct model instances in python.
from spaces.models import Unit
from tilavarauspalvelu.models import Unit

items: list[ApplicationRound] = list(self)
if not items:
Expand Down
3 changes: 1 addition & 2 deletions common/management/commands/data_creation/create_caisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
TaxPercentage,
)
from reservations.models import ReservationMetadataSet
from spaces.models import Space, Unit
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import PaymentAccounting, PaymentMerchant, PaymentProduct, TermsOfUse
from tilavarauspalvelu.models import PaymentAccounting, PaymentMerchant, PaymentProduct, Space, TermsOfUse, Unit

from .utils import SetName, with_logs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from permissions.enums import UserRoleChoice
from permissions.models import GeneralRole, UnitRole
from spaces.models import Unit, UnitGroup
from tilavarauspalvelu.models import Unit, UnitGroup
from users.models import User

from .utils import with_logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from datetime import timedelta

from reservation_units.models import Equipment, EquipmentCategory, Purpose, Qualifier
from spaces.models import Space, Unit
from tilavarauspalvelu.enums import ResourceLocationType, ServiceTypeChoices
from tilavarauspalvelu.models import Resource, Service
from tilavarauspalvelu.models import Resource, Service, Space, Unit

from .utils import weighted_choice, with_logs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
TaxPercentage,
)
from reservations.models import ReservationMetadataSet
from spaces.models import Unit
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import Resource, Service, TermsOfUse
from tilavarauspalvelu.models import Resource, Service, TermsOfUse, Unit

from .create_seasonal_booking import _create_application_round_time_slots
from .utils import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from applications.typing import TimeSlotDB
from reservation_units.models import ReservationUnit
from reservations.models import AgeGroup, ReservationPurpose
from spaces.models import ServiceSector, Unit
from tilavarauspalvelu.models import ServiceSector, Unit
from users.models import User

from .utils import batched, faker_en, faker_fi, faker_sv, get_paragraphs, random_subset, weighted_choice, with_logs
Expand Down
4 changes: 2 additions & 2 deletions common/management/commands/data_creation/create_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.contrib.gis.geos import Point

from common.management.commands.data_creation.utils import with_logs
from spaces.models import Location, Unit, UnitGroup
from spaces.models.location import COORDINATE_SYSTEM_ID
from tilavarauspalvelu.constants import COORDINATE_SYSTEM_ID
from tilavarauspalvelu.models import Location, Unit, UnitGroup


@with_logs()
Expand Down
2 changes: 1 addition & 1 deletion email_notification/admin/email_template_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.http import HttpResponseRedirect

from email_notification.admin import EmailTemplateAdmin
from spaces.models import Location
from tilavarauspalvelu.models import Location


def _get_email_template_tester_form_initial_values(request, template_pk: int | None = None) -> dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion email_notification/helpers/email_builder_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from config.utils.commons import LanguageType
from email_notification.admin.email_template_tester import EmailTemplateTesterForm
from reservations.models import Reservation
from spaces.models import Location
from tilavarauspalvelu.models import Location

type InstructionNameType = Literal["confirmed", "pending", "cancelled"]

Expand Down
3 changes: 2 additions & 1 deletion email_notification/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from email_notification.helpers.email_sender import EmailNotificationSender
from email_notification.models import EmailType
from reservations.models import Reservation
from spaces.models import Unit
from users.models import ReservationNotification, User
from utils.sentry import SentryLogger

Expand Down Expand Up @@ -60,6 +59,8 @@ def _get_reservation_staff_notification_recipients(
Get users with unit roles and notifications enabled, collect the ones that can manage relevant units,
have matching notification setting are not the reservation creator
"""
from tilavarauspalvelu.models import Unit

notification_recipients: list[str] = []
reservation_units = reservation.reservation_unit.all()
units = Unit.objects.filter(reservationunit__in=reservation_units).prefetch_related("unit_groups").distinct()
Expand Down
24 changes: 12 additions & 12 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2837,18 +2837,6 @@ msgstr "Vaaditut kentät"
msgid "Reservation metadata sets"
msgstr "Varauslomakkeet"

#: spaces/admin/space.py
msgid "Search by name or unit name"
msgstr "Etsi nimellä tai toimipisteen nimellä"

#: spaces/admin/unit.py
msgid "Search by name or TPREK ID"
msgstr "Etsi nimellä tai TPREK ID:llä"

#: spaces/admin/unit_group.py
msgid "Search by name"
msgstr "Etsi nimellä"

#: templates/admin/base.html
msgid "Change password"
msgstr "Vaihda salasana"
Expand Down Expand Up @@ -3015,6 +3003,18 @@ msgstr ""
"Etsi maksutunnuksella, varauksen tunnuksella, verkkokaupan tunnuksella, "
"varauksen nimellä tai varausyksikön nimellä"

#: tilavarauspalvelu/admin/space/admin.py
msgid "Search by name or unit name"
msgstr "Etsi nimellä tai toimipisteen nimellä"

#: tilavarauspalvelu/admin/unit/admin.py
msgid "Search by name or TPREK ID"
msgstr "Etsi nimellä tai TPREK ID:llä"

#: tilavarauspalvelu/admin/unit_group/admin.py
msgid "Search by name"
msgstr "Etsi nimellä"

#: tilavarauspalvelu/api/gdpr/views.py
msgid "User has upcoming or too recent reservations."
msgstr "Käyttäjällä on tulevia tai liian äskettäisiä varauksia."
Expand Down
24 changes: 12 additions & 12 deletions locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2771,18 +2771,6 @@ msgstr ""
msgid "Reservation metadata sets"
msgstr ""

#: spaces/admin/space.py
msgid "Search by name or unit name"
msgstr ""

#: spaces/admin/unit.py
msgid "Search by name or TPREK ID"
msgstr ""

#: spaces/admin/unit_group.py
msgid "Search by name"
msgstr ""

#: templates/admin/base.html
msgid "Change password"
msgstr ""
Expand Down Expand Up @@ -2947,6 +2935,18 @@ msgid ""
"name, or Reservation Unit name"
msgstr ""

#: tilavarauspalvelu/admin/space/admin.py
msgid "Search by name or unit name"
msgstr ""

#: tilavarauspalvelu/admin/unit/admin.py
msgid "Search by name or TPREK ID"
msgstr ""

#: tilavarauspalvelu/admin/unit_group/admin.py
msgid "Search by name"
msgstr ""

#: tilavarauspalvelu/api/gdpr/views.py
msgid "User has upcoming or too recent reservations."
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 5.1.1 on 2024-09-19 05:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("permissions", "0033_create_and_modified_auto_now"),
("tilavarauspalvelu", "0005_realestate_building_space_alter_resource_space_unit_and_more"),
]

operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name="unitrole",
name="unit_groups",
field=models.ManyToManyField(
blank=True, related_name="unit_roles", to="tilavarauspalvelu.unitgroup"
),
),
migrations.AlterField(
model_name="unitrole",
name="units",
field=models.ManyToManyField(blank=True, related_name="unit_roles", to="tilavarauspalvelu.unit"),
),
],
database_operations=[],
),
]
4 changes: 2 additions & 2 deletions permissions/models/unit_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class UnitRole(models.Model):
user: User = models.ForeignKey("users.User", related_name="unit_roles", on_delete=models.CASCADE)
role: str = StrChoiceField(enum=UserRoleChoice)

units = models.ManyToManyField("spaces.Unit", related_name="unit_roles", blank=True)
unit_groups = models.ManyToManyField("spaces.UnitGroup", related_name="unit_roles", blank=True)
units = models.ManyToManyField("tilavarauspalvelu.Unit", related_name="unit_roles", blank=True)
unit_groups = models.ManyToManyField("tilavarauspalvelu.UnitGroup", related_name="unit_roles", blank=True)

assigner: User | None = models.ForeignKey("users.User", on_delete=models.SET_NULL, null=True, blank=True)
created: datetime.datetime = models.DateTimeField(auto_now_add=True)
Expand Down
7 changes: 5 additions & 2 deletions permissions/permission_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from common.date_utils import local_datetime
from permissions.enums import UserPermissionChoice, UserRoleChoice
from spaces.models import Unit

if TYPE_CHECKING:
from collections.abc import Container, Iterable
Expand All @@ -15,7 +14,7 @@
from common.typing import AnyUser
from reservation_units.models import ReservationUnit
from reservations.models import RecurringReservation, Reservation
from spaces.models import Space
from tilavarauspalvelu.models import Space, Unit
from users.models import User


Expand Down Expand Up @@ -80,6 +79,8 @@ def has_role_for_units_or_their_unit_groups(
return False

if units is None: # Check for any unit or unit group the user has roles in
from tilavarauspalvelu.models import Unit

unit_ids = list(self.user.unit_roles_map.keys())
unit_group_ids = list(self.user.unit_group_roles_map.keys())
units = (
Expand Down Expand Up @@ -126,6 +127,8 @@ def has_permission_for_unit_or_their_unit_group(
unit_ids: Iterable[Unit] = (),
require_all: bool = False,
) -> bool:
from tilavarauspalvelu.models import Unit

unit_ids = list(unit_ids)
if not unit_ids: # Check for all units and unit groups the user has permissions for.
unit_ids = list(self.user.unit_permissions_map.keys())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.1.1 on 2024-09-19 05:31

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("reservation_units", "0108_alter_reservationunit_resources"),
("tilavarauspalvelu", "0005_realestate_building_space_alter_resource_space_unit_and_more"),
]

operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name="reservationunit",
name="spaces",
field=models.ManyToManyField(
blank=True,
related_name="reservation_units",
to="tilavarauspalvelu.space",
),
),
migrations.AlterField(
model_name="reservationunit",
name="unit",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="tilavarauspalvelu.unit",
),
),
],
database_operations=[],
),
]
7 changes: 3 additions & 4 deletions reservation_units/models/reservation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from opening_hours.models import OriginHaukiResource
from reservation_units.models import ReservationUnitCancellationRule, ReservationUnitType
from reservations.models import ReservationMetadataSet
from spaces.models import Unit
from tilavarauspalvelu.models import PaymentAccounting, PaymentMerchant, PaymentProduct, TermsOfUse
from tilavarauspalvelu.models import PaymentAccounting, PaymentMerchant, PaymentProduct, TermsOfUse, Unit

__all__ = [
"ReservationUnit",
Expand Down Expand Up @@ -115,7 +114,7 @@ class ReservationUnit(SearchDocumentMixin, models.Model):
# Many-to-One related

unit: Unit | None = models.ForeignKey(
"spaces.Unit",
"tilavarauspalvelu.Unit",
blank=True,
null=True,
on_delete=models.SET_NULL,
Expand Down Expand Up @@ -200,7 +199,7 @@ class ReservationUnit(SearchDocumentMixin, models.Model):
# Many-to-Many related

spaces = models.ManyToManyField(
"spaces.Space",
"tilavarauspalvelu.Space",
related_name="reservation_units",
blank=True,
)
Expand Down
Loading

0 comments on commit 4b0296f

Please sign in to comment.