diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index ed838ca6..6cd12eb9 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -413,11 +413,13 @@ def changedetection_app(config=None, datastore_o=None): tags=existing_tags, active_tag=limit_tag, app_rss_token=datastore.data['settings']['application']['rss_access_token'], - has_unviewed=datastore.data['has_unviewed'], + has_unviewed=datastore.has_unviewed, # Don't link to hosting when we're on the hosting environment hosted_sticky=os.getenv("SALTED_PASS", False) == False, guid=datastore.data['app_guid'], queued_uuids=update_q.queue) + + if session.get('share-link'): del(session['share-link']) return output @@ -746,15 +748,14 @@ def changedetection_app(config=None, datastore_o=None): return output # Clear all statuses, so we do not see the 'unviewed' class - @app.route("/api/mark-all-viewed", methods=['GET']) + @app.route("/form/mark-all-viewed", methods=['GET']) @login_required def mark_all_viewed(): # Save the current newest history as the most recently viewed for watch_uuid, watch in datastore.data['watching'].items(): - datastore.set_last_viewed(watch_uuid, watch.newest_history_key) + datastore.set_last_viewed(watch_uuid, int(time.time())) - flash("Cleared all statuses.") return redirect(url_for('index')) @app.route("/diff/", methods=['GET']) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index f884387f..cde2f456 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -66,7 +66,7 @@ class model(dict): @property def viewed(self): - if int(self.newest_history_key) <= int(self['last_viewed']): + if int(self['last_viewed']) >= int(self.newest_history_key) : return True return False diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 9960ed9c..3f000b9f 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -128,6 +128,7 @@ class ChangeDetectionStore: save_data_thread = threading.Thread(target=self.save_datastore).start() def set_last_viewed(self, uuid, timestamp): + logging.debug("Setting watch UUID: {} last viewed to {}".format(uuid, int(timestamp))) self.data['watching'][uuid].update({'last_viewed': int(timestamp)}) self.needs_write = True @@ -165,20 +166,20 @@ class ChangeDetectionStore: seconds += x * n return max(seconds, minimum_seconds_recheck_time) + @property + def has_unviewed(self): + for uuid, watch in self.__data['watching'].items(): + if watch.viewed == False: + return True + return False + @property def data(self): has_unviewed = False for uuid, watch in self.__data['watching'].items(): - #self.__data['watching'][uuid]['viewed']=True -# if int(watch.newest_history_key) <= int(watch['last_viewed']): -# self.__data['watching'][uuid]['viewed'] = True - - # else: -# self.__data['watching'][uuid]['viewed'] = False -# has_unviewed = True - # #106 - Be sure this is None on empty string, False, None, etc # Default var for fetch_backend + # @todo this may not be needed anymore, or could be easily removed if not self.__data['watching'][uuid]['fetch_backend']: self.__data['watching'][uuid]['fetch_backend'] = self.__data['settings']['application']['fetch_backend'] @@ -187,8 +188,6 @@ class ChangeDetectionStore: if not self.__data['settings']['application']['base_url']: self.__data['settings']['application']['base_url'] = env_base_url.strip('" ') - self.__data['has_unviewed'] = has_unviewed - return self.__data def get_all_tags(self): diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index 8036b411..eaf517d3 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -3,14 +3,15 @@ import time from flask import url_for from urllib.request import urlopen -from . util import set_original_response, set_modified_response, live_server_setup +from .util import set_original_response, set_modified_response, live_server_setup sleep_time_for_fetch_thread = 3 + # Basic test to check inscriptus is not adding return line chars, basically works etc def test_inscriptus(): from inscriptis import get_text - html_content="test!
ok man" + html_content = "test!
ok man" stripped_text_from_html = get_text(html_content) assert stripped_text_from_html == 'test!\nok man' @@ -82,7 +83,7 @@ def test_check_basic_change_detection_functionality(client, live_server): # re #16 should have the diff in here too assert b'(into ) which has this one new line' in res.data assert b'CDATA' in res.data - + assert expected_url.encode('utf-8') in res.data # Following the 'diff' link, it should no longer display as 'unviewed' even after we recheck it a few times @@ -101,7 +102,8 @@ def test_check_basic_change_detection_functionality(client, live_server): # It should report nothing found (no new 'unviewed' class) res = client.get(url_for("index")) assert b'unviewed' not in res.data - assert b'head title' not in res.data # Should not be present because this is off by default + assert b'Mark all viewed' not in res.data + assert b'head title' not in res.data # Should not be present because this is off by default assert b'test-endpoint' in res.data set_original_response() @@ -109,7 +111,8 @@ def test_check_basic_change_detection_functionality(client, live_server): # Enable auto pickup of in settings res = client.post( url_for("settings_page"), - data={"application-extract_title_as_title": "1", "requests-time_between_check-minutes": 180, 'application-fetch_backend': "html_requests"}, + data={"application-extract_title_as_title": "1", "requests-time_between_check-minutes": 180, + 'application-fetch_backend': "html_requests"}, follow_redirects=True ) @@ -118,11 +121,18 @@ def test_check_basic_change_detection_functionality(client, live_server): res = client.get(url_for("index")) assert b'unviewed' in res.data + assert b'Mark all viewed' in res.data + # It should have picked up the <title> assert b'head title' in res.data + # hit the mark all viewed link + res = client.get(url_for("mark_all_viewed"), follow_redirects=True) + + assert b'Mark all viewed' not in res.data + assert b'unviewed' not in res.data + # # Cleanup everything res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True) assert b'Deleted' in res.data -