Colander: How to list attributes? Mixins or inheritance?

25 views
Skip to first unread message

Dirk Makowski

unread,
Aug 11, 2011, 5:22:12 AM8/11/11
to pylons-...@googlegroups.com
Hi all,

about Colander I have 2 questions:

[1]
given a colander schema like

class Principal(MappingSchema):
    is_enabled = SchemaNode(Bool()
            , title = 'Enabled?'
            , foo = 'bar'
        )

How can I build a list of the defined fields which are class attributes and tell their kwargs?
(I'd like to use Colander to define more general data dictionaries and want to read those definitions under different circumstances.)

[2]
If many schemas have several attributes in common, is it possible to define them in a separate schema and use that as a mix-in? Or must the common schema be inherited from?

[a] Mixin
class MyMixin(object):
    frobotz = SchemaNode(Bool()
            , title = 'FroBotz?'
            , baz = 'qux'
        )

class MySchema(MappingSchema, MyMixin):
     ...

[b] Inheritance
class MyMixin(MappingSchema):
    frobotz = SchemaNode(Bool()
            , title = 'FroBotz?'
            , baz = 'qux'
        )

class MySchema(MyMixin):
     ...


Thanks for your help.
Dirk
Reply all
Reply to author
Forward
0 new messages