From f0d302d4a526b608f7cf66a5f396264a329dfeab Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 30 Oct 2021 17:29:43 -0700 Subject: [PATCH] Move give_theme_cookie to flasktools. --- frontends/etiquette_flask/backend/common.py | 6 ++++- .../etiquette_flask/backend/decorators.py | 22 ------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/frontends/etiquette_flask/backend/common.py b/frontends/etiquette_flask/backend/common.py index 89879bb..04e4d83 100644 --- a/frontends/etiquette_flask/backend/common.py +++ b/frontends/etiquette_flask/backend/common.py @@ -65,7 +65,11 @@ def decorate_and_route(*route_args, **route_kwargs): # same one multiple times. The _fully_decorated will track that. if not hasattr(endpoint, '_fully_decorated'): 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 = session_manager.give_token(endpoint) diff --git a/frontends/etiquette_flask/backend/decorators.py b/frontends/etiquette_flask/backend/decorators.py index 6dcf4b2..4257ec6 100644 --- a/frontends/etiquette_flask/backend/decorators.py +++ b/frontends/etiquette_flask/backend/decorators.py @@ -24,25 +24,3 @@ def catch_etiquette_exception(function): response = flasktools.json_response(response, status=status) flask.abort(response) 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