mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 06:05:10 +01:00
Cache the tags
This commit is contained in:
13
digimarks.py
13
digimarks.py
@@ -42,6 +42,9 @@ try:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Cache the tags
|
||||||
|
all_tags = {}
|
||||||
|
|
||||||
|
|
||||||
def getkey():
|
def getkey():
|
||||||
return os.urandom(24).encode('hex')
|
return os.urandom(24).encode('hex')
|
||||||
@@ -193,15 +196,14 @@ def bookmarks(userkey):
|
|||||||
# return render_template('bookmarks.html', bookmarks)
|
# return render_template('bookmarks.html', bookmarks)
|
||||||
#else:
|
#else:
|
||||||
# abort(404)
|
# abort(404)
|
||||||
tags = get_tags_for_user(userkey)
|
|
||||||
message = request.args.get('message')
|
message = request.args.get('message')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
filter_on = request.form['filter']
|
filter_on = request.form['filter']
|
||||||
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.title.contains(filter_on))
|
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.title.contains(filter_on))
|
||||||
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, filter=filter_on, message=message)
|
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=all_tags, filter=filter_on, message=message)
|
||||||
else:
|
else:
|
||||||
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey)
|
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey)
|
||||||
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, message=message)
|
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=all_tags, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -283,9 +285,9 @@ def addingbookmark(userkey):
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
bookmark = updatebookmark(userkey, request)
|
bookmark = updatebookmark(userkey, request)
|
||||||
print bookmark
|
|
||||||
if type(bookmark).__name__ == 'Response':
|
if type(bookmark).__name__ == 'Response':
|
||||||
return bookmark
|
return bookmark
|
||||||
|
all_tags[user.key] = get_tags_for_user(user.key)
|
||||||
return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash))
|
return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash))
|
||||||
return redirect(url_for('add'))
|
return redirect(url_for('add'))
|
||||||
|
|
||||||
@@ -296,6 +298,7 @@ def editingbookmark(userkey, urlhash):
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
bookmark = updatebookmark(userkey, request, urlhash=urlhash)
|
bookmark = updatebookmark(userkey, request, urlhash=urlhash)
|
||||||
|
all_tags[user.key] = get_tags_for_user(user.key)
|
||||||
return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash))
|
return redirect(url_for('editbookmark', userkey=userkey, urlhash=bookmark.url_hash))
|
||||||
return redirect(url_for('add'))
|
return redirect(url_for('add'))
|
||||||
|
|
||||||
@@ -305,6 +308,7 @@ def deletingbookmark(userkey, urlhash):
|
|||||||
""" Delete the bookmark from form submit by <urlhash>/delete """
|
""" Delete the bookmark from form submit by <urlhash>/delete """
|
||||||
Bookmark.delete().where(Bookmark.userkey==userkey, Bookmark.url_hash==urlhash)
|
Bookmark.delete().where(Bookmark.userkey==userkey, Bookmark.url_hash==urlhash)
|
||||||
message = 'Bookmark deleted'
|
message = 'Bookmark deleted'
|
||||||
|
all_tags[user.key] = get_tags_for_user(user.key)
|
||||||
return redirect(url_for('bookmarks', userkey=userkey, message=message))
|
return redirect(url_for('bookmarks', userkey=userkey, message=message))
|
||||||
|
|
||||||
|
|
||||||
@@ -347,6 +351,7 @@ if __name__ == '__main__':
|
|||||||
users = User.select()
|
users = User.select()
|
||||||
print 'Current user keys:'
|
print 'Current user keys:'
|
||||||
for user in users:
|
for user in users:
|
||||||
|
all_tags[user.key] = get_tags_for_user(user.key)
|
||||||
print user.key
|
print user.key
|
||||||
|
|
||||||
# run the application
|
# run the application
|
||||||
|
|||||||
Reference in New Issue
Block a user