yafowil.widget.array 1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ from yafowil.base import factory
2
+ from yafowil.utils import entry_point
3
+ import os
4
+
5
+
6
+ resourcedir = os.path.join(os.path.dirname(__file__), 'resources')
7
+ js = [{
8
+ 'group': 'yafowil.widget.array.common',
9
+ 'resource': 'widget.js',
10
+ 'order': 20,
11
+ }]
12
+ default_css = [{
13
+ 'group': 'yafowil.widget.array.common',
14
+ 'resource': 'default/widget.css',
15
+ 'order': 20,
16
+ }]
17
+ bootstrap_css = [{
18
+ 'group': 'yafowil.widget.array.common',
19
+ 'resource': 'bootstrap/widget.css',
20
+ 'order': 20,
21
+ }]
22
+ plone5_css = [{
23
+ 'group': 'yafowil.widget.array.common',
24
+ 'resource': 'plone5/widget.css',
25
+ 'order': 20,
26
+ }]
27
+
28
+
29
+ @entry_point(order=10)
30
+ def register():
31
+ from yafowil.widget.array import widget # noqa
32
+ factory.register_theme('default', 'yafowil.widget.array',
33
+ resourcedir, js=js, css=default_css)
34
+ factory.register_theme('bootstrap', 'yafowil.widget.array',
35
+ resourcedir, js=js, css=bootstrap_css)
36
+ factory.register_theme('plone5', 'yafowil.widget.array',
37
+ resourcedir, js=js, css=plone5_css)
@@ -0,0 +1,377 @@
1
+ from yafowil.base import factory
2
+
3
+
4
+ DOC_ARRAY_WITH_LEAFS = """
5
+ Array with single fields as array entries
6
+ -----------------------------------------
7
+
8
+ Array containing single field entries. Preset value is expected as list.
9
+
10
+ .. code-block:: python
11
+
12
+ value = ['1', '2', '3']
13
+ array = factory('#array', value=value, props={
14
+ 'label': 'My Array',
15
+ 'help': 'I am an array',
16
+ 'required': 'Array must at least contain one entry',
17
+ })
18
+ array['field'] = factory('#arrayfield:text', props={
19
+ 'label': 'Entry',
20
+ 'help': 'I am an array entry',
21
+ 'required': 'Entry must not be empty',
22
+ })
23
+ """
24
+
25
+
26
+ def array_with_leafs():
27
+ form = factory('fieldset',
28
+ name='yafowil.widget.array.array_with_leafs')
29
+ value = ['1', '2', '3']
30
+ arr = form['array'] = factory('#array', value=value, props={
31
+ 'label': 'My Array',
32
+ 'help': 'I am an array',
33
+ 'required': 'Array must at least contain one entry',
34
+ })
35
+ arr['field'] = factory('#arrayfield:text', props={
36
+ 'label': 'Entry',
37
+ 'help': 'I am an array entry',
38
+ 'required': 'Entry must not be empty',
39
+ })
40
+ return {
41
+ 'widget': form,
42
+ 'doc': DOC_ARRAY_WITH_LEAFS,
43
+ 'title': 'Single field array',
44
+ }
45
+
46
+
47
+ DOC_ARRAY_WITH_COMPOUNDS = """
48
+ Array with compounds as array entries
49
+ -------------------------------------
50
+
51
+ Array containing compound entries. Preset value is expected as list containing
52
+ dictionaries addressing array child compound fields by key.
53
+
54
+ .. code-block:: python
55
+
56
+ value = [
57
+ {'f1': 'Value 1.1 F1', 'f2': 'Value 1.2 F2'},
58
+ {'f1': 'Value 2.1 F1', 'f2': 'Value 2.2 F2'},
59
+ ]
60
+ array = factory('#array', value=value, props={
61
+ 'label': 'Compound Array'
62
+ 'required': 'Array must at least contain one entry',
63
+ })
64
+ compound = array['compound'] = factory('compound')
65
+ compound['f1'] = factory('#arrayfield:text', props={
66
+ 'label': 'Field 1',
67
+ })
68
+ compound['f2'] = factory('#arrayfield:text', props={
69
+ 'label': 'Field 2',
70
+ 'required': 'Field 2 is required',
71
+ })
72
+ """
73
+
74
+
75
+ def array_with_compounds():
76
+ form = factory('fieldset',
77
+ name='yafowil.widget.array.array_with_compounds')
78
+ value = [
79
+ {'f1': 'Value 1.1 F1', 'f2': 'Value 1.2 F2'},
80
+ {'f1': 'Value 2.1 F1', 'f2': 'Value 2.2 F2'},
81
+ ]
82
+ arr = form['array'] = factory('#array', value=value, props={
83
+ 'label': 'Compound Array',
84
+ 'required': 'Array must at least contain one entry',
85
+ })
86
+ comp = arr['compound'] = factory('compound')
87
+ comp['f1'] = factory('#arrayfield:text', props={
88
+ 'label': 'Field 1',
89
+ })
90
+ comp['f2'] = factory('#arrayfield:text', props={
91
+ 'label': 'Field 2',
92
+ 'required': 'Field 2 is required',
93
+ })
94
+ return {
95
+ 'widget': form,
96
+ 'doc': DOC_ARRAY_WITH_COMPOUNDS,
97
+ 'title': 'Compound field array',
98
+ }
99
+
100
+
101
+ DOC_ARRAY_WITH_ARRAY_WITH_LEAFS = """
102
+ Array in array with single fields
103
+ ---------------------------------
104
+
105
+ Array in array containing single field entries. Preset value is a 2-dimensional
106
+ list
107
+
108
+ .. code-block:: python
109
+
110
+ value = [['1', '2'], ['3', '4'], ['5', '6']]
111
+ array = factory('#array', value=value, props={
112
+ 'label': 'Array',
113
+ 'required': 'Array must at least contain one entry',
114
+ })
115
+ subarray = array['subarray'] = factory('error:array', props={
116
+ 'label': 'Subarray',
117
+ 'required': 'Subarray must at least contain one entry',
118
+ })
119
+ subarray['field'] = factory('#arrayfield:text', props={
120
+ 'label': 'Entry',
121
+ 'required': 'Entry must not be empty',
122
+ })
123
+ """
124
+
125
+
126
+ def array_with_array_with_leafs():
127
+ form = factory('fieldset',
128
+ name='yafowil.widget.array_with_array_with_leafs')
129
+ value = [['1', '2'], ['3', '4'], ['5', '6']]
130
+ arr = form['array'] = factory('#array', value=value, props={
131
+ 'label': 'Array',
132
+ 'required': 'Array must at least contain one entry',
133
+ })
134
+ subarr = arr['subarray'] = factory('error:array', props={
135
+ 'label': 'Subarray',
136
+ 'required': 'Subarray must at least contain one entry',
137
+ })
138
+ subarr['field'] = factory('#arrayfield:text', props={
139
+ 'label': 'Entry',
140
+ 'required': 'Entry must not be empty',
141
+ })
142
+ return {
143
+ 'widget': form,
144
+ 'doc': DOC_ARRAY_WITH_ARRAY_WITH_LEAFS,
145
+ 'title': 'Single field array in array',
146
+ }
147
+
148
+
149
+ DOC_ARRAY_WITH_ARRAY_WITH_COMPOUNDS = """\
150
+ Array in array with compounds as array entries
151
+ ----------------------------------------------
152
+
153
+ Array in array containing compound entries. Preset value is lists in list
154
+ containing dictionaries addressing inner array child compound fields by key.
155
+
156
+ .. code-block:: python
157
+
158
+ value = [
159
+ [{
160
+ 'f1': 'Value 0.0 F1',
161
+ 'f2': 'Value 0.0 F2',
162
+ }, {
163
+ 'f1': 'Value 0.1 F1',
164
+ 'f2': 'Value 0.1 F2',
165
+ }], [{
166
+ 'f1': 'Value 1.0 F1',
167
+ 'f2': 'Value 1.0 F2',
168
+ }, {
169
+ 'f1': 'Value 1.1 F1',
170
+ 'f2': 'Value 1.1 F2',
171
+ }]
172
+ ]
173
+ array = factory('#array', value=value, props={
174
+ 'label': 'Array 1',
175
+ })
176
+ subarray = array['subarray'] = factory('array', props={
177
+ 'label': 'Array 2',
178
+ })
179
+ compound = subarray['comp'] = factory('compound')
180
+ compound['f1'] = factory('#arrayfield:text', props={
181
+ 'label': 'F1',
182
+ })
183
+ compound['f2'] = factory('#arrayfield:text', props={
184
+ 'label': 'F2',
185
+ 'required': 'F2 is required',
186
+ })
187
+ """
188
+
189
+
190
+ def array_with_array_with_compounds():
191
+ form = factory('fieldset',
192
+ name='yafowil.widget.array_with_array_with_compounds')
193
+ value = [
194
+ [{
195
+ 'f1': 'Value 0.0 F1',
196
+ 'f2': 'Value 0.0 F2',
197
+ }, {
198
+ 'f1': 'Value 0.1 F1',
199
+ 'f2': 'Value 0.1 F2',
200
+ }], [{
201
+ 'f1': 'Value 1.0 F1',
202
+ 'f2': 'Value 1.0 F2',
203
+ }, {
204
+ 'f1': 'Value 1.1 F1',
205
+ 'f2': 'Value 1.1 F2',
206
+ }]
207
+ ]
208
+ arr = form['array'] = factory('#array', value=value, props={
209
+ 'label': 'Array 1',
210
+ })
211
+ subarr = arr['subarray'] = factory('array', props={
212
+ 'label': 'Array 2',
213
+ })
214
+ comp = subarr['comp'] = factory('compound')
215
+ comp['f1'] = factory('#arrayfield:text', props={
216
+ 'label': 'F1',
217
+ })
218
+ comp['f2'] = factory('#arrayfield:text', props={
219
+ 'label': 'F2',
220
+ 'required': 'F2 is required',
221
+ })
222
+ return {
223
+ 'widget': form,
224
+ 'doc': DOC_ARRAY_WITH_ARRAY_WITH_COMPOUNDS,
225
+ 'title': 'Compound array in array',
226
+ }
227
+
228
+
229
+ DOC_ARRAY_WITH_ARRAY_WITH_ARRAY_WITH_LEAFS = """\
230
+ 3-Dimensional Array with single fields
231
+ --------------------------------------
232
+
233
+ 3-Dimensional array containing single field entries. Preset value is a
234
+ 3-dimensional list
235
+
236
+ .. code-block:: python
237
+
238
+ value = [[['1', '2'], ['3']], [['4', '5']]]
239
+ arr_1 = factory('#array', value=value, props={
240
+ 'label': 'Array 1',
241
+ 'help': 'This is Array 1',
242
+ 'required': 'Array 1 must not be empty',
243
+ })
244
+ arr_2 = arr_1['array_2'] = factory('help:error:array', props={
245
+ 'label': 'Array 2',
246
+ 'help': 'This is Array 2',
247
+ 'required': 'Array 2 must not be empty',
248
+ })
249
+ arr_3 = arr_2['array_3'] = factory('help:error:array', props={
250
+ 'label': 'Array 3',
251
+ 'help': 'This is Array 3',
252
+ 'required': 'Array 3 must not be empty',
253
+ })
254
+ arr_3['field'] = factory('#arrayfield:text', props={
255
+ 'label': 'Text Field',
256
+ 'help': 'This is the text field',
257
+ 'required': 'Text Field is required',
258
+ })
259
+ """
260
+
261
+
262
+ def array_with_array_with_array_with_leafs():
263
+ form = factory(
264
+ 'fieldset',
265
+ name='yafowil.widget.array_with_array_with_array_with_leafs')
266
+ value = [[['1', '2'], ['3']], [['4', '5']]]
267
+ arr_1 = form['array_1'] = factory('#array', value=value, props={
268
+ 'label': 'Array 1',
269
+ 'help': 'This is Array 1',
270
+ 'required': 'Array 1 must not be empty',
271
+ })
272
+ arr_2 = arr_1['array_2'] = factory('help:error:array', props={
273
+ 'label': 'Array 2',
274
+ 'help': 'This is Array 2',
275
+ 'required': 'Array 2 must not be empty',
276
+ })
277
+ arr_3 = arr_2['array_3'] = factory('help:error:array', props={
278
+ 'label': 'Array 3',
279
+ 'help': 'This is Array 3',
280
+ 'required': 'Array 3 must not be empty',
281
+ })
282
+ arr_3['textfield'] = factory('#arrayfield:text', props={
283
+ 'label': 'Text Field',
284
+ 'help': 'This is the text field',
285
+ 'required': 'Text Field is required',
286
+ })
287
+ return {
288
+ 'widget': form,
289
+ 'doc': DOC_ARRAY_WITH_ARRAY_WITH_ARRAY_WITH_LEAFS,
290
+ 'title': 'Single fields in 3-dimensional array',
291
+ }
292
+
293
+
294
+ DOC_ARRAY_WITH_ARRAY_WITH_ARRAY_WITH_COMPOUNDS = """\
295
+ 3-Dimensional Array with compounds
296
+ ----------------------------------
297
+
298
+ 3-Dimensional array containing compound entries. Preset value is a
299
+ 3-dimensional list containing dictionaries addressing most inner array child
300
+ compound fields by key.
301
+
302
+ .. code-block:: python
303
+
304
+ value = [
305
+ [[{
306
+ 'f1': 'Value F1',
307
+ 'f2': 'Value F2',
308
+ }]], [[{
309
+ 'f1': 'Value F1',
310
+ 'f2': 'Value F2',
311
+ }]]
312
+ ]
313
+ arr_1 = factory('#array', value=value, props={
314
+ 'label': 'Array 1',
315
+ })
316
+ arr_2 = arr_1['array_2'] = factory('array', props={
317
+ 'label': 'Array 2',
318
+ })
319
+ arr_3 = arr_2['array_3'] = factory('array', props={
320
+ 'label': 'Array 3',
321
+ })
322
+ compound = arr_3['comp'] = factory('compound')
323
+ compound['f1'] = factory('#arrayfield:text', props={
324
+ 'label': 'F1',
325
+ })
326
+ compound['f2'] = factory('#arrayfield:text', props={
327
+ 'label': 'F2',
328
+ 'required': 'F2 is required',
329
+ })
330
+ """
331
+
332
+
333
+ def array_with_array_with_array_with_compounds():
334
+ form = factory(
335
+ 'fieldset',
336
+ name='yafowil.widget.array_with_array_with_array_with_compounds')
337
+ value = [
338
+ [[{
339
+ 'f1': 'Value F1',
340
+ 'f2': 'Value F2',
341
+ }]], [[{
342
+ 'f1': 'Value F1',
343
+ 'f2': 'Value F2',
344
+ }]]]
345
+ arr_1 = form['array_1'] = factory('#array', value=value, props={
346
+ 'label': 'Array 1',
347
+ })
348
+ arr_2 = arr_1['array_2'] = factory('array', props={
349
+ 'label': 'Array 2',
350
+ })
351
+ arr_3 = arr_2['array_3'] = factory('array', props={
352
+ 'label': 'Array 3',
353
+ })
354
+ comp = arr_3['comp'] = factory('compound')
355
+ comp['f1'] = factory('#arrayfield:text', props={
356
+ 'label': 'F1',
357
+ })
358
+ comp['f2'] = factory('#arrayfield:text', props={
359
+ 'label': 'F2',
360
+ 'required': 'F2 is required',
361
+ })
362
+ return {
363
+ 'widget': form,
364
+ 'doc': DOC_ARRAY_WITH_ARRAY_WITH_ARRAY_WITH_COMPOUNDS,
365
+ 'title': 'Compounds in 3-dimensional array',
366
+ }
367
+
368
+
369
+ def get_example():
370
+ return [
371
+ array_with_leafs(),
372
+ array_with_compounds(),
373
+ array_with_array_with_leafs(),
374
+ array_with_array_with_compounds(),
375
+ array_with_array_with_array_with_leafs(),
376
+ array_with_array_with_array_with_compounds(),
377
+ ]
@@ -0,0 +1,67 @@
1
+ /* yafowil.widget.array - bootstrap theme styles */
2
+ .icon-plus-sign,
3
+ .icon-minus-sign,
4
+ .icon-circle-arrow-up,
5
+ .icon-circle-arrow-down {
6
+ display:inline-block;
7
+ font-family:'Glyphicons Halflings';
8
+ font-style:normal;
9
+ font-weight:400;
10
+ line-height:1;
11
+ margin-left:2px;
12
+ position:relative;
13
+ top:1px;
14
+ }
15
+ .icon-plus-sign:before {
16
+ content:"";
17
+ }
18
+ .icon-minus-sign:before {
19
+ content:"";
20
+ }
21
+ .icon-circle-arrow-up:before {
22
+ content:"";
23
+ }
24
+ .icon-circle-arrow-down:before {
25
+ content:"";
26
+ }
27
+ .array table {
28
+ border-radius:4px;
29
+ margin-bottom:0;
30
+ }
31
+ .array table table {
32
+ border-right:#ddd 1px solid;
33
+ margin-top:10px;
34
+ }
35
+ .array table table th {
36
+ padding-left:0;
37
+ }
38
+ .array td.widget {
39
+ padding:0 0 10px 0;
40
+ }
41
+ .array td.widget .form-group {
42
+ margin:0;
43
+ }
44
+ .array th {
45
+ vertical-align:middle;
46
+ }
47
+ .array th.head_actions,
48
+ .array td.actions {
49
+ width:5.5em;
50
+ }
51
+ .array_actions {
52
+ display:inline-block;
53
+ margin-top:0.6em;
54
+ padding-right:0.45em;
55
+ width:5.5em;
56
+ }
57
+ .array_actions a {
58
+ float:right;
59
+ }
60
+ .array_actions a.array_row_up_disabled,
61
+ .array_actions a.array_row_down_disabled {
62
+ opacity:0.4;
63
+ filter:alpha(opacity=40);
64
+ }
65
+ .arraytemplate {
66
+ display:none;
67
+ }
@@ -0,0 +1,65 @@
1
+ /* yafowil.widget.array - default theme styles */
2
+ .arraytemplate {
3
+ display:none;
4
+ }
5
+ .icon-plus-sign:before {
6
+ content:"\00a0";
7
+ }
8
+ .icon-minus-sign:before {
9
+ content: "\00a0";
10
+ }
11
+ .icon-circle-arrow-up:before {
12
+ content:"\00a0";
13
+ }
14
+ .icon-circle-arrow-down:before {
15
+ content: "\00a0";
16
+ }
17
+ .array table {
18
+ border-collapse:collapse;
19
+ border-top:#ccc 1px solid;
20
+ border-left:#ccc 1px solid;
21
+ border-right:#ccc 1px solid;
22
+ margin-bottom:0.5em;
23
+ }
24
+ .array table th {
25
+ color:#333;
26
+ background-color:#ccc;
27
+ }
28
+ .array table tr {
29
+ border-bottom:#ccc 1px solid;
30
+ }
31
+ .array table td.actions {
32
+ vertical-align:top;
33
+ }
34
+ .errormessage {
35
+ color:red;
36
+ font-size:11px;
37
+ padding-bottom:2px;
38
+ }
39
+ .array_actions a {
40
+ line-height:16px;
41
+ font-size:16px;
42
+ padding-left:16px;
43
+ text-decoration:none;
44
+ float:right;
45
+ margin-top:1px;
46
+ border:none !important;
47
+ }
48
+ .array_actions a.array_row_add {
49
+ background:url('images/icon_add.png') 50% 50% no-repeat;
50
+ }
51
+ .array_actions a.array_row_remove {
52
+ background:url('images/icon_remove.png') 50% 50% no-repeat;
53
+ }
54
+ .array_actions a.array_row_up {
55
+ background:url('images/icon_up.png') 50% 50% no-repeat;
56
+ }
57
+ .array_actions a.array_row_up_disabled {
58
+ background:url('images/icon_up_disabled.png') 50% 50% no-repeat !important;
59
+ }
60
+ .array_actions a.array_row_down {
61
+ background:url('images/icon_down.png') 50% 50% no-repeat;
62
+ }
63
+ .array_actions a.array_row_down_disabled {
64
+ background:url('images/icon_down_disabled.png') 50% 50% no-repeat !important;
65
+ }
@@ -0,0 +1,93 @@
1
+ /* yafowil.widget.array - bootstrap theme styles */
2
+ .array .icon-plus-sign,
3
+ .array .icon-minus-sign,
4
+ .array .icon-circle-arrow-up,
5
+ .array .icon-circle-arrow-down {
6
+ display:inline-block;
7
+ font-family:'yafowil-fontello';
8
+ font-style:normal;
9
+ font-weight:400;
10
+ font-variant:normal;
11
+ text-transform:none;
12
+ text-decoration:none;
13
+ text-align:center;
14
+ line-height:1em;
15
+ position:relative;
16
+ top:1px;
17
+ width:1em;
18
+ margin-right:2px;
19
+ margin-left:2px;
20
+ speak:none;
21
+ -webkit-font-smoothing:antialiased;
22
+ -moz-osx-font-smoothing:grayscale;
23
+ }
24
+ .array .icon-plus-sign:before {
25
+ font-family:'yafowil-fontello';
26
+ content:"\e800";
27
+ }
28
+ .array .icon-minus-sign:before {
29
+ font-family:'yafowil-fontello';
30
+ content:"\e801";
31
+ }
32
+ .array .icon-circle-arrow-up:before {
33
+ font-family:'yafowil-fontello';
34
+ content:"\e803";
35
+ }
36
+ .array .icon-circle-arrow-down:before {
37
+ font-family:'yafowil-fontello';
38
+ content:"\e802";
39
+ }
40
+ .array table {
41
+ margin-bottom:0;
42
+ border:none;
43
+ background:transparent;
44
+ }
45
+ .array table tr,
46
+ .array table td {
47
+ border:none;
48
+ }
49
+ .array table th {
50
+ border:none;
51
+ border-bottom:#ddd 2px solid;
52
+ }
53
+ .array table table {
54
+ border-right:#ddd 1px solid;
55
+ margin-top:10px;
56
+ }
57
+ .array table table th {
58
+ padding-left:0;
59
+ }
60
+ .array td.widget {
61
+ padding:0;
62
+ }
63
+ .array td.widget .form-group {
64
+ margin:0;
65
+ }
66
+ .array th {
67
+ vertical-align:middle;
68
+ }
69
+ .array th.head_actions,
70
+ .array td.actions {
71
+ width:6.5em;
72
+ }
73
+ .array_actions {
74
+ display:inline-block;
75
+ margin-top:0.6em;
76
+ padding-right:0.45em;
77
+ width:6.5em;
78
+ }
79
+ .array_actions a {
80
+ float:right;
81
+ }
82
+ .array_actions a.array_row_up_disabled,
83
+ .array_actions a.array_row_down_disabled {
84
+ opacity:0.4;
85
+ filter:alpha(opacity=40);
86
+ }
87
+ .arraytemplate {
88
+ display:none;
89
+ }
90
+ .array .field {
91
+ padding-top:0.5em;
92
+ margin-bottom:0;
93
+ }