Move give_theme_cookie to flasktools.
This commit is contained in:
parent
6ac1d8a90a
commit
f0d302d4a5
2 changed files with 5 additions and 23 deletions
|
@ -65,7 +65,11 @@ def decorate_and_route(*route_args, **route_kwargs):
|
||||||
# same one multiple times. The _fully_decorated will track that.
|
# same one multiple times. The _fully_decorated will track that.
|
||||||
if not hasattr(endpoint, '_fully_decorated'):
|
if not hasattr(endpoint, '_fully_decorated'):
|
||||||
endpoint = flasktools.ensure_response_type(endpoint)
|
endpoint = flasktools.ensure_response_type(endpoint)
|
||||||
endpoint = decorators.give_theme_cookie(endpoint)
|
endpoint = flasktools.give_theme_cookie(
|
||||||
|
endpoint,
|
||||||
|
cookie_name='etiquette_theme',
|
||||||
|
default_theme='slate',
|
||||||
|
)
|
||||||
endpoint = decorators.catch_etiquette_exception(endpoint)
|
endpoint = decorators.catch_etiquette_exception(endpoint)
|
||||||
endpoint = session_manager.give_token(endpoint)
|
endpoint = session_manager.give_token(endpoint)
|
||||||
|
|
||||||
|
|
|
@ -24,25 +24,3 @@ def catch_etiquette_exception(function):
|
||||||
response = flasktools.json_response(response, status=status)
|
response = flasktools.json_response(response, status=status)
|
||||||
flask.abort(response)
|
flask.abort(response)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
def give_theme_cookie(function):
|
|
||||||
@functools.wraps(function)
|
|
||||||
def wrapped(*args, **kwargs):
|
|
||||||
old_theme = request.cookies.get('etiquette_theme', None)
|
|
||||||
new_theme = request.args.get('theme', None)
|
|
||||||
theme = new_theme or old_theme or 'slate'
|
|
||||||
|
|
||||||
request.cookies = werkzeug.datastructures.MultiDict(request.cookies)
|
|
||||||
request.cookies['etiquette_theme'] = theme
|
|
||||||
|
|
||||||
response = function(*args, **kwargs)
|
|
||||||
|
|
||||||
if new_theme is None:
|
|
||||||
pass
|
|
||||||
elif new_theme == '':
|
|
||||||
response.set_cookie('etiquette_theme', value='', expires=0)
|
|
||||||
elif new_theme != old_theme:
|
|
||||||
response.set_cookie('etiquette_theme', value=new_theme, expires=2147483647)
|
|
||||||
|
|
||||||
return response
|
|
||||||
return wrapped
|
|
||||||
|
|
Loading…
Reference in a new issue