mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
Attempt to get 'message' and 'tags' through a decorator
This commit is contained in:
26
digimarks.py
26
digimarks.py
@@ -6,6 +6,7 @@ import sys
|
|||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
import bs4
|
import bs4
|
||||||
|
from functools import update_wrapper
|
||||||
from more_itertools import unique_everseen
|
from more_itertools import unique_everseen
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
@@ -197,9 +198,25 @@ def get_tags_for_user(userkey):
|
|||||||
return clean_tags(tags)
|
return clean_tags(tags)
|
||||||
|
|
||||||
|
|
||||||
|
def request_vars(userkey):
|
||||||
|
def decorator(fn):
|
||||||
|
def wrapped_function(*args, **kwargs):
|
||||||
|
message = request.args.get('message')
|
||||||
|
try:
|
||||||
|
tags = all_tags[userkey]
|
||||||
|
tags = {}
|
||||||
|
except KeyError:
|
||||||
|
tags = {}
|
||||||
|
return fn(*args, **kwargs)
|
||||||
|
return update_wrapper(wrapped_function, fn)
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
#request_vars = decorator(get_request_vars)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
return render_template('404.html'), 404
|
return render_template('404.html', error=e), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@@ -210,6 +227,7 @@ def index():
|
|||||||
|
|
||||||
@app.route('/<userkey>', methods=['GET', 'POST'])
|
@app.route('/<userkey>', methods=['GET', 'POST'])
|
||||||
@app.route('/<userkey>/sort/<sortmethod>', methods=['GET', 'POST'])
|
@app.route('/<userkey>/sort/<sortmethod>', methods=['GET', 'POST'])
|
||||||
|
@request_vars(userkey)
|
||||||
def bookmarks(userkey, sortmethod = None):
|
def bookmarks(userkey, sortmethod = None):
|
||||||
""" User homepage, list their bookmarks, optionally filtered and/or sorted """
|
""" User homepage, list their bookmarks, optionally filtered and/or sorted """
|
||||||
#return object_list('bookmarks.html', Bookmark.select())
|
#return object_list('bookmarks.html', Bookmark.select())
|
||||||
@@ -219,15 +237,15 @@ def bookmarks(userkey, sortmethod = None):
|
|||||||
# return render_template('bookmarks.html', bookmarks)
|
# return render_template('bookmarks.html', bookmarks)
|
||||||
#else:
|
#else:
|
||||||
# abort(404)
|
# abort(404)
|
||||||
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),
|
||||||
Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
|
Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
|
||||||
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=all_tags[userkey], filter=filter_on, message=message)
|
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, filter=filter_on, message=message)
|
||||||
else:
|
else:
|
||||||
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
|
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
|
||||||
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=all_tags[userkey], message=message)
|
return render_template('bookmarks.html', bookmarks=bookmarks, userkey=userkey, tags=tags, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user