mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 06:05:10 +01:00
More tagging: tag overview page, some refactoring
This commit is contained in:
31
digimarks.py
31
digimarks.py
@@ -47,6 +47,15 @@ def getkey():
|
|||||||
return os.urandom(24).encode('hex')
|
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):
|
class User(db.Model):
|
||||||
""" User account """
|
""" User account """
|
||||||
username = CharField()
|
username = CharField()
|
||||||
@@ -131,12 +140,8 @@ class Bookmark(db.Model):
|
|||||||
def set_tags(self, tags):
|
def set_tags(self, tags):
|
||||||
""" Set tags from `tags`, strip and sort them """
|
""" Set tags from `tags`, strip and sort them """
|
||||||
tags_split = tags.split(',')
|
tags_split = tags.split(',')
|
||||||
tags_split = [x.strip() for x in tags_split]
|
tags_clean = clean_tags(tags_split)
|
||||||
tags_split = list(unique_everseen(tags_split))
|
self.tags = ','.join(tags_clean)
|
||||||
tags_split.sort()
|
|
||||||
if tags_split[0] == '':
|
|
||||||
del tags_split[0]
|
|
||||||
self.tags = ','.join(tags_split)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tags_list(self):
|
def tags_list(self):
|
||||||
@@ -160,12 +165,11 @@ class Bookmark(db.Model):
|
|||||||
|
|
||||||
def get_tags_for_user(userkey):
|
def get_tags_for_user(userkey):
|
||||||
""" Extract all tags from the bookmarks """
|
""" Extract all tags from the bookmarks """
|
||||||
bookmarks = Bookmark.select(Bookmark.userkey == userkey)
|
bookmarks = Bookmark.select().filter(Bookmark.userkey == userkey)
|
||||||
tags = []
|
tags = []
|
||||||
for bookmark in bookmarks:
|
for bookmark in bookmarks:
|
||||||
these_tags = bookmark.tags.split(',')
|
tags += bookmark.tags_list
|
||||||
print these_tags
|
return clean_tags(tags)
|
||||||
return tags
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@@ -269,9 +273,16 @@ def deletingbookmark(userkey, urlhash):
|
|||||||
def tags(userkey):
|
def tags(userkey):
|
||||||
""" Overview of all tags used by user """
|
""" Overview of all tags used by user """
|
||||||
tags = get_tags_for_user(userkey)
|
tags = get_tags_for_user(userkey)
|
||||||
|
print tags
|
||||||
return render_template('tags.html', tags=tags, userkey=userkey)
|
return render_template('tags.html', tags=tags, userkey=userkey)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/<userkey>/tag/<tag>')
|
||||||
|
def tag(userkey, tag):
|
||||||
|
""" Overview of all bookmarks with a certain tag """
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<systemkey>/adduser')
|
@app.route('/<systemkey>/adduser')
|
||||||
def adduser(systemkey):
|
def adduser(systemkey):
|
||||||
""" Add user endpoint, convenience """
|
""" Add user endpoint, convenience """
|
||||||
|
|||||||
@@ -4,5 +4,11 @@
|
|||||||
{% block pagecontent %}
|
{% block pagecontent %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
|
{% for tag in tags %}
|
||||||
|
<div class="chip">
|
||||||
|
<a href="{{ url_for('tag', userkey=userkey, tag=tag) }}">{{ tag }}</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user