From 4aae87a5346de601e1199ff95fd4777ac7d9ce2a Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Wed, 20 Jul 2016 22:45:07 +0200 Subject: [PATCH] More tagging: tag overview page, some refactoring --- digimarks.py | 31 +++++++++++++++++++++---------- templates/tags.html | 6 ++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/digimarks.py b/digimarks.py index e8915da..cfec245 100644 --- a/digimarks.py +++ b/digimarks.py @@ -47,6 +47,15 @@ def getkey(): return os.urandom(24).encode('hex') +def clean_tags(tags_list): + tags_res = [x.strip() for x in tags_list] + tags_res = list(unique_everseen(tags_res)) + tags_res.sort() + if tags_res and tags_res[0] == '': + del tags_res[0] + return tags_res + + class User(db.Model): """ User account """ username = CharField() @@ -131,12 +140,8 @@ class Bookmark(db.Model): def set_tags(self, tags): """ Set tags from `tags`, strip and sort them """ tags_split = tags.split(',') - tags_split = [x.strip() for x in tags_split] - tags_split = list(unique_everseen(tags_split)) - tags_split.sort() - if tags_split[0] == '': - del tags_split[0] - self.tags = ','.join(tags_split) + tags_clean = clean_tags(tags_split) + self.tags = ','.join(tags_clean) @property def tags_list(self): @@ -160,12 +165,11 @@ class Bookmark(db.Model): def get_tags_for_user(userkey): """ Extract all tags from the bookmarks """ - bookmarks = Bookmark.select(Bookmark.userkey == userkey) + bookmarks = Bookmark.select().filter(Bookmark.userkey == userkey) tags = [] for bookmark in bookmarks: - these_tags = bookmark.tags.split(',') - print these_tags - return tags + tags += bookmark.tags_list + return clean_tags(tags) @app.route('/') @@ -269,9 +273,16 @@ def deletingbookmark(userkey, urlhash): def tags(userkey): """ Overview of all tags used by user """ tags = get_tags_for_user(userkey) + print tags return render_template('tags.html', tags=tags, userkey=userkey) +@app.route('//tag/') +def tag(userkey, tag): + """ Overview of all bookmarks with a certain tag """ + return render_template('index.html') + + @app.route('//adduser') def adduser(systemkey): """ Add user endpoint, convenience """ diff --git a/templates/tags.html b/templates/tags.html index a31ca57..e9f3a82 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -4,5 +4,11 @@ {% block pagecontent %}
+ {% for tag in tags %} +
+ {{ tag }} +
+ {% endfor %} +
{% endblock %}