Deform/Colander: Mark deeply nested fields read-only after bind

6 views
Skip to first unread message

D.S. Ljungmark

unread,
Sep 10, 2018, 3:13:20 PM9/10/18
to pylons-...@googlegroups.com
So, I've got a rather complex schema with several hierarchies deep. At the lowest level, are a Sequence of Mappings as follows:


class Thingie(colander.MappingSchema):
    name = colander.SchemaNode(
        colander.String(),
        missing=colander.required,
        validator=name_validator,
    )

    port = colander.SchemaNode(
        colander.String(),
        missing=colander.required,
        validator=validate_port,
    )

class MidLevel(colander.MappingSchema):
 
    @colander.instantiate(
        missing=[],
        title="Thingie definitions",
        validator=colander.All(validate_unique_names,
                               validate_no_duped_ports))


    class thingies(colander.SequenceSchema):
        meter = Thingie(
            title="Thingie",
        )



Now, I'd want to make _new_ entries use a read/Write field for the name, but turn it read-only when bound with data from the database backend.  This _seems_ at first view as if it should be a simple thing, but so far, I've not succeeded.


I think I'm on a wrong track with binding, but I'm not sure where to go here.

TL/DR:
How do I make a Sequence where already populated fields are Read Only, and new fields permit user input?

Reply all
Reply to author
Forward
0 new messages