From 70129400aa8c5e9e4cf6c81c8a6a0f53e6889815 Mon Sep 17 00:00:00 2001 From: Pauliina Ilmanen Date: Thu, 9 Jan 2025 13:17:35 +0200 Subject: [PATCH 1/3] Rename people_capacity to people_capacity_lower People capacity will be split into two fields: `people_capacity_lower` and `people_capacity_upper` for adding a possibility to define a range of the space capacity. Rename the `people_capacity` field to `people_capacity_lower` in the `Resource` model and keep the data of the original field in this new field. Keep the original name `people_capacity` in the API until UI changes are done. Refs TTVA-217 --- .sanitizerconfig | 2 +- openapi.yaml | 4 ++-- resources/api/resource.py | 5 ++-- resources/importer/kirjasto10.py | 6 ++--- .../migrations/0129_rename_people_capacity.py | 18 ++++++++++++++ resources/models/resource.py | 2 +- resources/tests/test_resource_api.py | 24 +++++++++---------- respa_admin/forms.py | 2 +- .../respa_admin/resources/form/_booking.html | 2 +- respa_admin/tests/conftest.py | 2 +- 10 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 resources/migrations/0129_rename_people_capacity.py diff --git a/.sanitizerconfig b/.sanitizerconfig index fc48ac74b..b2de98372 100644 --- a/.sanitizerconfig +++ b/.sanitizerconfig @@ -372,7 +372,7 @@ strategy: name_fi: null name_sv: null need_manual_confirmation: null - people_capacity: null + people_capacity_lower: null public: null reservable: null reservable_days_in_advance: null diff --git a/openapi.yaml b/openapi.yaml index 3b28da599..21d4fd633 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -526,7 +526,7 @@ paths: in: query description: Order queryset by given resource fields, accepted values are `resource_name_fi`, `resource_name_en`, `resource_name_sv`, `unit_name_fi`, - `unit_name_en`, `unit_name_sv`, `type`, `people_capacity`. Prefix parameter + `unit_name_en`, `unit_name_sv`, `type`, `people_capacity_lower`. Prefix parameter value with `-` to get reverse ordering. schema: type: string @@ -1043,7 +1043,7 @@ components: authentication: type: string description: The type of authentication required to reserve the resource - people_capacity: + people_capacity_lower: type: number description: The maximum number of people for the resource area: diff --git a/resources/api/resource.py b/resources/api/resource.py index 906011019..2edc57d35 100644 --- a/resources/api/resource.py +++ b/resources/api/resource.py @@ -198,6 +198,7 @@ class ResourceSerializer( ExtraDataMixin, TranslatedModelSerializer, munigeo_api.GeoModelSerializer ): purposes = PurposeSerializer(many=True) + people_capacity = serializers.IntegerField(source='people_capacity_lower') images = NestedResourceImageSerializer(many=True) equipment = ResourceEquipmentSerializer( many=True, read_only=True, source="resource_equipment" @@ -677,7 +678,7 @@ def __init__(self, *args, **kwargs): field_name="type__id", lookup_expr="in", widget=django_filters.widgets.CSVWidget ) people = django_filters.NumberFilter( - field_name="people_capacity", lookup_expr="gte" + field_name="people_capacity_lower", lookup_expr="gte" ) need_manual_confirmation = django_filters.BooleanFilter( field_name="need_manual_confirmation", widget=DRFFilterBooleanWidget @@ -721,7 +722,7 @@ def __init__(self, *args, **kwargs): ("type__name_fi", "type_name_fi"), ("type__name_en", "type_name_en"), ("type__name_sv", "type_name_sv"), - ("people_capacity", "people_capacity"), + ("people_capacity_lower", "people_capacity_lower"), ("accessibility_priority", "accessibility"), ), ) diff --git a/resources/importer/kirjasto10.py b/resources/importer/kirjasto10.py index 80101d9f1..38ea16571 100644 --- a/resources/importer/kirjasto10.py +++ b/resources/importer/kirjasto10.py @@ -94,9 +94,9 @@ def import_resources(self): except ValueError: area = None try: - people_capacity = int(res_data['Max henkilömäärä']) + people_capacity_lower = int(res_data['Max henkilömäärä']) except ValueError: - people_capacity = None + people_capacity_lower = None try: min_period = datetime.timedelta(minutes=int(60 * float(res_data['Varausaika min'].replace(',', '.')))) except ValueError: @@ -119,7 +119,7 @@ def import_resources(self): data = dict( unit_id=unit.pk, - people_capacity=people_capacity, + people_capacity_lower=people_capacity_lower, area=area, need_manual_confirmation=confirm, min_period=min_period, diff --git a/resources/migrations/0129_rename_people_capacity.py b/resources/migrations/0129_rename_people_capacity.py new file mode 100644 index 000000000..0aca609e7 --- /dev/null +++ b/resources/migrations/0129_rename_people_capacity.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.11 on 2025-01-09 10:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('resources', '0128_equipment_active'), + ] + + operations = [ + migrations.RenameField( + model_name='resource', + old_name='people_capacity', + new_name='people_capacity_lower', + ), + ] diff --git a/resources/models/resource.py b/resources/models/resource.py index f81c50480..75d9be75b 100644 --- a/resources/models/resource.py +++ b/resources/models/resource.py @@ -332,7 +332,7 @@ class Resource(ModifiableModel, AutoIdentifiedModel): max_length=20, choices=AUTHENTICATION_TYPES, ) - people_capacity = models.PositiveIntegerField( + people_capacity_lower = models.PositiveIntegerField( verbose_name=_("People capacity"), null=True, blank=True ) area = models.PositiveIntegerField( diff --git a/resources/tests/test_resource_api.py b/resources/tests/test_resource_api.py index f1f5d0581..5dbd138da 100644 --- a/resources/tests/test_resource_api.py +++ b/resources/tests/test_resource_api.py @@ -1487,34 +1487,34 @@ def test_order_by_filter(list_url, api_client, resource_in_unit, resource_in_uni assert response.data["results"][0]["type"]["id"] == resource_in_unit2.type.id # test resource people capacity - resource_in_unit.people_capacity = 1 + resource_in_unit.people_capacity_lower = 1 resource_in_unit.save() - resource_in_unit2.people_capacity = 50 + resource_in_unit2.people_capacity_lower = 50 resource_in_unit2.save() - response = api_client.get("%s?order_by=people_capacity" % list_url) + response = api_client.get("%s?order_by=people_capacity_lower" % list_url) assert response.status_code == 200 assert_response_objects(response, [resource_in_unit, resource_in_unit2]) assert ( - response.data["results"][0]["people_capacity"] - == resource_in_unit.people_capacity + response.data["results"][0]["people_capacity_lower"] + == resource_in_unit.people_capacity_lower ) assert ( - response.data["results"][1]["people_capacity"] - == resource_in_unit2.people_capacity + response.data["results"][1]["people_capacity_lower"] + == resource_in_unit2.people_capacity_lower ) - response = api_client.get("%s?order_by=-people_capacity" % list_url) + response = api_client.get("%s?order_by=-people_capacity_lower" % list_url) assert response.status_code == 200 assert_response_objects(response, [resource_in_unit, resource_in_unit2]) assert ( - response.data["results"][1]["people_capacity"] - == resource_in_unit.people_capacity + response.data["results"][1]["people_capacity_lower"] + == resource_in_unit.people_capacity_lower ) assert ( - response.data["results"][0]["people_capacity"] - == resource_in_unit2.people_capacity + response.data["results"][0]["people_capacity_lower"] + == resource_in_unit2.people_capacity_lower ) diff --git a/respa_admin/forms.py b/respa_admin/forms.py index 572e41185..c9086e310 100644 --- a/respa_admin/forms.py +++ b/respa_admin/forms.py @@ -240,7 +240,7 @@ class Meta: "equipment", "access_methods", "external_reservation_url", - "people_capacity", + "people_capacity_lower", "area", "min_period", "max_period", diff --git a/respa_admin/templates/respa_admin/resources/form/_booking.html b/respa_admin/templates/respa_admin/resources/form/_booking.html index 1cc9b7934..336f7ef2f 100644 --- a/respa_admin/templates/respa_admin/resources/form/_booking.html +++ b/respa_admin/templates/respa_admin/resources/form/_booking.html @@ -6,7 +6,7 @@

{% trans "Booking information" %}

{% trans "*Mandatory fields" %}
- {% include "respa_admin/forms/_input.html" with field=form.people_capacity %} + {% include "respa_admin/forms/_input.html" with field=form.people_capacity_lower %} {% include "respa_admin/forms/_input.html" with field=form.area %}
{% include "respa_admin/forms/_input.html" with field=form.people_capacity_lower %} + {% include "respa_admin/forms/_input.html" with field=form.people_capacity_upper %} {% include "respa_admin/forms/_input.html" with field=form.area %}