Centralize flask.render_template calls to simplify common args.
This commit is contained in:
parent
928e64fe08
commit
d7307a6c44
7 changed files with 24 additions and 25 deletions
|
@ -108,6 +108,15 @@ def P_user(username):
|
|||
def P_user_id(user_id):
|
||||
return P.get_user(id=user_id)
|
||||
|
||||
def render_template(request, *args, **kwargs):
|
||||
session = session_manager.get(request)
|
||||
ret = flask.render_template(
|
||||
session=session,
|
||||
theme=request.args.get('theme'),
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
return ret
|
||||
|
||||
def back_url():
|
||||
return request.args.get('goto') or request.referrer or '/'
|
||||
|
|
|
@ -19,11 +19,10 @@ session_manager = common.session_manager
|
|||
@session_manager.give_token
|
||||
def get_album_html(album_id):
|
||||
album = common.P_album(album_id)
|
||||
session = session_manager.get(request)
|
||||
response = flask.render_template(
|
||||
response = common.render_template(
|
||||
request,
|
||||
'album.html',
|
||||
album=album,
|
||||
session=session,
|
||||
view=request.args.get('view', 'grid'),
|
||||
)
|
||||
return response
|
||||
|
@ -174,11 +173,10 @@ def get_albums_core():
|
|||
@session_manager.give_token
|
||||
def get_albums_html():
|
||||
albums = get_albums_core()
|
||||
session = session_manager.get(request)
|
||||
response = flask.render_template(
|
||||
response = common.render_template(
|
||||
request,
|
||||
'album.html',
|
||||
albums=albums,
|
||||
session=session,
|
||||
view=request.args.get('view', 'grid'),
|
||||
)
|
||||
return response
|
||||
|
|
|
@ -13,8 +13,7 @@ session_manager = common.session_manager
|
|||
@session_manager.give_token
|
||||
def root():
|
||||
motd = random.choice(common.P.config['motd_strings'])
|
||||
session = session_manager.get(request)
|
||||
return flask.render_template('root.html', motd=motd, session=session)
|
||||
return common.render_template(request, 'root.html', motd=motd)
|
||||
|
||||
@site.route('/favicon.ico')
|
||||
@site.route('/favicon.png')
|
||||
|
|
|
@ -38,9 +38,8 @@ def post_bookmark_edit(bookmark_id):
|
|||
@site.route('/bookmarks')
|
||||
@session_manager.give_token
|
||||
def get_bookmarks_html():
|
||||
session = session_manager.get(request)
|
||||
bookmarks = list(common.P.get_bookmarks())
|
||||
return flask.render_template('bookmarks.html', bookmarks=bookmarks, session=session)
|
||||
return common.render_template(request, 'bookmarks.html', bookmarks=bookmarks)
|
||||
|
||||
@site.route('/bookmarks.json')
|
||||
@session_manager.give_token
|
||||
|
|
|
@ -23,8 +23,7 @@ photo_download_zip_tokens = cacheclass.Cache(maxlen=100)
|
|||
@session_manager.give_token
|
||||
def get_photo_html(photo_id):
|
||||
photo = common.P_photo(photo_id, response_type='html')
|
||||
session = session_manager.get(request)
|
||||
return flask.render_template('photo.html', photo=photo, session=session)
|
||||
return common.render_template(request, 'photo.html', photo=photo)
|
||||
|
||||
@site.route('/photo/<photo_id>.json')
|
||||
@session_manager.give_token
|
||||
|
@ -201,8 +200,7 @@ def post_batch_photos_unset_searchhidden():
|
|||
@site.route('/clipboard')
|
||||
@session_manager.give_token
|
||||
def get_clipboard_page():
|
||||
session = session_manager.get(request)
|
||||
return flask.render_template('clipboard.html', session=session)
|
||||
return common.render_template(request, 'clipboard.html')
|
||||
|
||||
@site.route('/batch/photos/photo_card', methods=['POST'])
|
||||
@decorators.required_fields(['photo_ids'], forbid_whitespace=True)
|
||||
|
@ -428,14 +426,13 @@ def get_search_core():
|
|||
def get_search_html():
|
||||
search_results = get_search_core()
|
||||
search_kwargs = search_results['search_kwargs']
|
||||
session = session_manager.get(request)
|
||||
response = flask.render_template(
|
||||
response = common.render_template(
|
||||
request,
|
||||
'search.html',
|
||||
next_page_url=search_results['next_page_url'],
|
||||
prev_page_url=search_results['prev_page_url'],
|
||||
photos=search_results['photos'],
|
||||
search_kwargs=search_kwargs,
|
||||
session=session,
|
||||
total_tags=search_results['total_tags'],
|
||||
warnings=search_results['warnings'],
|
||||
)
|
||||
|
|
|
@ -91,7 +91,6 @@ def get_tags_html(specific_tag_name=None):
|
|||
response = flask.redirect(new_url)
|
||||
return response
|
||||
|
||||
session = session_manager.get(request)
|
||||
include_synonyms = request.args.get('synonyms')
|
||||
include_synonyms = include_synonyms is None or etiquette.helpers.truthystring(include_synonyms)
|
||||
|
||||
|
@ -101,10 +100,10 @@ def get_tags_html(specific_tag_name=None):
|
|||
tags = [specific_tag]
|
||||
tags = etiquette.tag_export.easybake(tags, include_synonyms=False, with_objects=True)
|
||||
|
||||
response = flask.render_template(
|
||||
response = common.render_template(
|
||||
request,
|
||||
'tags.html',
|
||||
include_synonyms=include_synonyms,
|
||||
session=session,
|
||||
specific_tag=specific_tag,
|
||||
tags=tags,
|
||||
)
|
||||
|
|
|
@ -17,8 +17,7 @@ session_manager = common.session_manager
|
|||
@session_manager.give_token
|
||||
def get_user_html(username):
|
||||
user = common.P_user(username, response_type='html')
|
||||
session = session_manager.get(request)
|
||||
return flask.render_template('user.html', user=user, session=session)
|
||||
return common.render_template(request, 'user.html', user=user)
|
||||
|
||||
@site.route('/user/<username>.json')
|
||||
@session_manager.give_token
|
||||
|
@ -44,10 +43,9 @@ def get_user_id_redirect(user_id):
|
|||
@site.route('/login', methods=['GET'])
|
||||
@session_manager.give_token
|
||||
def get_login():
|
||||
session = session_manager.get(request)
|
||||
response = flask.render_template(
|
||||
response = common.render_template(
|
||||
request,
|
||||
'login.html',
|
||||
session=session,
|
||||
min_username_length=common.P.config['user']['min_username_length'],
|
||||
min_password_length=common.P.config['user']['min_password_length'],
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue