Exemple #1
0
class IBool(IField):
    """Boolean Field."""

    default = Bool(
        title=_("Default Value"),
        description=_("""The field default value may be None or a legal
                        field value"""))
    required = Bool(
        title=_("Required"),
        description=(_("Tells whether a field requires its value to exist.")),
        required=False,
        default=False)
Exemple #2
0
class IBool(IField):
    """Boolean Field."""

    default = Bool(
        title=_("Default Value"),
        description=_("""The field default value may be None or a legal
                        field value"""))
Exemple #3
0
class ICollection(IMinMaxLen, IIterable, IContainer):
    """Abstract interface containing a collection value.

    The Value must be iterable and may have a min_length/max_length.
    """

    value_type = Field(
        title=_("Value Type"),
        description=_("Field value items must conform to the given type, "
                      "expressed via a Field."))

    unique = Bool(
        title=_('Unique Members'),
        description=_('Specifies whether the members of the collection '
                      'must be unique.'),
        default=False)
class IObject(IField):
    """
    Field containing an Object value.

    .. versionchanged:: 4.6.0
       Add the *validate_invariants* attribute.
    """

    schema = Object(
        IInterface,
        description=_("The Interface that defines the Fields comprising the Object.")
    )

    validate_invariants = Bool(
        title=_("Validate Invariants"),
        description=_("A boolean that says whether ``schema.validateInvariants`` "
                      "is called from ``self.validate()``. The default is true."),
        default=True,
    )
Exemple #5
0
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
Exemple #6
0
class IAbstractBag(IUnorderedCollection):
    """An unordered collection of values, with no limitations on whether
    members are unique"""

    unique = Bool(
        description="This ICollection interface attribute must be False")
Exemple #7
0
class IAbstractSet(IUnorderedCollection):
    """An unordered collection of unique values."""

    unique = Bool(
        description="This ICollection interface attribute must be True")