-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathforms.py
167 lines (141 loc) · 4.53 KB
/
forms.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from django import forms
from django.utils.translation import gettext_lazy as _
from entangled.forms import EntangledModelForm
from ... import settings
from ...fields import AttributesFormField, ButtonGroup, TagTypeFormField
from ...helpers import first_choice
from ...models import FrontendUIItem
from .. import modal
from .constants import (
MODAL_CENTERED_CHOICES,
MODAL_FULLSCREEN_CHOICES,
MODAL_INNER_TYPE_CHOICES,
MODAL_SIZE_CHOICES,
)
# TODO leaving this comment for now
# data-bs-toggle="modal" data-bs-target="#modalExample"
# aria-expanded="false" aria-controls="modalExample">
# data-bs-target can also be classes
# data-bs-parent links to the wrapper modal
# <div class="modal" id="modalExample">
mixin_factory = settings.get_forms(modal)
class ModalForm(mixin_factory("Modal"), EntangledModelForm):
"""
Component > "Modal" Plugin
https://getbootstrap.com/docs/5.0/components/modal/
"""
class Meta:
model = FrontendUIItem
entangled_fields = {
"config": [
"modal_siblings",
"attributes",
]
}
untangled_fields = ("tag_type",)
modal_siblings = forms.CharField(
label=_("Siblings"),
initial=".card",
required=False,
help_text=_("Element to be used to create accordions."),
)
attributes = AttributesFormField()
tag_type = TagTypeFormField()
class ModalTriggerForm(mixin_factory("ModalTrigger"), EntangledModelForm):
"""
Component > "Modal Trigger" Plugin
https://getbootstrap.com/docs/5.0/components/modal/
"""
class Meta:
model = FrontendUIItem
entangled_fields = {
"config": [
"trigger_identifier",
"attributes",
]
}
untangled_fields = ("tag_type",)
trigger_identifier = forms.SlugField(
label=_("Unique identifier"),
required=True,
help_text=_("Identifier to connect trigger with container."),
)
attributes = AttributesFormField()
tag_type = TagTypeFormField()
class ModalContainerForm(mixin_factory("ModalContainer"), EntangledModelForm):
"""
Component > "Modal Container" Plugin
https://getbootstrap.com/docs/5.0/components/modal/
"""
class Meta:
model = FrontendUIItem
entangled_fields = {
"config": [
"container_identifier",
"attributes",
"modal_centered",
"modal_static",
"modal_scrollable",
"modal_size",
"modal_fullscreen",
]
}
untangled_fields = ("tag_type",)
container_identifier = forms.SlugField(
label=_("Unique identifier"),
required=True,
help_text=_("Identifier to connect trigger with container."),
)
modal_centered = forms.ChoiceField(
label=_("Centered"),
choices=settings.EMPTY_CHOICE + MODAL_CENTERED_CHOICES,
required=False,
)
modal_static = forms.BooleanField(
label=_("Static"),
required=False,
help_text=_("Disable scrolling in the container."),
)
modal_scrollable = forms.BooleanField(
label=_("Scrollable"),
required=False,
help_text=_("Enable scrolling in the container."),
)
modal_size = forms.ChoiceField(
label=_("Size"),
choices=settings.EMPTY_CHOICE + MODAL_SIZE_CHOICES,
required=False,
)
modal_fullscreen = forms.ChoiceField(
label=_("Fullscreen"),
choices=settings.EMPTY_CHOICE + MODAL_FULLSCREEN_CHOICES,
required=False,
)
attributes = AttributesFormField()
tag_type = TagTypeFormField()
class ModalInnerForm(mixin_factory("ModalInner"), EntangledModelForm):
"""
Component > "Modal Container" Plugin
https://getbootstrap.com/docs/5.0/components/modal/
"""
class Meta:
model = FrontendUIItem
entangled_fields = {
"config": [
"inner_type",
]
}
untangled_fields = ("tag_type",)
inner_type = forms.ChoiceField(
label=_("Type"),
choices=settings.EMPTY_CHOICE + MODAL_INNER_TYPE_CHOICES,
required=True,
)
inner_type = forms.ChoiceField(
label=_("Inner type"),
choices=MODAL_INNER_TYPE_CHOICES,
initial=first_choice(MODAL_INNER_TYPE_CHOICES),
help_text=_("Define the structure of the plugin."),
widget=ButtonGroup(attrs=dict(label_class="btn-secondary")),
)
attributes = AttributesFormField()