class IMinMaxLen(ILen): """Field requiring the length of its value to be within a range""" min_length = Int( title=_("Minimum length"), description=_(""" Value after whitespace processing cannot have less than `min_length` characters (if a string type) or elements (if another sequence type). If `min_length` is ``None``, there is no minimum. """), required=False, min=0, # needs to be a positive number default=0) max_length = Int( title=_("Maximum length"), description=_(""" Value after whitespace processing cannot have greater or equal than `max_length` characters (if a string type) or elements (if another sequence type). If `max_length` is ``None``, there is no maximum."""), required=False, min=0, # needs to be a positive number default=None)
class IInt(IIntegral): """ Field containing exactly the native class :class:`int` (or, on Python 2, ``long``). .. seealso:: :class:`zope.schema.Int` """ min = Int( title=_("Start of the range"), required=False, default=None ) max = Int( title=_("End of the range (including the value itself)"), required=False, default=None ) default = Int( title=_("Default Value"), description=_("""The field default value may be None or a legal field value""") )
class IInt(IMinMax, IField): """Field containing an Integer Value.""" min = Int(title=_("Start of the range"), required=False, default=None) max = Int(title=_("End of the range (excluding the value itself)"), required=False, default=None) default = Int( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""))
class IDottedName(_IStrLine): """Dotted name field. Values of DottedName fields must be Python-style dotted names. """ min_dots = Int(title=_("Minimum number of dots"), required=True, min=0, default=0) max_dots = Int( title=_("Maximum number of dots (should not be less than min_dots)"), required=False, default=None)
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=u"", required=False, ) description = Text( title=_("Description"), description=_("A description of the field"), default=u"", required=False, ) required = Bool( title=_("Required"), description=(_("Tells whether a field requires its value to exist.")), default=True) 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