예제 #1
0
 def value(self):
     # if self._state is not None:
     #     return self._state
     result = _compat.OrderedDict()
     for key, element in iteritems(self):
         # if element.value is Unspecified:
         #     return NotUnserializable
         result[key] = element.value
     return result
예제 #2
0
 def __new__(cls, cls_name, bases, attributes):
     member_schema = attributes["member_schema"] = _compat.OrderedDict()
     for base in reversed(bases):
         member_schema.update(getattr(base, "member_schema", {}) or {})
     for name, attribute in iteritems(attributes):
         if isinstance(attribute, type) and issubclass(attribute, Element):
             if attribute.name != Unnamed and attribute.name not in member_schema:
                 name = attribute.name
             else:
                 attribute = attribute.using(name=name)
             member_schema[name] = attribute
     return super(FormMeta, cls).__new__(cls, cls_name, bases, attributes)
예제 #3
0
    def __new__(cls, *args, **kwargs):
        self = super(Form, cls).__new__(cls)
        for attribute_name in dir(self):
            if not attribute_name.startswith('validate_'):
                continue
            attribute = getattr(self, attribute_name)
            member_name = attribute_name[len('validate_'):]
            member = self.member_schema[member_name]
            self.member_schema[member_name] = member.validated_by([attribute])

        self._elements = _compat.OrderedDict()
        for name, element_cls in iteritems(self.member_schema):
            self._elements[name] = element = element_cls.using(name=name)()
            setattr(self, name, element)

        return self
예제 #4
0
 def of(cls, schema):
     cls.member_schema = _compat.OrderedDict(schema)
     return cls
예제 #5
0
 def __prepare__(name, bases, **kwargs):
     return _compat.OrderedDict()
예제 #6
0
 def test_set_strict(self, element_cls):
     value = _compat.OrderedDict({u"foo": 1})
     element = element_cls.using(strict=True)(value)
     assert element.raw_value == value
     assert element.value == value
예제 #7
0
 def possible_value(self):
     return _compat.OrderedDict([(u"foo", 1)])
예제 #8
0
 def test_retains_ordering(self, element_cls):
     value = [(u"foo", 1), (u"bar", 2), (u"baz", 3)]
     assert element_cls(value).value == _compat.OrderedDict(value)