yafowil.widget.array 2.0.0__py2.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,211 @@
1
+ from yafowil.base import factory
2
+ from yafowil.utils import entry_point
3
+ import os
4
+ import webresource as wr
5
+
6
+
7
+ resources_dir = os.path.join(os.path.dirname(__file__), 'resources')
8
+
9
+
10
+ ##############################################################################
11
+ # Common
12
+ ##############################################################################
13
+
14
+ # webresource ################################################################
15
+
16
+ array_js = wr.ScriptResource(
17
+ name='yafowil-array-js',
18
+ directory=os.path.join(resources_dir, 'default'),
19
+ path='yafowil-array/default',
20
+ depends='jquery-js',
21
+ resource='widget.js',
22
+ compressed='widget.min.js'
23
+ )
24
+
25
+ # B/C resources ##############################################################
26
+
27
+ js = [{
28
+ 'group': 'yafowil.widget.array.common',
29
+ 'resource': 'default/widget.js',
30
+ 'order': 20,
31
+ }]
32
+
33
+
34
+ ##############################################################################
35
+ # Default
36
+ ##############################################################################
37
+
38
+ # webresource ################################################################
39
+
40
+ default_resources = wr.ResourceGroup(
41
+ name='yafowil.widget.array',
42
+ directory=resources_dir,
43
+ path='yafowil-array'
44
+ )
45
+ default_resources.add(array_js)
46
+ default_resources.add(wr.StyleResource(
47
+ name='yafowil-array-css',
48
+ directory=os.path.join(resources_dir, 'default'),
49
+ path='yafowil-array/default',
50
+ resource='widget.min.css'
51
+ ))
52
+
53
+ # B/C resources ##############################################################
54
+
55
+ default_css = [{
56
+ 'group': 'yafowil.widget.array.common',
57
+ 'resource': 'default/widget.min.css',
58
+ 'order': 20,
59
+ }]
60
+
61
+
62
+ ##############################################################################
63
+ # Bootstrap
64
+ ##############################################################################
65
+
66
+ # webresource ################################################################
67
+
68
+ bootstrap_resources = wr.ResourceGroup(
69
+ name='yafowil.widget.array',
70
+ directory=resources_dir,
71
+ path='yafowil-array'
72
+ )
73
+ bootstrap_resources.add(array_js)
74
+ bootstrap_resources.add(wr.StyleResource(
75
+ name='yafowil-array-css',
76
+ directory=os.path.join(resources_dir, 'bootstrap'),
77
+ path='yafowil-array/bootstrap',
78
+ resource='widget.min.css'
79
+ ))
80
+
81
+ # B/C resources ##############################################################
82
+
83
+ bootstrap_css = [{
84
+ 'group': 'yafowil.widget.array.common',
85
+ 'resource': 'bootstrap/widget.min.css',
86
+ 'order': 20,
87
+ }]
88
+
89
+
90
+ ##############################################################################
91
+ # Bootstrap 5
92
+ ##############################################################################
93
+
94
+ # webresource ################################################################
95
+ bootstrap5_resources = wr.ResourceGroup(
96
+ name='yafowil.widget.array',
97
+ directory=resources_dir,
98
+ path='yafowil-array'
99
+ )
100
+ bootstrap5_js = wr.ScriptResource(
101
+ name='yafowil-array-js',
102
+ directory=os.path.join(resources_dir, 'bootstrap5'),
103
+ path='yafowil-array/bootstrap5',
104
+ depends='jquery-js',
105
+ resource='widget.js',
106
+ compressed='widget.min.js'
107
+ )
108
+ bootstrap5_resources.add(bootstrap5_js)
109
+ bootstrap5_resources.add(wr.StyleResource(
110
+ name='yafowil-array-css',
111
+ directory=os.path.join(resources_dir, 'bootstrap5'),
112
+ path='yafowil-array/bootstrap5',
113
+ resource='widget.min.css'
114
+ ))
115
+
116
+ # B/C resources ##############################################################
117
+
118
+ bootstrap5_css = [{
119
+ 'group': 'yafowil.widget.array.common',
120
+ 'resource': 'bootstrap5/widget.min.css',
121
+ 'order': 20,
122
+ }]
123
+
124
+
125
+
126
+ ##############################################################################
127
+ # Plone5
128
+ ##############################################################################
129
+
130
+ # webresource ################################################################
131
+
132
+ plone5_resources = wr.ResourceGroup(
133
+ name='yafowil.widget.array',
134
+ directory=resources_dir,
135
+ path='yafowil-array'
136
+ )
137
+ plone5_resources.add(array_js)
138
+ plone5_resources.add(wr.StyleResource(
139
+ name='yafowil-array-css',
140
+ directory=os.path.join(resources_dir, 'plone5'),
141
+ path='yafowil-array/plone5',
142
+ resource='widget.min.css'
143
+ ))
144
+
145
+ # B/C resources ##############################################################
146
+
147
+ plone5_css = [{
148
+ 'group': 'yafowil.widget.array.common',
149
+ 'resource': 'plone5/widget.min.css',
150
+ 'order': 20,
151
+ }]
152
+
153
+
154
+ ##############################################################################
155
+ # Registration
156
+ ##############################################################################
157
+
158
+ @entry_point(order=10)
159
+ def register():
160
+ from yafowil.widget.array import widget # noqa
161
+
162
+ widget_name = 'yafowil.widget.array'
163
+
164
+ # Default
165
+ factory.register_theme(
166
+ 'default',
167
+ widget_name,
168
+ resources_dir,
169
+ js=js,
170
+ css=default_css
171
+ )
172
+ factory.register_resources('default', widget_name, default_resources)
173
+
174
+ # Bootstrap
175
+ factory.register_theme(
176
+ ['bootstrap', 'bootstrap3'],
177
+ widget_name,
178
+ resources_dir,
179
+ js=js,
180
+ css=bootstrap_css
181
+ )
182
+ factory.register_resources(
183
+ ['bootstrap', 'bootstrap3'],
184
+ widget_name,
185
+ bootstrap_resources
186
+ )
187
+
188
+ # Bootstrap 5
189
+ factory.register_theme(
190
+ ['bootstrap5'],
191
+ widget_name,
192
+ resources_dir,
193
+ js=bootstrap5_js,
194
+ css=bootstrap5_css
195
+ )
196
+
197
+ factory.register_resources(
198
+ ['bootstrap5'],
199
+ widget_name,
200
+ bootstrap5_resources
201
+ )
202
+
203
+ # Plone 5
204
+ factory.register_theme(
205
+ 'plone5',
206
+ widget_name,
207
+ resources_dir,
208
+ js=js,
209
+ css=plone5_css
210
+ )
211
+ factory.register_resources('plone5', widget_name, plone5_resources)
@@ -0,0 +1,418 @@
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
+ DOC_ARRAY_DISPLAY = """\
370
+ Display Mode
371
+ ------------
372
+
373
+ Display mode renders the widget and its children uneditable.
374
+
375
+ .. code-block:: python
376
+
377
+ value = ['1', '2', '3', '4']
378
+ array = factory('#array', value=value, mode='display', props={
379
+ 'label': 'An Array in display mode',
380
+ 'help': 'I am an array',
381
+ })
382
+ array['field'] = factory('#arrayfield:text', props={
383
+ 'label': 'Entry in display mode',
384
+ 'help': 'I am an array entry',
385
+ })
386
+ """
387
+
388
+
389
+ def array_display():
390
+ form = factory(
391
+ 'fieldset',
392
+ name='yafowil.widget.array_display')
393
+ value = ['I am not editable.', 'Me neither!']
394
+ array = form['array'] = factory('#array', mode='display', value=value, props={
395
+ 'label': 'An Array in display mode',
396
+ 'help': 'I am an array'
397
+ })
398
+ array['field'] = factory('#arrayfield:text', props={
399
+ 'label': 'Entry in display mode',
400
+ 'help': 'I am an array entry',
401
+ })
402
+ return {
403
+ 'widget': form,
404
+ 'doc': DOC_ARRAY_DISPLAY,
405
+ 'title': 'Display Mode',
406
+ }
407
+
408
+
409
+ def get_example():
410
+ return [
411
+ array_with_leafs(),
412
+ array_with_compounds(),
413
+ array_with_array_with_leafs(),
414
+ array_with_array_with_compounds(),
415
+ array_with_array_with_array_with_leafs(),
416
+ array_with_array_with_array_with_compounds(),
417
+ array_display(),
418
+ ]
@@ -0,0 +1 @@
1
+ .arraytemplate{display:none}.icon-circle-arrow-down,.icon-circle-arrow-up,.icon-minus-sign,.icon-plus-sign{display:inline-block;font-family:Glyphicons Halflings;font-style:normal;font-weight:400;line-height:1;margin-left:2px;position:relative;top:1px}.icon-plus-sign:before{content:""}.icon-minus-sign:before{content:""}.icon-circle-arrow-up:before{content:""}.icon-circle-arrow-down:before{content:""}.array table{border-radius:4px;margin-bottom:0}.array table table{border-right:1px solid #ddd;margin-top:10px}.array table table th{padding-left:0}.array table td.widget{padding:0 0 10px}.array table td.widget .form-group{margin:0}.array table th{vertical-align:middle}.array table td.actions,.array table th.head_actions{width:5.5em}.array .array_actions{display:inline-block;margin-top:.6em;padding-right:.45em;width:5.5em}.array .array_actions a{background:none;float:right}.array .array_actions a.array_row_down_disabled,.array .array_actions a.array_row_up_disabled{filter:alpha(opacity=40);opacity:.4}.array .array_actions span{color:var(--yafowil-accent-color,#0d6efd)}