This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
aldryn_config.py
64 lines (54 loc) · 2.05 KB
/
aldryn_config.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
from aldryn_client import forms
def split_and_strip(string):
return [item.strip() for item in string.split(',') if item]
class Form(forms.BaseForm):
grid_size = forms.NumberField(
'Maximum columns to support',
required=False
)
enable_glyphicons = forms.CheckboxField(
'Enable Glyphicons',
required=False,
initial=True,
help_text='If you disable this, remember to also update your sass config to not load the font.',
)
enable_fontawesome = forms.CheckboxField(
'Enable Fontawesome',
required=False,
initial=True,
help_text='If you disable this, remember to also update your sass config to not load the font.',
)
carousel_styles = forms.CharField(
'List of additional carousel styles (comma separated)',
required=False
)
def clean(self):
data = super(Form, self).clean()
# older versions of this addon had a bug where the values would be
# saved to settings.json as a list instead of a string.
if isinstance(data['carousel_styles'], list):
data['carousel_styles'] = ', '.join(data['carousel_styles'])
# prettify
data['carousel_styles'] = ', '.join(split_and_strip(data['carousel_styles']))
return data
def to_settings(self, data, settings):
choices = []
if data['grid_size']:
settings['ALDRYN_BOOTSTRAP3_GRID_SIZE'] = int(data['grid_size'])
if data['enable_glyphicons']:
choices.append(
('glyphicons', 'glyphicons', 'Glyphicons')
)
if data['enable_fontawesome']:
choices.append(
('fontawesome', 'fa', 'Font Awesome')
)
if choices:
settings['ALDRYN_BOOTSTRAP3_ICONSETS'] = choices
if data['carousel_styles']:
settings['ALDRYN_BOOTSTRAP3_CAROUSEL_STYLES'] = [
(item, item)
for item in split_and_strip(data['carousel_styles'])
]
return settings