Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .sanitizerconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,9 @@ msgstr "Tunnistautuminen"
msgid "People capacity"
msgstr "Henkilömäärä"

msgid "People capacity upper limit"
msgstr "Maksimihenkilömäärä"

msgid "Area (m2)"
msgstr "Pinta-ala (m2)"

Expand Down
3 changes: 3 additions & 0 deletions locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ msgstr "Autentisering"
msgid "People capacity"
msgstr "Kapacitet"

msgid "People capacity upper limit"
msgstr "Maximal kapacitet"

msgid "Area (m2)"
msgstr "Yta (m2)"

Expand Down
4 changes: 2 additions & 2 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions resources/api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -676,9 +677,7 @@ def __init__(self, *args, **kwargs):
type = django_filters.Filter(
field_name="type__id", lookup_expr="in", widget=django_filters.widgets.CSVWidget
)
people = django_filters.NumberFilter(
field_name="people_capacity", lookup_expr="gte"
)
people = django_filters.NumberFilter(method='filter_people_capacity')
need_manual_confirmation = django_filters.BooleanFilter(
field_name="need_manual_confirmation", widget=DRFFilterBooleanWidget
)
Expand Down Expand Up @@ -721,11 +720,16 @@ 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"),
),
)

def filter_people_capacity(self, queryset, name, value):
return queryset.filter(
Q(people_capacity_lower__gte=value) | Q(people_capacity_upper__gte=value)
)

def filter_is_favorite(self, queryset, name, value):
if not self.user.is_authenticated:
if value:
Expand Down
6 changes: 3 additions & 3 deletions resources/importer/kirjasto10.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions resources/migrations/0129_rename_people_capacity.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
18 changes: 18 additions & 0 deletions resources/migrations/0130_resource_people_capacity_upper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.11 on 2025-01-09 11:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('resources', '0129_rename_people_capacity'),
]

operations = [
migrations.AddField(
model_name='resource',
name='people_capacity_upper',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='People capacity upper limit'),
),
]
5 changes: 4 additions & 1 deletion resources/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ 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
)
people_capacity_upper = models.PositiveIntegerField(
verbose_name=_("People capacity upper limit"), null=True, blank=True
)
area = models.PositiveIntegerField(
verbose_name=_("Area (m2)"), null=True, blank=True
)
Expand Down
51 changes: 39 additions & 12 deletions resources/tests/test_resource_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -1645,3 +1645,30 @@ def test_query_counts(

with django_assert_max_num_queries(MAX_QUERIES):
staff_api_client.get(list_url)

@pytest.mark.django_db
def test_filter_people_capacity(api_client, resource_in_unit, resource_in_unit2, resource_in_unit3):
resource_in_unit.people_capacity_lower = 10
resource_in_unit.people_capacity_upper = 20
resource_in_unit.save()

resource_in_unit2.people_capacity_lower = 15
resource_in_unit2.people_capacity_upper = 25
resource_in_unit2.save()

resource_in_unit3.people_capacity_lower = 20
resource_in_unit3.people_capacity_upper = None
resource_in_unit3.save()

response = api_client.get(reverse("resource-list") + "?people=15")
assert response.status_code == 200
assert len(response.data["results"]) == 3

response = api_client.get(reverse("resource-list") + "?people=22")
assert response.status_code == 200
assert len(response.data["results"]) == 1
assert response.data["results"][0]["id"] == resource_in_unit2.id

response = api_client.get(reverse("resource-list") + "?people=50")
assert response.status_code == 200
assert len(response.data["results"]) == 0
3 changes: 2 additions & 1 deletion respa_admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class Meta:
"equipment",
"access_methods",
"external_reservation_url",
"people_capacity",
"people_capacity_lower",
"people_capacity_upper",
"area",
"min_period",
"max_period",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ <h2>{% trans "Booking information" %}</h2>
<span class="pull-right">{% trans "*Mandatory fields" %}</span>
</div>
<div class="input-row">
{% 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.people_capacity_upper %}
{% include "respa_admin/forms/_input.html" with field=form.area %}
</div>
<div class="input-row dropdown-row">
Expand Down
2 changes: 1 addition & 1 deletion respa_admin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"purposes": "",
"equipment": "",
"responsible_contact_info": "",
"people_capacity": "",
"people_capacity_lower": "",
"area": "",
"min_period": "",
"max_period": "",
Expand Down
Loading