-
Notifications
You must be signed in to change notification settings - Fork 3
/
styles.py
24 lines (17 loc) · 748 Bytes
/
styles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
from . settings import LASANA_DEFAULT_STYLE, LASANA_ALLOW_CHANGE_STYLE
basic_name = re.compile(r'^[a-zA-Z0-9_\-]+$')
def is_basic_name(style):
# Only allow style names with letters, numbers, underscore and hyphens
return bool(basic_name.match(style))
def get_style(request):
if not LASANA_ALLOW_CHANGE_STYLE:
return LASANA_DEFAULT_STYLE
style_from_session = request.session.get('style')
style_from_get = request.GET.get('style')
if style_from_get and not is_basic_name(style_from_get):
style_from_get = None
return style_from_get or style_from_session or LASANA_DEFAULT_STYLE
def set_style(request, style):
if style and is_basic_name(style):
request.session['style'] = style