Skip to content

Commit

Permalink
Move terms of use models to the new app
Browse files Browse the repository at this point in the history
  • Loading branch information
matti-lamppu committed Sep 27, 2024
1 parent 9f513f7 commit 587419a
Show file tree
Hide file tree
Showing 37 changed files with 520 additions and 339 deletions.
5 changes: 3 additions & 2 deletions applications/admin/application_round/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from applications.models import ApplicationRound
from common.fields.forms import disabled_widget
from reservation_units.models import ReservationUnit
from terms_of_use.models import TermsOfUse
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import TermsOfUse


class ApplicationRoundAdminForm(forms.ModelForm):
Expand Down Expand Up @@ -41,7 +42,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
kwargs["initial"]["status"] = ApplicationRoundStatusChoice(instance.status).label
self.base_fields["reservation_units"].queryset = ReservationUnit.objects.select_related("unit").all()
self.base_fields["terms_of_use"].queryset = TermsOfUse.objects.filter(
terms_type=TermsOfUse.TERMS_TYPE_RECURRING
terms_type=TermsOfUseTypeChoices.RECURRING
)
super().__init__(*args, **kwargs)

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-18 09:48

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


class Migration(migrations.Migration):
dependencies = [
("applications", "0093_remove_applicationround_target_group"),
("tilavarauspalvelu", "0004_migrate_terms_of_use"),
]

operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name="applicationround",
name="terms_of_use",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="application_rounds",
to="tilavarauspalvelu.termsofuse",
),
),
],
# We just moved the model, so no need to modify foreign keys
database_operations=[],
),
]
2 changes: 1 addition & 1 deletion applications/models/application_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ApplicationRound(models.Model):
related_name="application_rounds",
)
terms_of_use = models.ForeignKey(
"terms_of_use.TermsOfUse",
"tilavarauspalvelu.TermsOfUse",
null=True,
blank=False,
on_delete=models.SET_NULL,
Expand Down
27 changes: 14 additions & 13 deletions common/management/commands/data_creation/create_caisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
)
from reservations.models import ReservationMetadataSet
from spaces.models import Space, Unit
from terms_of_use.models import TermsOfUse
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import TermsOfUse

from .utils import SetName, with_logs

Expand Down Expand Up @@ -67,7 +68,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"name_en": "Payment terms - free of charge",
"name_sv": "Betalningsvillkor - kostnadsfritt",
"text": "",
"terms_type": TermsOfUse.TERMS_TYPE_PAYMENT,
"terms_type": TermsOfUseTypeChoices.PAYMENT,
},
)
payment_terms_1, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -82,7 +83,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Palvelussa ilmoitetut hinnat sisältävät arvolisäveron. "
"Mahdolliset lisäpalvelut eivät sisälly hintaan.",
),
"terms_type": TermsOfUse.TERMS_TYPE_PAYMENT,
"terms_type": TermsOfUseTypeChoices.PAYMENT,
},
)
payment_terms_3, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -103,7 +104,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"vähintään 18 vuoden ikää. Palvelussa ilmoitetut hinnat sisältävät arvolisäveron. "
"Mahdolliset lisäpalvelut eivät sisälly hintaan.",
),
"terms_type": TermsOfUse.TERMS_TYPE_PAYMENT,
"terms_type": TermsOfUseTypeChoices.PAYMENT,
},
)
payment_terms_4, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -124,7 +125,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"ilmoitetut hinnat sisältävät arvolisäveron. Mahdolliset lisäpalvelut "
"eivät sisälly hintaan."
),
"terms_type": TermsOfUse.TERMS_TYPE_PAYMENT,
"terms_type": TermsOfUseTypeChoices.PAYMENT,
},
)

Expand All @@ -143,7 +144,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Varaajan tulee olla täysi-ikäinen. Tilassa järjestettävä tilaisuus "
"ei saa häiritä muuta kirjaston toimintaa, asiakkaita tai käyttäjiä."
),
"terms_type": TermsOfUse.TERMS_TYPE_SERVICE,
"terms_type": TermsOfUseTypeChoices.SERVICE,
},
)
service_terms_library, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -156,7 +157,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"text": (
"Tähän varaukseen sovelletaan Helsingin kaupungin tilojen ja laitteiden varaamisen sopimusehtoja."
),
"terms_type": TermsOfUse.TERMS_TYPE_SERVICE,
"terms_type": TermsOfUseTypeChoices.SERVICE,
},
)
service_terms_gadgets, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -173,7 +174,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Tilaustöiden tekeminen korvausta vastaan tai ammattimainen "
"tulonhankinta ei ole sallittua."
),
"terms_type": TermsOfUse.TERMS_TYPE_SERVICE,
"terms_type": TermsOfUseTypeChoices.SERVICE,
},
)
service_terms_youth, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -190,7 +191,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Yöpyminen on sallittu vain nuorisopalveluiden leirikeskuksissa "
"tai vastaavissa tiloissa, jotka on tarkoitettu yöpymiseen."
),
"terms_type": TermsOfUse.TERMS_TYPE_SERVICE,
"terms_type": TermsOfUseTypeChoices.SERVICE,
},
)

