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/html_tools.py b/backend/html_tools.py index 904910d2..d71c4fbd 100644 --- a/backend/html_tools.py +++ b/backend/html_tools.py @@ -13,11 +13,14 @@ def css_filter(css_filter, html_content): # Extract/find element def extract_element(find='title', html_content=''): - html_title = False + + #Re #106, be sure to handle when its not found + element_text = None soup = BeautifulSoup(html_content, 'html.parser') - title = soup.find(find) - if title and title.string is not None: - html_title = title.string.strip() + result = soup.find(find) + if result and result.string: + element_text = result.string.strip() + + return element_text - return html_title diff --git a/backend/store.py b/backend/store.py index af1478c6..0289dd7d 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 @@ -185,6 +187,10 @@ class ChangeDetectionStore: self.__data['watching'][uuid]['viewed'] = False has_unviewed = True + # #106 - Be sure this is None on empty string, False, None, etc + if not self.__data['watching'][uuid]['title']: + self.__data['watching'][uuid]['title'] = None + self.__data['has_unviewed'] = has_unviewed return self.__data 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 +