From b85af8904ab20a2e0b71e0bbe930748b45d5ea34 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 2 Jul 2021 12:14:09 +1000 Subject: [PATCH] #110 global recheck time (#113) * Re #106 - handling empty title with gettr cleanup * Re #110 - Global recheck time improvements, add tests, add form feedback, follow default minutes * Adding comments --- backend/__init__.py | 18 ++++- backend/store.py | 4 +- backend/templates/edit.html | 5 ++ backend/templates/settings.html | 2 + backend/tests/test_watch_fields_storage.py | 93 ++++++++++++++++++++++ 5 files changed, 120 insertions(+), 2 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 9c00e2d4..5d7b0dd1 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -380,6 +380,11 @@ def changedetection_app(config=None, datastore_o=None): populate_form_from_watch(form, datastore.data['watching'][uuid]) if request.method == 'POST' and form.validate(): + + # Re #110, if they submit the same as the default value, set it to None, so we continue to follow the default + if form.minutes_between_check.data == datastore.data['settings']['requests']['minutes_between_check']: + form.minutes_between_check.data = None + update_obj = {'url': form.url.data.strip(), 'minutes_between_check': form.minutes_between_check.data, 'tag': form.tag.data.strip(), @@ -428,7 +433,18 @@ def changedetection_app(config=None, datastore_o=None): if request.method == 'POST' and not form.validate(): flash("An error occurred, please see below.", "error") - output = render_template("edit.html", uuid=uuid, watch=datastore.data['watching'][uuid], form=form) + # Re #110 offer the default minutes + using_default_minutes = False + if form.minutes_between_check.data == None: + form.minutes_between_check.data = datastore.data['settings']['requests']['minutes_between_check'] + using_default_minutes = True + + output = render_template("edit.html", + uuid=uuid, + watch=datastore.data['watching'][uuid], + form=form, + using_default_minutes=using_default_minutes + ) return output diff --git a/backend/store.py b/backend/store.py index 9cc2e5a7..f5a19d7e 100644 --- a/backend/store.py +++ b/backend/store.py @@ -54,7 +54,9 @@ class ChangeDetectionStore: 'last_viewed': 0, # history key value of the last viewed via the [diff] link 'newest_history_key': "", 'title': None, - 'minutes_between_check': 3 * 60, # Default 3 hours + # Re #110, so then if this is set to None, we know to use the default value instead + # Requires setting to None on submit if it's the same as the default + 'minutes_between_check': None, 'previous_md5': "", 'uuid': str(uuid_builder.uuid4()), 'headers': {}, # Extra headers to send diff --git a/backend/templates/edit.html b/backend/templates/edit.html index eb794a60..3e828e49 100644 --- a/backend/templates/edit.html +++ b/backend/templates/edit.html @@ -15,6 +15,11 @@
{{ render_field(form.minutes_between_check, size=5) }} + {% if using_default_minutes %} + 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_field(form.css_filter, size=25, placeholder=".class-name or #some-id, or other CSS selector rule.") }} diff --git a/backend/templates/settings.html b/backend/templates/settings.html index 457e5f4b..177b834c 100644 --- a/backend/templates/settings.html +++ b/backend/templates/settings.html @@ -8,12 +8,14 @@
{{ render_field(form.minutes_between_check, size=5) }} + Default time for all watches, when the watch does not have a specific time setting.
{% if current_user.is_authenticated %} Remove password {% else %} {{ render_field(form.password, size=10) }} + Password protection for your changedetection.io application. {% endif %}
diff --git a/backend/tests/test_watch_fields_storage.py b/backend/tests/test_watch_fields_storage.py index 94089253..f9ee7634 100644 --- a/backend/tests/test_watch_fields_storage.py +++ b/backend/tests/test_watch_fields_storage.py @@ -50,3 +50,96 @@ def test_check_watch_field_storage(client, live_server): +# Re https://github.com/dgtlmoon/changedetection.io/issues/110 +def test_check_recheck_global_setting(client, live_server): + + res = client.post( + url_for("settings_page"), + data={ + "minutes_between_check": 1566, + }, + follow_redirects=True + ) + assert b"Settings updated." in res.data + + # Now add a record + + test_url = "http://somerandomsitewewatch.com" + + res = client.post( + url_for("import_page"), + data={"urls": test_url}, + follow_redirects=True + ) + assert b"1 Imported" in res.data + + # Now visit the edit page, it should have the default minutes + + res = client.get( + url_for("edit_page", uuid="first"), + follow_redirects=True + ) + + # Should show the default minutes + assert b"change to another value if you want to be specific" in res.data + assert b"1566" in res.data + + res = client.post( + url_for("settings_page"), + data={ + "minutes_between_check": 222, + }, + follow_redirects=True + ) + assert b"Settings updated." in res.data + + res = client.get( + url_for("edit_page", uuid="first"), + follow_redirects=True + ) + + # Should show the default minutes + assert b"change to another value if you want to be specific" in res.data + assert b"222" in res.data + + # Now change it specifically, it should show the new minutes + res = client.post( + url_for("edit_page", uuid="first"), + data={"url": test_url, + "minutes_between_check": 55, + }, + follow_redirects=True + ) + + res = client.get( + url_for("edit_page", uuid="first"), + follow_redirects=True + ) + assert b"55" in res.data + + # Now submit an empty field, it should give back the default global minutes + res = client.post( + url_for("settings_page"), + data={ + "minutes_between_check": 666, + }, + follow_redirects=True + ) + assert b"Settings updated." in res.data + + res = client.post( + url_for("edit_page", uuid="first"), + data={"url": test_url, + "minutes_between_check": "", + }, + follow_redirects=True + ) + + assert b"Updated watch." in res.data + + res = client.get( + url_for("edit_page", uuid="first"), + follow_redirects=True + ) + assert b"666" in res.data +