From 6ecf0eb10468d6f8eddb5e1e673c8c14eb03b5b9 Mon Sep 17 00:00:00 2001 From: Jan Mach <jan.mach@cesnet.cz> Date: Fri, 21 Feb 2020 09:37:50 +0100 Subject: [PATCH] Added default 'detect time from' time boundary in case there are no time intervals defined. * If none of the following search parameters (dt_from, dt_to, st_from, st_to) is present in the URL, provide default dt_from (last 7 days) to reduce amount of processed events. * User still has the ability to perform unbound search by submitting empty form. (Redmine issue: #4609) --- lib/hawat/blueprints/events/__init__.py | 8 +++++++- lib/hawat/blueprints/timeline/__init__.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/hawat/blueprints/events/__init__.py b/lib/hawat/blueprints/events/__init__.py index 0144ccf95..e30495830 100644 --- a/lib/hawat/blueprints/events/__init__.py +++ b/lib/hawat/blueprints/events/__init__.py @@ -51,7 +51,7 @@ BLUEPRINT_NAME = 'events' def _get_search_form(request_args = None): choices = hawat.events.get_event_form_choices() - return SimpleEventSearchForm( + form = SimpleEventSearchForm( request_args, meta = {'csrf': False}, choices_source_types = choices['source_types'], @@ -66,6 +66,12 @@ def _get_search_form(request_args = None): choices_inspection_errs = choices['inspection_errs'], ) + # In case no time bounds were set adjust them manually. + if request_args and not ('dt_from' in request_args or 'dt_to' in request_args or 'st_from' in request_args or 'st_to' in request_args): + form.dt_from.process_data(hawat.forms.default_dt_with_delta()) + + return form + class AbstractSearchView(PsycopgMixin, BaseSearchView): # pylint: disable=locally-disabled,abstract-method """ diff --git a/lib/hawat/blueprints/timeline/__init__.py b/lib/hawat/blueprints/timeline/__init__.py index 95c086426..e0150797e 100644 --- a/lib/hawat/blueprints/timeline/__init__.py +++ b/lib/hawat/blueprints/timeline/__init__.py @@ -50,7 +50,7 @@ BLUEPRINT_NAME = 'timeline' def _get_search_form(request_args = None): choices = hawat.events.get_event_form_choices() - return SimpleTimelineSearchForm( + form = SimpleTimelineSearchForm( request_args, meta = {'csrf': False}, choices_source_types = choices['source_types'], @@ -65,6 +65,12 @@ def _get_search_form(request_args = None): choices_inspection_errs = choices['inspection_errs'], ) + # In case no time bounds were set adjust them manually. + if request_args and not ('dt_from' in request_args or 'dt_to' in request_args or 'st_from' in request_args or 'st_to' in request_args): + form.dt_from.process_data(hawat.forms.default_dt_with_delta()) + + return form + class AbstractSearchView(PsycopgMixin, BaseSearchView): # pylint: disable=locally-disabled,abstract-method """ -- GitLab