Expand All @@ -210,7 +211,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"ei ole mahdollista. Jos varaus on maksullinen, käyttämättä "
"jääneen vuoron maksua ei palauteta."
),
"terms_type": TermsOfUse.TERMS_TYPE_CANCELLATION,
"terms_type": TermsOfUseTypeChoices.CANCELLATION,
},
)
cancel_terms_zero_days, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -224,7 +225,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Varauksen voi perua Varaamossa veloituksetta ennen varauksen alkamista. "
"Myöhästyessäsi yli 15 minuuttia varaus vapautetaan muiden käyttöön."
),
"terms_type": TermsOfUse.TERMS_TYPE_CANCELLATION,
"terms_type": TermsOfUseTypeChoices.CANCELLATION,
},
)
cancel_terms_14_days, _ = TermsOfUse.objects.get_or_create(
Expand All @@ -238,7 +239,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"Varauksen voi perua veloituksetta kaksi viikkoa (14 vrk) ennen varauksen alkamista. "
"Myöhemmin tehdyistä peruutuksista peritään täysi hinta."
),
"terms_type": TermsOfUse.TERMS_TYPE_CANCELLATION,
"terms_type": TermsOfUseTypeChoices.CANCELLATION,
},
)

Expand Down Expand Up @@ -272,7 +273,7 @@ def _create_caisa(metadata_sets: dict[SetName, ReservationMetadataSet]) -> None:
"muutos liittyy hinnoittelun tarkoituksenmukaiseen kohtuullistamiseen, "
"varauksen tekijän sitä kirjallisesti hakiessa."
),
"terms_type": TermsOfUse.TERMS_TYPE_PAYMENT,
"terms_type": TermsOfUseTypeChoices.PAYMENT,
},
)

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

from .create_seasonal_booking import _create_application_round_time_slots
from .utils import (
Expand Down Expand Up @@ -117,7 +117,7 @@ def _create_reservation_units(
authentication=weighted_choice(AuthenticationType.values, weights=[2, 1]),
can_apply_free_of_charge=can_apply_free_of_charge,
cancellation_rule=next(cancellation_rules_loop),
cancellation_terms=terms_of_use[TermsOfUse.TERMS_TYPE_CANCELLATION],
cancellation_terms=terms_of_use[TermsOfUseTypeChoices.CANCELLATION.value],
contact_information=faker_fi.text(),
description=description.fi,
description_en=description.en,
Expand All @@ -137,8 +137,8 @@ def _create_reservation_units(
name_fi=f"{name} FI",
name_sv=f"{name} SV",
origin_hauki_resource=random.choice(hauki_resources),
payment_terms=terms_of_use[TermsOfUse.TERMS_TYPE_PAYMENT],
pricing_terms=terms_of_use[TermsOfUse.TERMS_TYPE_PRICING],
payment_terms=terms_of_use[TermsOfUseTypeChoices.PAYMENT.value],
pricing_terms=terms_of_use[TermsOfUseTypeChoices.PRICING.value],
rank=i,
reservation_begins=datetime(2021, 1, 1, tzinfo=UTC),
reservation_cancelled_instructions=cancelled.fi,
Expand All @@ -158,7 +158,7 @@ def _create_reservation_units(
reservation_unit_type=next(reservation_unit_types_loop),
reservations_max_days_before=max_before,
reservations_min_days_before=min_before,
service_specific_terms=terms_of_use[TermsOfUse.TERMS_TYPE_SERVICE],
service_specific_terms=terms_of_use[TermsOfUseTypeChoices.SERVICE.value],
surface_area=random.randint(10, 1000),
terms_of_use=terms.fi,
terms_of_use_en=terms.en,
Expand Down Expand Up @@ -397,19 +397,19 @@ def _create_terms_of_use() -> dict[str, TermsOfUse]:
text_fi=text_fi,
text_sv=text_sv,
text_en=text_en,
terms_type=TermsOfUse.TERMS_TYPE_GENERIC,
terms_type=TermsOfUseTypeChoices.GENERIC,
)

#
# Create other kinds of terms
#
terms_of_use: list[TermsOfUse] = []
term_types: list[str] = [
TermsOfUse.TERMS_TYPE_PAYMENT,
TermsOfUse.TERMS_TYPE_CANCELLATION,
TermsOfUse.TERMS_TYPE_RECURRING,
TermsOfUse.TERMS_TYPE_SERVICE,
TermsOfUse.TERMS_TYPE_PRICING,
TermsOfUseTypeChoices.PAYMENT.value,
TermsOfUseTypeChoices.CANCELLATION.value,
TermsOfUseTypeChoices.RECURRING.value,
TermsOfUseTypeChoices.SERVICE.value,
TermsOfUseTypeChoices.PRICING.value,
]
for term_type in term_types:
name = term_type.replace("_", " ").title()
Expand Down
2 changes: 1 addition & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def APP_VERSION(cls) -> str:
TEMPLATES = [
{
"BACKEND": "django_jinja.jinja2.Jinja2",
"DIRS": [],
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
},
{
Expand Down
Loading

0 comments on commit 587419a

Please sign in to comment.