From 082f1d3194f80adc6a5201845796d55d6d10ac80 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Fri, 22 Jul 2016 21:06:31 +0200 Subject: [PATCH] Update modified field, added some comments --- digimarks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/digimarks.py b/digimarks.py index 66b5b1c..a44005b 100644 --- a/digimarks.py +++ b/digimarks.py @@ -237,7 +237,7 @@ def addbookmark(userkey): def updatebookmark(userkey, request, urlhash = None): - """ Add or edit bookmark """ + """ Add (no urlhash) or edit (urlhash is set) a bookmark """ title = request.form.get('title') url = request.form.get('url') tags = request.form.get('tags') @@ -246,13 +246,16 @@ def updatebookmark(userkey, request, urlhash = None): starred = True if url and not urlhash: - #bookmark = Bookmark(url=url, title=title, starred=starred, userkey=userkey) + # New bookmark bookmark, created = Bookmark.get_or_create(url=url, userkey=userkey) if not created: message = 'Existing bookmark, did not overwrite with new values' return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash, message=message)) elif url: + # Existing bookmark, get from DB bookmark = Bookmark.get(userkey == userkey, Bookmark.url_hash == urlhash) + # Editing this bookmark, set modified_date to now + bookmark.modified_date = datetime.datetime.now() bookmark.title = title bookmark.url = url