Read-Only Sequence of Mappings

  • People

    • Person

        • Name

          name1

        • Age

          23

    • Person

        • Name

          name2

        • Age

          25

Captured

None

Code (show in context)

    @view_config(renderer='templates/form.pt',
              name='readonly_sequence_of_mappings')
    @demonstrate('Read-Only Sequence of Mappings')
    def readonly_sequence_of_mappings(self):
        class Person(colander.Schema):
            name = colander.SchemaNode(colander.String())
            age = colander.SchemaNode(colander.Integer(),
                                      validator=colander.Range(0,200))
        class People(colander.SequenceSchema):
            person = Person()
        class Schema(colander.Schema):
            people = People()
        schema = Schema()
        form = deform.Form(schema, buttons=('submit',))
        return self.render_form(
            form,
            appstruct={'people':
                       [{'name':'name1', 'age':23},
                        {'name':'name2', 'age':25},]
                       },
            readonly=True)