Skip to content
Snippets Groups Projects
Commit 7bd545d4 authored by Jan Mach's avatar Jan Mach
Browse files

Added defaults for both upper and lower threshold of detection time in timeline search form.

To enable search result caching. (Redmine issue: #6308)
parent eb1d9d40
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,7 @@ def _get_search_form(request_args = None):
# 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(vial.forms.default_dt_with_delta())
form.dt_to.process_data(vial.forms.default_dt())
return form
......
......@@ -55,7 +55,8 @@ class SimpleTimelineSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional()
],
description = lazy_gettext('Upper time boundary for event detection time as provided by event detector. Timestamp is expected to be in the format <code>YYYY-MM-DD hh:mm:ss</code> and in the timezone according to the user`s preferences. Event detectors are usually outside of the control of Mentat system administrators and may sometimes emit events with invalid detection times, for example timestamps in the future.')
description = lazy_gettext('Upper time boundary for event detection time as provided by event detector. Timestamp is expected to be in the format <code>YYYY-MM-DD hh:mm:ss</code> and in the timezone according to the user`s preferences. Event detectors are usually outside of the control of Mentat system administrators and may sometimes emit events with invalid detection times, for example timestamps in the future.'),
default = vial.forms.default_dt
)
st_from = vial.forms.SmartDateTimeField(
lazy_gettext('Storage time from:'),
......@@ -297,32 +298,21 @@ class SimpleTimelineSearchForm(flask_wtf.FlaskForm):
)
aggregations = wtforms.SelectMultipleField(
lazy_gettext('Restrict to aggregation calculations:'),
lazy_gettext('Restrict only to selected aggregation calculations:'),
validators = [
wtforms.validators.Optional()
],
filters = [lambda x: x or []],
description = lazy_gettext('Choose only which aggregation calculations to perform.')
)
dbtoplist = wtforms.RadioField(
lazy_gettext('Toplist in database:'),
validators = [
wtforms.validators.InputRequired(),
],
choices = [
(True, lazy_gettext('Enabled')),
(False, lazy_gettext('Disabled'))
],
default = False,
filters = [vial.forms.str_to_bool],
coerce = vial.forms.str_to_bool
description = lazy_gettext('Choose only which aggregation calculations to perform. When left empty all calculations will be performed.')
)
limit = wtforms.IntegerField(
lazy_gettext('Toplist limit:'),
validators = [
wtforms.validators.Optional()
wtforms.validators.Optional(),
wtforms.validators.NumberRange(min = 1, max = 1000)
],
default = 100
default = 100,
description = lazy_gettext('Perform toplisting to given limit for certain calculations like IP addresses and ports.')
)
submit = wtforms.SubmitField(
......
......@@ -375,12 +375,13 @@ ssh, udp
{{ macros_form.render_form_errors(g.search_form.classes.errors) }}
</div>
</div>
{%- if 'aggregations' in g.search_form %}
{%- if 'aggregations' in g.search_form and permission_can('power') %}
<hr>
<div class="form-group">
<div class="col-sm-6">
{{ get_icon('role-admin') }}
{%- call macros_form.render_form_label_help_html(g.search_form.aggregations) %}
{{ macros_form.render_help_idea_reference() }}
{%- endcall %}
......@@ -388,7 +389,12 @@ ssh, udp
{{ macros_form.render_form_errors(g.search_form.aggregations.errors) }}
</div>
<div class="col-sm-6">
{{ macros_form.render_form_item_radiobutton(g.search_form.dbtoplist) }}
{{ get_icon('role-admin') }}
{%- call macros_form.render_form_label_help_html(g.search_form.limit) %}
{{ macros_form.render_help_idea_reference() }}
{%- endcall %}
{{ g.search_form.limit(class_='form-control') }}
{{ macros_form.render_form_errors(g.search_form.limit.errors) }}
</div>
</div>
{%- endif %}
......
......@@ -28,10 +28,18 @@ def default_dt_with_delta(delta = 7):
Create default timestamp for datetime form values with given time delta in days
and adjust the result to whole hours.
"""
return datetime.datetime.now().replace(
hour = 0, minute = 0, second = 0, microsecond = 0
return datetime.datetime.utcnow().replace(
minute = 0, second = 0, microsecond = 0
) - datetime.timedelta(days = delta)
def default_dt():
"""
Create default timestamp for datetime form values with given time delta in days
and adjust the result to whole hours.
"""
return datetime.datetime.utcnow().replace(
minute = 0, second = 0, microsecond = 0
)
def str_to_bool(value):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment