-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ed9302
commit 993dd78
Showing
21 changed files
with
238 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
reservation_units/migrations/0105_alter_reservationunit_services.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.1.1 on 2024-09-18 09:02 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("reservation_units", "0104_alter_reservationunit_reservation_kind"), | ||
("tilavarauspalvelu", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.AlterField( | ||
model_name="reservationunit", | ||
name="services", | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name="reservation_units", | ||
to="tilavarauspalvelu.service", | ||
), | ||
), | ||
], | ||
# We just moved the model, so no need to modify foreign keys | ||
database_operations=[], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 5.1.1 on 2024-09-18 09:02 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("reservation_units", "0105_alter_reservationunit_services"), | ||
("services", "0005_alter_service_options"), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.DeleteModel( | ||
name="Service", | ||
), | ||
], | ||
# We want to reuse the table, so don't drop it | ||
database_operations=[], | ||
) | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .reservables.service import ServiceAdmin | ||
|
||
__all__ = [ | ||
"ServiceAdmin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
from modeltranslation.admin import TranslationAdmin | ||
|
||
from tilavarauspalvelu.models import Service | ||
|
||
|
||
@admin.register(Service) | ||
class ServiceAdmin(TranslationAdmin): | ||
# List | ||
list_display = [ | ||
"name", | ||
"service_type", | ||
"buffer_time_before", | ||
"buffer_time_after", | ||
] | ||
list_filter = ["service_type"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
__all__ = [ | ||
"ServiceTypeChoices", | ||
] | ||
|
||
|
||
class ServiceTypeChoices(models.TextChoices): | ||
INTRODUCTION = "introduction", _("Introduction") | ||
CATERING = "catering", _("Catering") | ||
CONFIGURATION = "configuration", _("Configuration") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 5.1.1 on 2024-09-18 09:02 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.CreateModel( | ||
name="Service", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("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)), | ||
( | ||
"service_type", | ||
models.CharField( | ||
choices=[ | ||
("introduction", "Introduction"), | ||
("catering", "Catering"), | ||
("configuration", "Configuration"), | ||
], | ||
default="introduction", | ||
max_length=50, | ||
), | ||
), | ||
("buffer_time_before", models.DurationField(blank=True, null=True)), | ||
("buffer_time_after", models.DurationField(blank=True, null=True)), | ||
], | ||
options={ | ||
"db_table": "service", | ||
"ordering": ["pk"], | ||
"base_manager_name": "objects", | ||
}, | ||
), | ||
], | ||
# We want to reuse the table, so don't create a new one. | ||
database_operations=[], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .reservables.service import Service | ||
|
||
__all__ = [ | ||
"Service", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .model import Service | ||
|
||
__all__ = [ | ||
"Service", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .model import Service | ||
|
||
|
||
class ServiceActions: | ||
def __init__(self, service: "Service") -> None: | ||
self.service = service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
from functools import cached_property | ||
from typing import TYPE_CHECKING | ||
|
||
from django.db import models | ||
|
||
from tilavarauspalvelu.enums import ServiceTypeChoices | ||
|
||
from .queryset import ServiceQuerySet | ||
|
||
if TYPE_CHECKING: | ||
import datetime | ||
|
||
from .actions import ServiceActions | ||
|
||
|
||
__all__ = [ | ||
"Service", | ||
] | ||
|
||
|
||
class Service(models.Model): | ||
name: str = models.CharField(max_length=255) | ||
service_type: str = models.CharField( | ||
max_length=50, | ||
choices=ServiceTypeChoices.choices, | ||
default=ServiceTypeChoices.INTRODUCTION, | ||
) | ||
|
||
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 = ServiceQuerySet.as_manager() | ||
|
||
class Meta: | ||
db_table = "service" | ||
base_manager_name = "objects" | ||
ordering = ["pk"] | ||
|
||
def __str__(self) -> str: | ||
return f"{self.name} ({self.service_type})" | ||
|
||
@cached_property | ||
def actions(self) -> ServiceActions: | ||
# Import actions inline to defer loading them. | ||
# This allows us to avoid circular imports. | ||
from .actions import ServiceActions | ||
|
||
return ServiceActions(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from django.db import models | ||
|
||
__all__ = [ | ||
"ServiceQuerySet", | ||
] | ||
|
||
|
||
class ServiceQuerySet(models.QuerySet): ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from modeltranslation.decorators import register | ||
from modeltranslation.translator import TranslationOptions | ||
|
||
from .models import Service | ||
|
||
|
||
@register(Service) | ||
class ServiceTranslationOptions(TranslationOptions): | ||
fields = ["name"] |