Example #1
0
    class TestModel:
        field1 = pb.field('element', idx=1)
        field2 = pb.field('element', idx=2)

        field3 = pb.wrap('wrapper', pb.field('element'), idx=1)
        field4 = pb.wrap('wrapper', pb.field('element'), idx=2)

        nested1 = pb.nested(Nested, idx=1)
        nested2 = pb.nested(Nested, idx=2)
Example #2
0
    class User:
        name = pb.attr()
        surname = pb.attr()
        age = pb.attr(converter=int)

        phone = pb.wrap('contacts', pb.field())
        emails = pb.wrap('contacts', pb.as_list(pb.field(name='email')))

        passport_series = pb.wrap('documents/passport', pb.attr('series'))
        passport_number = pb.wrap('documents/passport', pb.attr('number'))

        occupations = pb.wrap('occupations',
                              pb.lst(pb.nested(Occupation)),
                              ns='data',
                              ns_map={'data': 'http://www.test22.org'})

        citizenship = pb.field(default='RU')
Example #3
0
class User:
    name = pb.attr()
    surname = pb.attr()
    age = pb.attr(converter=int)

    birth_year = pb.wrap('birthdate', pb.attr('year', converter=int))
    birth_month = pb.wrap('birthdate', pb.attr('month', converter=int))
    birth_day = pb.wrap('birthdate', pb.attr('day', converter=int))

    @property
    def birthdate(self):
        return date(year=self.birth_year,
                    month=self.birth_month,
                    day=self.birth_day)

    @birthdate.setter
    def birthdate(self, value):
        self.birth_year = value.year
        self.birth_month = value.month
        self.birth_day = value.day

    phone = pb.wrap('contacts', pb.field())
    emails = pb.wrap('contacts', pb.as_list(pb.field(name='email')))

    passport_series = pb.wrap('documents/passport', pb.attr('series'))
    passport_number = pb.wrap('documents/passport', pb.attr('number'))

    occupations = pb.wrap('occupations',
                          pb.lst(pb.nested(Occupation)),
                          ns='data',
                          ns_map={'data': 'http://www.test2.org'})

    citizenship = pb.field(default='RU')

    @phone.validator
    def check(self, attribute, value):
        if not re.match(r'\+\d{11,13}', value):
            raise ValueError("phone number is incorrect")
Example #4
0
 class TestModel:
     field = pb.field()
     nested = pb.as_list(pb.nested(Nested))
Example #5
0
 class TestModel:
     element1 = pb.field()
     element2 = pb.nested(NestedModel, default=None)
Example #6
0
 class TestModel:
     elements = pb.as_list(pb.nested(NestedModel))
Example #7
0
 class TestModel:
     nested = pb.nested(NestedModel1)
Example #8
0
 class NestedModel1:
     nested = pb.nested(NestedModel2)
Example #9
0
 class TestRootModel:
     model1 = pb.nested(TestBaseModel)
     model2 = pb.nested(TestExtendedModel)
Example #10
0
 class TestModel:
     element = pb.nested(NestedModel)
Example #11
0
 class TestModel:
     nested = pb.nested(NestedModel, default=None)