From 74e832ec3a115ef385f9f034f73fe1613ff1264a Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Thu, 21 Jul 2016 15:41:17 +0200 Subject: [PATCH] Better tags in bookmarks, tag page works, filter form --- digimarks.py | 22 +++++++++++++++------ static/css/digimarks.css | 6 ++++++ templates/bookmarks.html | 41 +++++++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/digimarks.py b/digimarks.py index b8173da..e464327 100644 --- a/digimarks.py +++ b/digimarks.py @@ -178,8 +178,7 @@ def index(): return render_template('index.html') -@app.route('//') -@app.route('/') +@app.route('/', methods=['GET', 'POST']) def bookmarks(userkey): """ User homepage, list their (unfiltered) bookmarks """ #return object_list('bookmarks.html', Bookmark.select()) @@ -189,7 +188,11 @@ def bookmarks(userkey): # return render_template('bookmarks.html', bookmarks) #else: # abort(404) - bookmarks = Bookmark.select().where(Bookmark.userkey == userkey) + if request.method == 'POST': + filter_on = request.form['filter'] + bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.title % "%" + filter + "%") + else: + bookmarks = Bookmark.select().where(Bookmark.userkey == userkey) tags = get_tags_for_user(userkey) return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags) @@ -214,7 +217,7 @@ def viewbookmarkjson(userkey, urlhash): def editbookmark(userkey, urlhash): """ Bookmark edit form """ # bookmark = getbyurlhash() - bookmark = Bookmark.get(Bookmark.url_hash == urlhash) + bookmark = Bookmark.get(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey) print bookmark.url return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark) @@ -243,7 +246,12 @@ def addingbookmark(userkey): starred = False print starred if url: - bookmark = Bookmark(url=url, title=title, starred=starred, userkey=userkey) + #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 bookmark.set_tags(tags) bookmark.set_hash() #bookmark.fetch_image() @@ -281,7 +289,9 @@ def tags(userkey): @app.route('//tag/') def tag(userkey, tag): """ Overview of all bookmarks with a certain tag """ - return render_template('index.html') + bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.tags.contains(tag)) + tags = get_tags_for_user(userkey) + return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags) @app.route('//adduser') diff --git a/static/css/digimarks.css b/static/css/digimarks.css index f1af572..6174cb9 100644 --- a/static/css/digimarks.css +++ b/static/css/digimarks.css @@ -42,3 +42,9 @@ { color: #FFF; } + + .chip a, + .white-text .chip a + { + color: #1b5e20; /* green darken-4 */ + } diff --git a/templates/bookmarks.html b/templates/bookmarks.html index 596fd5d..83b4157 100644 --- a/templates/bookmarks.html +++ b/templates/bookmarks.html @@ -2,13 +2,28 @@ {% block title %}Bookmarks{% endblock %} {% block pageheader %}Bookmarks{% endblock %} {% block pagecontent %} + +
+
+
+ +
+ +
+

+
+
+
+ {% if tags %}
+

{% for tag in tags %}

{% endfor %} +

{% endif %} @@ -27,7 +42,6 @@
Added @ {{ bookmark.created_date.strftime('%Y-%m-%d %H:%M') }}close