[r2587]: projects / FastData2 / trunk / fastdata2 / widgetfactory.py Maximize Restore History

Download this file

widgetfactory.py    58 lines (49 with data), 1.9 kB

 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
from view import widget_for
from toscawidgets.widgets.grids.widgets import Grid, Cell
from toscawidgets.api import Widget
from ormdatahandler import is_sqlobject_obj, is_sqlalchemy_obj, is_sa_column, \
is_so_column
is_list_with_data = "isinstance(obj, list) and len(obj)>0"
[widget_for.when(is_list_with_data)]
def __widget_for_list(obj, cls, **kw):
"""
>>> w = widget_for(obj=[None,None])
>>> o = w.render()
>>> 'unknown-0' in o
True
>>> 'unknown-1' in o
True
>>> 'unknown-2' in o
False
"""
widget = widget_for(obj=obj[0], **kw)
repetitions = len(obj) + kw.get('extra_repetitions', 0)
if isinstance(widget, FormField):
return FormFieldRepeater(
id=widget.id, widget=widget, repetitions=repetitions
)
return WidgetRepeater(id=widget.id, widget=widget, repetitions=repetitions)
so_list_index = is_list_with_data + \
' and is_sqlobject_obj(obj[0]) and kw.get("action")=="index"'
[widget_for.when(so_list_index)]
def _widget_for_soindex(obj, cls, **kw):
cols = []
for col in list(obj[0].sqlmeta.columnList):
w = widget_for(col, action='index')
if w:
cols.append(w)
return Grid(id=obj[0].__class__.__name__ + '_fdindex', columns=cols)
sa_list_index = is_list_with_data + \
'and is_sqlalchemy_obj(obj[0]) and kw.get("action")=="index"'
[widget_for.when(sa_list_index)]
def _widget_for_saindex(obj, cls, **kw):
cols = []
for col in list(obj[0].c):
w = widget_for(col, action='index')
if w:
cols.append(w)
return Grid(id=obj[0].__class__.__name__ + '_fdindex', columns=cols)
[widget_for.when('is_sa_column(obj) or is_so_column(obj) ' \
'and kw.get("action")=="index"')]
def _widget_for_orm_column_defaultindex(obj, cls, **kw):
return Cell(id=obj.name)