From 27939b3f03766324b7e26b45fc13ede65886ac5e Mon Sep 17 00:00:00 2001 From: Mattia Mancini <mancini@astron.nl> Date: Thu, 16 Aug 2018 09:30:49 +0000 Subject: [PATCH] Story OSB-11: improving filtering --- .../monitoringdb/views/station_test_views.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/LCU/Maintenance/DBInterface/monitoringdb/views/station_test_views.py b/LCU/Maintenance/DBInterface/monitoringdb/views/station_test_views.py index dcb0159162b..87c1e2c0111 100644 --- a/LCU/Maintenance/DBInterface/monitoringdb/views/station_test_views.py +++ b/LCU/Maintenance/DBInterface/monitoringdb/views/station_test_views.py @@ -27,6 +27,16 @@ class ComponentViewSet(ReadOnlyModelViewSet): filter_fields = '__all__' +class StationTestFilterSet(filters.FilterSet): + station_name = filters.CharFilter(field_name='station__name', + lookup_expr='contains') + station_type = filters.CharFilter(field_name='station__type', + lookup_expr='contains') + + from_date = filters.DateFilter(field_name='start_datetime', lookup_expr='gt') + to_date = filters.DateFilter(field_name='end_datetime', lookup_expr='lt') + + class ComponentErrorFilterSet(filters.FilterSet): component_id = filters.NumberFilter(field_name='component', lookup_expr='component_id') component_type = filters.CharFilter(field_name='component', lookup_expr='type') @@ -34,7 +44,7 @@ class ComponentErrorFilterSet(filters.FilterSet): station_name = filters.CharFilter(field_name='station_test__station', lookup_expr='name__contains') station_type = filters.CharFilter(field_name='station_test__station', - lookup_expr='name__contains') + lookup_expr='type__contains') from_date = filters.DateFilter(field_name='station_test', lookup_expr='start_datetime__gt') to_date = filters.DateFilter(field_name='station_test', lookup_expr='end_datetime__lt') @@ -61,7 +71,10 @@ class ElementErrorFilterSet(filters.FilterSet): class ComponentErrorViewSet(ReadOnlyModelViewSet): serializer_class = ComponentErrorSerializer - queryset = ComponentError.objects.all().order_by('-station_test__start_datetime') + queryset = ComponentError.objects.all().order_by('-station_test__start_datetime', + 'type', + 'component__component_id', + 'station__name') filter_fields = '__all__' filterset_class = ComponentErrorFilterSet @@ -74,8 +87,9 @@ class StationViewSet(ReadOnlyModelViewSet): class StationTestViewSet(ReadOnlyModelViewSet): serializer_class = StationTestSerializer - queryset = StationTest.objects.all() + queryset = StationTest.objects.all().order_by('-start_datetime', 'station__name') filter_fields = '__all__' + filterset_class = StationTestFilterSet class ErrorDetailsViewSet(ReadOnlyModelViewSet): @@ -86,7 +100,10 @@ class ErrorDetailsViewSet(ReadOnlyModelViewSet): class ElementErrorViewSet(ReadOnlyModelViewSet): serializer_class = ElementErrorSerializer - queryset = ElementError.objects.all() + queryset = ElementError.objects.all().order_by('-station_test__start_datetime', + 'type', + 'component__component_id', + 'station__name') filter_fields = '__all__' -- GitLab