Discussion:
[pylons-discuss] Deform/Colander: Marking fields as read-only
D.S. Ljungmark
2018-09-10 14:42:45 UTC
Permalink
TL/DR:
How do I make a Sequence where already populated fields are Read Only, and
new fields permit user input?


I have 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 ( using `bind`),
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.


Any suggestions would be welcome.
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAO0vwOW-oq8%2BCwNx1dDpGOKbnXKVNtzcT2pPPCDoQ_JHDQu1GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Dennis Ljungmark
2018-09-11 10:07:46 UTC
Permalink
TL/DR:
How do I make a Sequence where already populated fields are Read Only, and
new fields permit user input?


I have 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 ( using `bind`),
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.


Any suggestions would be welcome.

( Please excuse using the web form, seems my email subscription is held for
moderation)
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/7a80f3d2-e4bc-46a5-bffe-16268fef947f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mike Orr
2018-09-11 15:32:33 UTC
Permalink
I don't know how you'd integrate it with Colander, but generally you'd
use a dict subclass with a __setitem__ method that raises an exception
for read-only keys. Lists and classes can do something similar.
How do I make a Sequence where already populated fields are Read Only, and new fields permit user input?
name = colander.SchemaNode(
colander.String(),
missing=colander.required,
validator=name_validator,
)
port = colander.SchemaNode(
colander.String(),
missing=colander.required,
validator=validate_port,
)
@colander.instantiate(
missing=[],
title="Thingie definitions",
validator=colander.All(validate_unique_names,
validate_no_duped_ports))
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 ( using `bind`), 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.
Any suggestions would be welcome.
( Please excuse using the web form, seems my email subscription is held for moderation)
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/7a80f3d2-e4bc-46a5-bffe-16268fef947f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Mike Orr <***@gmail.com>
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+***@googlegroups.com.
To post to this group, send email to pylons-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Duo1_X%2BAR5EQ%3D%3DT_10JGatA3JGMcYhyEC99LC%2B85x3ivhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...