Beispiel #1
0
    def process(self, context, boundTo, data):
        ## THE SPEC: self.original.typedValue.iface.__spec__
        spec = self.original.typedValue.iface.__spec__
        resultList = [None] * len(spec)
        message = ''
        results = {}
        failures = {}
        waiters = []
        for i, sub in enumerate(spec):

            def _process():
                # note, _process only works because it is called IMMEDIATELY
                # in the loop, watch out for confusing behavior if it is called
                # later when 'i' has changed
                resulti = resultList[i] = iformless.IInputProcessor(
                    sub).process(context, boundTo, data, autoConfigure=False)
                # Merge the valid value in case another fails
                results.update(resulti)

            def _except(e):
                errors = context.locate(iformless.IFormErrors)
                # XXX: It seems like this should only ever be called with a WovenContext
                # XXX: if it's using context.key. But it seems that it's only ever called with
                # XXX: a PageContext, so context.key used to be '' always?

                errors.updateErrors(getattr(context, 'key', ''), e.errors)
                pf = e.partialForm
                err = e.errors
                msg = e.formErrorMessage
                ## Set an error message for this group of bindings
                errors.setError(getattr(context, 'key', ''), msg)
                # Merge the failed value
                results.update(pf)
                # Merge the error message
                failures.update(e.errors)

            maybe = exceptblock(_process, _except, formless.ValidateError)
            if isinstance(maybe, Deferred):
                waiters.append(maybe)

        def _finish(ignored):
            if not failures:
                for specobj, result in zip(spec, resultList):
                    specobj.configure(boundTo, result)
            else:
                #print "There were validation errors. The errors were: ", failures
                raise formless.ValidateError(failures, 'Error:', results)

        return DeferredList(waiters).addBoth(_finish)
Beispiel #2
0
 def process(self, context, boundTo, data):
     ## THE SPEC: self.original.typedValue.iface.__spec__
     spec = self.original.typedValue.iface.__spec__
     resultList = [None] * len(spec)
     message = ''
     results = {}
     failures = {}
     waiters = []
     for i, sub in enumerate(spec):
         def _process():
             # note, _process only works because it is called IMMEDIATELY
             # in the loop, watch out for confusing behavior if it is called
             # later when 'i' has changed
             resulti = resultList[i] = iformless.IInputProcessor(sub).process(context, boundTo, data, autoConfigure = False)
             # Merge the valid value in case another fails
             results.update(resulti)
         def _except(e):
             errors = context.locate(iformless.IFormErrors)
             # XXX: It seems like this should only ever be called with a WovenContext
             # XXX: if it's using context.key. But it seems that it's only ever called with
             # XXX: a PageContext, so context.key used to be '' always?
             
             errors.updateErrors(getattr(context, 'key', ''), e.errors)
             pf = e.partialForm
             err = e.errors
             msg = e.formErrorMessage
             ## Set an error message for this group of bindings
             errors.setError(getattr(context, 'key', ''), msg)
             # Merge the failed value
             results.update(pf)
             # Merge the error message
             failures.update(e.errors)
         maybe = exceptblock(_process, _except, formless.ValidateError)
         if isinstance(maybe, Deferred):
             waiters.append(maybe)
     def _finish(ignored):
         if not failures:
             for specobj, result in zip(spec, resultList):
                 specobj.configure(boundTo, result)
         else:
             #print "There were validation errors. The errors were: ", failures
             raise formless.ValidateError(failures, 'Error:', results)
     return DeferredList(waiters).addBoth(_finish)
Beispiel #3
0
    def process(self, context, boundTo, data):
        spec = self.original.typedValue.iface.__spec__
        resultList = [None] * len(spec)
        message = ""
        results = {}
        failures = {}
        waiters = []
        for i, sub in enumerate(spec):

            def _process():
                resultList[i] = iformless.IInputProcessor(sub).process(context, boundTo, data, autoConfigure=False)
                resulti = resultList[i]
                results.update(resulti)

            def _except(e):
                errors = context.locate(iformless.IFormErrors)
                errors.updateErrors(getattr(context, "key", ""), e.errors)
                pf = e.partialForm
                err = e.errors
                msg = e.formErrorMessage
                errors.setError(getattr(context, "key", ""), msg)
                results.update(pf)
                failures.update(e.errors)

            maybe = exceptblock(_process, _except, formless.ValidateError)
            if isinstance(maybe, Deferred):
                waiters.append(maybe)

        def _finish(ignored):
            if not failures:
                for specobj, result in zip(spec, resultList):
                    specobj.configure(boundTo, result)
            else:
                raise formless.ValidateError(failures, "Error:", results)

        return DeferredList(waiters).addBoth(_finish)