From fba719ab8d88892936420bfdacd0c1cfcf4c1381 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 19 Jan 2023 21:20:58 +0100 Subject: [PATCH] Ability for watch to use a more obvious system default fetcher (#1320) --- changedetectionio/__init__.py | 12 ++++++------ changedetectionio/fetch_site_status.py | 5 ++--- changedetectionio/forms.py | 3 ++- changedetectionio/static/js/watch-settings.js | 11 ++++++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index c629123e..5b9a2bb1 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -571,6 +571,8 @@ def changedetection_app(config=None, datastore_o=None): data=default, ) + form.fetch_backend.choices.append(("system", 'System settings default')) + # form.browser_steps[0] can be assumed that we 'goto url' first if datastore.proxy_list is None: @@ -599,10 +601,6 @@ def changedetection_app(config=None, datastore_o=None): using_default_check_time = False break - # Use the default if it's the same as system-wide. - if form.fetch_backend.data == datastore.data['settings']['application']['fetch_backend']: - extra_update_obj['fetch_backend'] = None - # Ignore text @@ -652,8 +650,10 @@ def changedetection_app(config=None, datastore_o=None): watch = datastore.data['watching'].get(uuid) system_uses_webdriver = datastore.data['settings']['application']['fetch_backend'] == 'html_webdriver' - is_html_webdriver = True if watch.get('fetch_backend') == 'html_webdriver' or ( - watch.get('fetch_backend', None) is None and system_uses_webdriver) else False + + is_html_webdriver = False + if (watch.get('fetch_backend') == 'system' and system_uses_webdriver) or watch.get('fetch_backend') == 'html_requests': + is_html_webdriver = True output = render_template("edit.html", browser_steps_config=browser_step_ui_config, diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index 5081205f..04b57367 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -92,9 +92,8 @@ class perform_site_check(): # Pluggable content fetcher prefer_backend = watch.get_fetch_backend - # @todo move this to Watch model get_fetch_backend - if not prefer_backend: - prefer_backend = self.datastore.data['settings']['application']['fetch_backend'] + if not prefer_backend or prefer_backend == 'system': + prefer_backend = self.datastore.data['settings']['application']['fetch_backend'] if hasattr(content_fetcher, prefer_backend): klass = getattr(content_fetcher, prefer_backend) diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index c2c3df93..8ef2112f 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -138,7 +138,7 @@ class ValidateContentFetcherIsReady(object): from changedetectionio import content_fetcher # Better would be a radiohandler that keeps a reference to each class - if field.data is not None: + if field.data is not None and field.data != 'system': klass = getattr(content_fetcher, field.data) some_object = klass() try: @@ -345,6 +345,7 @@ class quickWatchForm(Form): edit_and_watch_submit_button = SubmitField('Edit > Watch', render_kw={"class": "pure-button pure-button-primary"}) + # Common to a single watch and the global settings class commonSettingsForm(Form): notification_urls = StringListField('Notification URL List', validators=[validators.Optional(), ValidateAppRiseServers()]) diff --git a/changedetectionio/static/js/watch-settings.js b/changedetectionio/static/js/watch-settings.js index 902e12f4..353b23a3 100644 --- a/changedetectionio/static/js/watch-settings.js +++ b/changedetectionio/static/js/watch-settings.js @@ -1,7 +1,7 @@ -$(document).ready(function() { +$(document).ready(function () { function toggle() { if ($('input[name="fetch_backend"]:checked').val() == 'html_webdriver') { - if(playwright_enabled) { + if (playwright_enabled) { // playwright supports headers, so hide everything else // See #664 $('#requests-override-options #request-method').hide(); @@ -14,9 +14,14 @@ $(document).ready(function() { $('#requests-override-options').hide(); } - $('#webdriver-override-options').show(); + } else if ($('input[name="fetch_backend"]:checked').val() == 'system') { + $('#requests-override-options #request-method').hide(); + $('#requests-override-options #request-body').hide(); + $('#ignore-status-codes-option').hide(); + $('#requests-override-options').hide(); + $('#webdriver-override-options').hide(); } else { $('#requests-override-options').show();