예제 #1
0
    def on_bind(self) -> None:
        assert self.template
        for k, v in getattr(self.parent.parent, '_fields_unapplied_data',
                            {}).get(self.name, {}).items():
            setattr_path(self, k, v)

        form = self.parent.parent
        if self.attr is MISSING:
            self.attr = self.name
        if self.display_name is MISSING:
            self.display_name = capitalize(self.name).replace(
                '_', ' ') if self.name else ''

        self.errors = Errors(parent=self, **self.errors)

        if form.editable is False:
            self.editable = False

        self.declared_field = self._declared
예제 #2
0
파일: action.py 프로젝트: OakNinja/iommi
    def on_bind(self) -> None:
        if self.parent is not None and self.parent.parent is not None:
            for k, v in getattr(self.parent.parent, '_actions_unapplied_data', {}).get(self.name, {}).items():
                setattr_path(self, k, v)
        evaluated_attributes = [
            'tag',
            'group',
            'template',
            'display_name',
            'name',
            'after',
            'default_child',
            'style',
        ]
        for key in evaluated_attributes:
            self._evaluate_attribute(key)

        self.extra_evaluated = evaluate_strict_container(self.extra_evaluated, **self.evaluate_attribute_kwargs())
        self.attrs = evaluate_attrs(self, **self.evaluate_attribute_kwargs())
예제 #3
0
def test_getattr_path_and_setattr_path():
    class Baz:
        def __init__(self):
            self.quux = 3

    class Bar:
        def __init__(self):
            self.baz = Baz()

    class Foo:
        def __init__(self):
            self.bar = Bar()

    foo = Foo()
    assert getattr_path(foo, 'bar__baz__quux') == 3

    setattr_path(foo, 'bar__baz__quux', 7)

    assert getattr_path(foo, 'bar__baz__quux') == 7

    setattr_path(foo, 'bar__baz', None)
    assert getattr_path(foo, 'bar__baz__quux') is None

    setattr_path(foo, 'bar', None)
    assert foo.bar is None
예제 #4
0
def test_getattr_path_and_setattr_path():
    class Baz(object):
        def __init__(self):
            self.quux = 3

    class Bar(object):
        def __init__(self):
            self.baz = Baz()

    class Foo(object):
        def __init__(self):
            self.bar = Bar()

    foo = Foo()
    assert 3 == getattr_path(foo, 'bar__baz__quux')

    setattr_path(foo, 'bar__baz__quux', 7)

    assert 7 == getattr_path(foo, 'bar__baz__quux')

    setattr_path(foo, 'bar__baz', None)
    assert None is getattr_path(foo, 'bar__baz__quux')

    setattr_path(foo, 'bar', None)
    assert None is foo.bar
예제 #5
0
 def write_to_instance(field: 'Field', instance: Any, value: Any) -> None:
     setattr_path(instance, field.attr, value)