From c341baf71bddd3f99b24ee393903b875ac88a2fc Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 4 Nov 2022 16:58:28 +0100 Subject: [PATCH] Re #1086 basic time schedule limits for watches --- changedetectionio/__init__.py | 13 ++--------- changedetectionio/forms.py | 24 +++++++++++++++++++++ changedetectionio/model/Watch.py | 1 + changedetectionio/static/styles/styles.css | 16 +++++++++++++- changedetectionio/static/styles/styles.scss | 22 +++++++++++++++++++ changedetectionio/templates/edit.html | 8 +++---- changedetectionio/templates/settings.html | 1 + 7 files changed, 68 insertions(+), 17 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 096c7752b..7840a360c 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -566,23 +566,12 @@ def changedetection_app(config=None, datastore_o=None): for p in datastore.proxy_list: form.proxy.choices.append(tuple((p, datastore.proxy_list[p]['label']))) - if request.method == 'POST' and form.validate(): extra_update_obj = {} if request.args.get('unpause_on_save'): extra_update_obj['paused'] = False - # Re #110, if they submit the same as the default value, set it to None, so we continue to follow the default - # Assume we use the default value, unless something relevant is different, then use the form value - # values could be None, 0 etc. - # Set to None unless the next for: says that something is different - extra_update_obj['time_between_check'] = dict.fromkeys(form.time_between_check.data) - for k, v in form.time_between_check.data.items(): - if v and v != datastore.data['settings']['requests']['time_between_check'][k]: - extra_update_obj['time_between_check'] = form.time_between_check.data - using_default_check_time = False - break # Use the default if its the same as system wide if form.fetch_backend.data == datastore.data['settings']['application']['fetch_backend']: @@ -634,6 +623,8 @@ def changedetection_app(config=None, datastore_o=None): visualselector_data_is_ready = datastore.visualselector_data_is_ready(uuid) + + # Only works reliably with Playwright visualselector_enabled = os.getenv('PLAYWRIGHT_DRIVER_URL', False) and default['fetch_backend'] == 'html_webdriver' diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index 7f857d0ca..f52b0a24d 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -8,9 +8,11 @@ from wtforms import ( PasswordField, RadioField, SelectField, + SelectMultipleField, StringField, SubmitField, TextAreaField, + TimeField, fields, validators, widgets, @@ -97,6 +99,26 @@ class TimeBetweenCheckForm(Form): seconds = IntegerField('Seconds', validators=[validators.Optional(), validators.NumberRange(min=0, message="Should contain zero or more seconds")]) # @todo add total seconds minimum validatior = minimum_seconds_recheck_time +class MultiCheckboxDayOfWeekField(SelectMultipleField): + widget = widgets.ListWidget(prefix_label=False) + option_widget = widgets.CheckboxInput() + + def _choices_generator(self, choices): + _choices = [] + i=0 + for d in ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']: + _choices.append((i, d)) + i += 1 + + for value, label in _choices: + selected = self.data is not None and self.coerce(value) in self.data + yield (value, label, selected) + +class TimeScheduleCheckLimitForm(Form): + day_of_week = MultiCheckboxDayOfWeekField('',coerce=int) + from_time = TimeField('From') + until_time = TimeField('Until') + # Separated by key:value class StringDictKeyValue(StringField): widget = widgets.TextArea() @@ -348,6 +370,7 @@ class watchForm(commonSettingsForm): tag = StringField('Group tag', [validators.Optional()], default='') time_between_check = FormField(TimeBetweenCheckForm) + time_schedule_check_limit = FormField(TimeScheduleCheckLimitForm) include_filters = StringListField('CSS/JSONPath/JQ/XPath Filters', [ValidateCSSJSONXPATHInput()], default='') @@ -393,6 +416,7 @@ class watchForm(commonSettingsForm): # datastore.data['settings']['requests'].. class globalSettingsRequestForm(Form): time_between_check = FormField(TimeBetweenCheckForm) + time_schedule_check_limit = FormField(TimeScheduleCheckLimitForm) proxy = RadioField('Proxy') jitter_seconds = IntegerField('Random jitter seconds ± check', render_kw={"style": "width: 5em;"}, diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 573ef47ca..a8777cf12 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -52,6 +52,7 @@ class model(dict): # Requires setting to None on submit if it's the same as the default # Should be all None by default, so we use the system default in this case. 'time_between_check': {'weeks': None, 'days': None, 'hours': None, 'minutes': None, 'seconds': None}, + 'time_schedule_check_limit': {'day_of_week': [1,1,1,1,1,1,1], 'time_from': '', 'time_until': ''}, 'webdriver_delay': None, 'webdriver_js_execute_code': None, # Run before change-detection } diff --git a/changedetectionio/static/styles/styles.css b/changedetectionio/static/styles/styles.css index 9835c9b0f..04b1d226b 100644 --- a/changedetectionio/static/styles/styles.css +++ b/changedetectionio/static/styles/styles.css @@ -132,7 +132,7 @@ body:after, body:before { .fetch-error { padding-top: 1em; - font-size: 60%; + font-size: 80%; max-width: 400px; display: block; } @@ -480,6 +480,20 @@ ul { .time-check-widget tr input[type="number"] { width: 5em; } +.pure-control-group table label { + color: #333; + font-weight: normal; } + +.time-schedule-check-limit-widget tr { + display: inline-block; } + +.time-schedule-check-limit-widget li { + text-decoration: none; } + +.time-schedule-check-limit-widget ul li { + display: inline-block; + width: 3em; } + #selector-wrapper { height: 600px; overflow-y: scroll; diff --git a/changedetectionio/static/styles/styles.scss b/changedetectionio/static/styles/styles.scss index c2772d323..468c80b6d 100644 --- a/changedetectionio/static/styles/styles.scss +++ b/changedetectionio/static/styles/styles.scss @@ -677,6 +677,28 @@ ul { } } } +.pure-control-group table label { + color: #333; + font-weight: normal; +} + +.time-schedule-check-limit-widget { + tr { + display: inline-block; + } + + li { + text-decoration: none; + } + + ul { + li { + display: inline-block; + width: 3em; + } + } +} + #selector-wrapper { height: 600px; diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index e7cd5b063..d5fdcdb15 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -52,13 +52,11 @@
{{ render_field(form.time_between_check, class="time-check-widget") }} + {{ render_field(form.time_schedule_check_limit, class="time-schedule-check-limit-widget") }} +@todo - add 'use default' checkbox {% if has_empty_checktime %} - Currently using the default global settings, change to another value if you want to be specific. - {% else %} - Set to blank to use the default global settings. {% endif %} +
{{ render_checkbox_field(form.extract_title_as_title) }} diff --git a/changedetectionio/templates/settings.html b/changedetectionio/templates/settings.html index c912105e8..a6d7d6386 100644 --- a/changedetectionio/templates/settings.html +++ b/changedetectionio/templates/settings.html @@ -30,6 +30,7 @@
{{ render_field(form.requests.form.time_between_check, class="time-check-widget") }} + {{ render_field(form.requests.form.time_schedule_check_limit, class="time-schedule-check-limit-widget") }} Default time for all watches, when the watch does not have a specific time setting.