diff --git a/backend/__init__.py b/backend/__init__.py index ce2c20eb..602c446d 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -483,8 +483,13 @@ def changedetection_app(config=None, datastore_o=None): def api_watch_add(): global messages + url = request.form.get('url').strip() + if datastore.url_exists(url): + messages.append({'class': 'error', 'message': 'The URL {} already exists'.format(url)}) + return redirect(url_for('index')) + # @todo add_watch should throw a custom Exception for validation etc - new_uuid = datastore.add_watch(url=request.form.get('url').strip(), tag=request.form.get('tag').strip()) + new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip()) # Straight into the queue. update_q.put(new_uuid) diff --git a/backend/store.py b/backend/store.py index be5875fc..e51a0f61 100644 --- a/backend/store.py +++ b/backend/store.py @@ -211,7 +211,7 @@ class ChangeDetectionStore: def url_exists(self, url): # Probably their should be dict... - for watch in self.data['watching']: + for watch in self.data['watching'].values(): if watch['url'] == url: return True