-
Notifications
You must be signed in to change notification settings - Fork 22
/
aldryn_config.py
42 lines (34 loc) · 1.28 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
from aldryn_client import forms
def split_and_strip(string):
return [item.strip() for item in string.split(",") if item]
class Form(forms.BaseForm):
templates = forms.CharField(
"List of additional templates (comma separated)",
required=False,
)
class_names = forms.CharField(
"List of classes (comma separated)",
required=False,
)
tag_types = forms.CharField(
"List of HTML tags (comma separated)",
required=False,
)
def clean(self):
data = super().clean()
# prettify
data["templates"] = ", ".join(split_and_strip(data["templates"]))
data["class_names"] = ", ".join(split_and_strip(data["class_names"]))
data["tag_types"] = ", ".join(split_and_strip(data["tag_types"]))
return data
def to_settings(self, data, settings):
if data["templates"]:
settings["DJANGOCMS_STYLE_TEMPLATES"] = [
(item, item)
for item in split_and_strip(data["templates"])
]
if data["class_names"]:
settings["DJANGOCMS_STYLE_CHOICES"] = split_and_strip(data["class_names"])
if data["tag_types"]:
settings["DJANGOCMS_STYLE_TAGS"] = split_and_strip(data["tag_types"])
return settings