diff --git a/parkings/api/enforcement/valid_parking.py b/parkings/api/enforcement/valid_parking.py index a67257fe..2d33e64f 100644 --- a/parkings/api/enforcement/valid_parking.py +++ b/parkings/api/enforcement/valid_parking.py @@ -1,6 +1,7 @@ import datetime import django_filters +from django.conf import settings from django.utils import timezone from django.utils.translation import gettext_lazy as _ from rest_framework import permissions, serializers, viewsets @@ -76,11 +77,17 @@ def filter_time(self, queryset, name, value): valid_parkings = queryset.valid_at(time) if valid_parkings: return valid_parkings - day_ago = time - datetime.timedelta(days=1) - valid_within_limit = queryset.starts_before(time).ends_after(day_ago) + limit = time - get_time_old_parkings_visible() + valid_within_limit = queryset.starts_before(time).ends_after(limit) return valid_within_limit.order_by('-time_end')[:1] +def get_time_old_parkings_visible(default=datetime.timedelta(minutes=15)): + value = getattr(settings, 'PARKKIHUBI_TIME_OLD_PARKINGS_VISIBLE', None) + assert value is None or isinstance(value, datetime.timedelta) + return value if value is not None else default + + class ValidParkingViewSet(viewsets.ReadOnlyModelViewSet): queryset = Parking.objects.order_by('-time_end') serializer_class = ValidParkingSerializer diff --git a/parkings/tests/api/enforcement/test_valid_parking.py b/parkings/tests/api/enforcement/test_valid_parking.py index 7a761313..b3d2ce55 100644 --- a/parkings/tests/api/enforcement/test_valid_parking.py +++ b/parkings/tests/api/enforcement/test_valid_parking.py @@ -132,6 +132,8 @@ def test_registration_number_filter(operator, staff_api_client, parking_factory) 'after_start_of_2nd', 'before_end_of_2nd', 'at_end_of_2nd', + 'less_than_15min_after_2nd', + 'more_than_15min_after_2nd', 'less_than_day_after_2nd', 'more_than_day_after_2nd', 'now', @@ -158,7 +160,9 @@ def test_time_filtering(operator, staff_api_client, parking_factory, name): 'after_start_of_2nd': ('2014-01-01T12:00:01Z', [p2]), 'before_end_of_2nd': ('2016-01-01T11:59:59Z', [p2]), 'at_end_of_2nd': ('2016-01-01T12:00:00Z', [p2]), - 'less_than_day_after_2nd': ('2016-01-01T22:00:00Z', [p2]), + 'less_than_15min_after_2nd': ('2016-01-01T12:14:59Z', [p2]), + 'more_than_15min_after_2nd': ('2016-01-02T12:15:01Z', []), + 'less_than_day_after_2nd': ('2016-01-01T22:00:00Z', []), 'more_than_day_after_2nd': ('2016-01-02T13:00:00Z', []), 'now': ('', [p3]), }[name] diff --git a/parkkihubi/settings.py b/parkkihubi/settings.py index ebaeb7fc..e950ac7a 100644 --- a/parkkihubi/settings.py +++ b/parkkihubi/settings.py @@ -167,6 +167,7 @@ # Parkkihubi # ############## PARKKIHUBI_TIME_PARKINGS_EDITABLE = timedelta(minutes=2) +PARKKIHUBI_TIME_OLD_PARKINGS_VISIBLE = timedelta(minutes=15) PARKKIHUBI_PUBLIC_API_ENABLED = env.bool('PARKKIHUBI_PUBLIC_API_ENABLED', True) PARKKIHUBI_OPERATOR_API_ENABLED = env.bool('PARKKIHUBI_OPERATOR_API_ENABLED', True) PARKKIHUBI_ENFORCEMENT_API_ENABLED = (