class IChoice(IField): """Field whose value is contained in a predefined set Only one, values or vocabulary, may be specified for a given choice. """ vocabulary = Field( title=_("Vocabulary or source providing values"), description=_("The ISource, IContextSourceBinder or IBaseVocabulary " "object that provides values for this field."), required=False, default=None) vocabularyName = TextLine( title=_("Vocabulary name"), description=_("Vocabulary name to lookup in the vocabulary registry"), required=False, default=None)
class ITitledTokenizedTerm(ITokenizedTerm): """A tokenized term that includes a title.""" title = TextLine(title=_("Title"))
class IField(Interface): """Basic Schema Field Interface. Fields are used for Interface specifications. They at least provide a title, description and a default value. You can also specify if they are required and/or readonly. The Field Interface is also used for validation and specifying constraints. We want to make it possible for a IField to not only work on its value but also on the object this value is bound to. This enables a Field implementation to perform validation against an object which also marks a certain place. Note that many fields need information about the object containing a field. For example, when validating a value to be set as an object attribute, it may be necessary for the field to introspect the object's state. This means that the field needs to have access to the object when performing validation:: bound = field.bind(object) bound.validate(value) """ def bind(object): """Return a copy of this field which is bound to context. The copy of the Field will have the 'context' attribute set to 'object'. This way a Field can implement more complex checks involving the object's location/environment. Many fields don't need to be bound. Only fields that condition validation or properties on an object containing the field need to be bound. """ title = TextLine(title=_("Title"), description=_("A short summary or label"), default="", required=False) description = Text(title=_("Description"), description=_("A description of the field"), default="", required=False) required = Bool( title=_("Required"), description=(_("Tells whether a field requires its value to exist.")), default=False, ) readonly = Bool( title=_("Read Only"), description=_("If true, the field's value cannot be changed."), required=False, default=False, ) default = Field( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""), ) missing_value = Field( title=_("Missing Value"), description=_("""If input for this Field is missing, and that's ok, then this is the value to use"""), ) order = Int( title=_("Field Order"), description=_(""" The order attribute can be used to determine the order in which fields in a schema were defined. If one field is created after another (in the same thread), its order will be greater. (Fields in separate threads could have the same order.) """), required=True, readonly=True, ) def constraint(value): """Check a customized constraint on the value. You can implement this method with your Field to require a certain constraint. This relaxes the need to inherit/subclass a Field you to add a simple constraint. Returns true if the given value is within the Field's constraint. """ def validate(value): """Validate that the given value is a valid field value. Returns nothing but raises an error if the value is invalid. It checks everything specific to a Field and also checks with the additional constraint. """ def get(object): """Get the value of the field for the given object.""" def query(object, default=None): """Query the value of the field for the given object. Return the default if the value hasn't been set. """ def set(object, value): """Set the value of the field for the object