From c7acf09cf9ea13faf7cc9fd0687be1a8b1b8e48d Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Thu, 21 Jul 2016 16:00:05 +0200 Subject: [PATCH] Check whether a bookmark (url) already existed, redirect with a warning --- digimarks.py | 13 ++++++++----- templates/edit.html | 11 +++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/digimarks.py b/digimarks.py index 227716f..a8bea1f 100644 --- a/digimarks.py +++ b/digimarks.py @@ -219,8 +219,9 @@ def editbookmark(userkey, urlhash): """ Bookmark edit form """ # bookmark = getbyurlhash() bookmark = Bookmark.get(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey) + message = request.args.get('message') print bookmark.url - return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark) + return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark, message=message) @app.route('//add') @@ -249,10 +250,12 @@ def addingbookmark(userkey): if url: #bookmark = Bookmark(url=url, title=title, starred=starred, userkey=userkey) bookmark, created = Bookmark.get_or_create(url=url, userkey=userkey) - print created - if created: - bookmark.title = title - bookmark.starred = starred + if not created: + return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash, message='Existing bookmark, did not overwrite with new values')) + + # Newly created, set properties + bookmark.title = title + bookmark.starred = starred bookmark.set_tags(tags) bookmark.set_hash() #bookmark.fetch_image() diff --git a/templates/edit.html b/templates/edit.html index 0f6623b..c62bdf7 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -17,6 +17,17 @@ {% endif %} + + {% if message %} +
+
+ + {{ message }} + +
+
+ {% endif %} +