3330.1.10
by Xavier Morel
[FIX] widgets registration (to pooler), creation (using right class from pooler) |
1 |
import openobject.pooler |
2 |
import openobject.meta |
|
2707
by ame (Tiny)
[FIX] form validation. |
3 |
|
2327.1.5
by ame (Tiny/Axelor)
* Integrated new widgets |
4 |
|
5 |
class WidgetType(type): |
|
4101
by Xavier Morel
[REM] post_init hook on widgets, complexifies the CPU profiles and generates a perf hit in cases where lots of widgets are initialized (e.g. big lists). |
6 |
def __new__(typ, name, bases, attrs): |
2327.1.59
by ame (Tiny/Axelor)
* Spliting base widget in to Widget & InputWidget |
7 |
_frozenset_from_bases(attrs, bases, 'params') |
2491
by ame (Tiny/Axelor)
* reimplemented base widget api (based on tg & tosca) |
8 |
_frozenset_from_bases(attrs, bases, 'member_widgets') |
2938.1.2
by Xavier Morel
[imp] Cleanup stray whitespace (lines of whitespace, extra whitespace after end of lines, ...) |
9 |
|
4101
by Xavier Morel
[REM] post_init hook on widgets, complexifies the CPU profiles and generates a perf hit in cases where lots of widgets are initialized (e.g. big lists). |
10 |
return super(WidgetType, typ).__new__(typ, name, bases, attrs) |
2327.1.65
by ame (Tiny/Axelor)
* cleanup |
11 |
|
3792
by Xavier Morel
[REF] extract the creation of a widget pooler key into a separate method |
12 |
def make_widget_key(cls, widget): |
13 |
return widget.__module__ + '.' + widget.__name__ |
|
14 |
||
3330.1.10
by Xavier Morel
[FIX] widgets registration (to pooler), creation (using right class from pooler) |
15 |
def __init__(cls, name, bases, dct): |
16 |
super(WidgetType, cls).__init__(name, bases, dct) |
|
3791
by Xavier Morel
[IMP] style |
17 |
if openobject.meta.Extends not in bases: |
3792
by Xavier Morel
[REF] extract the creation of a widget pooler key into a separate method |
18 |
cls.widget_key = cls.make_widget_key(cls) |
3330.1.10
by Xavier Morel
[FIX] widgets registration (to pooler), creation (using right class from pooler) |
19 |
openobject.pooler.register_object( |
3792
by Xavier Morel
[REF] extract the creation of a widget pooler key into a separate method |
20 |
cls, key=cls.widget_key, group='widgets') |
3330.1.10
by Xavier Morel
[FIX] widgets registration (to pooler), creation (using right class from pooler) |
21 |
return
|
22 |
assert len(bases) == 2, "It is only possible to Extend one object at a time, and one object has to be Extended" |
|
23 |
bases = list(bases) |
|
24 |
bases.remove(openobject.meta.Extends) |
|
25 |
base_widget = bases[0] |
|
26 |
openobject.pooler.register_object( |
|
3792
by Xavier Morel
[REF] extract the creation of a widget pooler key into a separate method |
27 |
cls, key=cls.make_widget_key(base_widget), group='widgets') |
2707
by ame (Tiny)
[FIX] form validation. |
28 |
|
2327.1.59
by ame (Tiny/Axelor)
* Spliting base widget in to Widget & InputWidget |
29 |
def _frozenset_from_bases(attrs, bases, name): |
30 |
items = set(attrs.pop(name, [])) |
|
3790
by Xavier Morel
[IMP] use regular for/if for side-effecting loops |
31 |
for b in bases: |
32 |
if hasattr(b, name): |
|
33 |
items.update(getattr(b, name)) |
|
2327.1.59
by ame (Tiny/Axelor)
* Spliting base widget in to Widget & InputWidget |
34 |
fs = attrs[name] = frozenset(items) |
35 |
return fs |