コード例 #1
0
 def __init__(self, fields, form):
     self.interfaces = []
     for field in fields:
         if IField.providedBy(field):
             if field.interface not in self.interfaces:
                 self.interfaces.append(field.interface)
     self.form = form
コード例 #2
0
 def __init__(self, title,
              valueField=None,
              minLength=0,
              maxLength=None,
              **options):
     super(CollectionField, self).__init__(title, **options)
     self._valueField = IField(valueField, None)
     self.minLength = minLength
     self.maxLength = maxLength
コード例 #3
0
class CollectionField(BaseField):
    """A collection field.
    """
    grok.implements(ICollectionField)

    collectionType = list
    allowAdding = True
    allowRemove = True
    inlineValidation = False

    def __init__(self, title,
                 valueField=None,
                 minLength=0,
                 maxLength=None,
                 **options):
        super(CollectionField, self).__init__(title, **options)
        self._valueField = IField(valueField, None)
        self.minLength = minLength
        self.maxLength = maxLength

    @property
    def valueField(self):
        return self._valueField

    def validate(self, value, form):
        error = super(CollectionField, self).validate(value, form)
        if error is not None:
            return error
        if not isinstance(value, Marker):
            if not isinstance(value, self.collectionType):
                return _(u'Object is of wrong type.')
            if self.minLength and len(value) < self.minLength:
                return _(u"There are too few items.")
            if self.maxLength and len(value) > self.maxLength:
                return _(u"There are too many items.")
            for item in value:
                error = self._valueField.validate(item, form)
                if error is not None:
                    return error
        return None

    def isEmpty(self, value):
        return value is NO_VALUE or not len(value)
コード例 #4
0
 def __init__(self, field):
     super(CollectionSchemaField, self).__init__(field)
     self.__value_field = IField(self._field.value_type)