Beispiel #1
0
def cloneFormData(original, content=_marker, prefix=None):
    assert interfaces.IFieldExtractionValueSetting.providedBy(original)
    clone = FormData(original.context, original.request, content)
    clone.ignoreRequest = original.ignoreRequest
    clone.ignoreContent = original.ignoreContent
    clone.mode = original.mode
    clone.parent = original
    if prefix is None:
        clone.prefix = original.prefix
    else:
        clone.prefix = prefix

    # form submission related attributes
    clone.methods = original.methods
    clone.formMethod = original.formMethod
    clone.enctype = original.enctype
    clone.widgetFactoryFactory = original.widgetFactoryFactory
    
    # Unpiling the error stack
    errors = original.errors.get(clone.prefix, None)
    if errors is not None:
        # errors must be a dict-like iterable.
        # we use the convenient "Errors"
        if not ICollection.providedBy(errors):
            errors = Errors(errors)
        clone.errors = errors
    return clone
Beispiel #2
0
 def formErrors(self):
     error = self.errors.get(self.prefix, None)
     if error is None:
         return []
     if ICollection.providedBy(error):
         return error
     return [error]
    def formErrors(self):
        error = self.errors.get(self.prefix, None)

        if self.errors and error is None:
            # If the form has errors but no form specific ones
            # we have to add it. This could be overridable.
            error = Error(_(u"There were errors."), self.prefix)

        if error is not None:
            # If there's a form error, we need to make sure it's iterable.
            # Doing this, we can handle both Error and Errors.
            # Some forms can trigger more than one error, on failure.
            if ICollection.providedBy(error):
                return error
            else:
                return [error]
        return []