[Zope3-Users] Formlib and invariants?

mats.nordgren mats at ronin-group.org
Wed May 3 14:59:06 EDT 2006


I'm trying to do a join form with formlib and are getting errors when checking
invariants.

I have my form interface IJoinForm

class IJoinForm(Interface):
    """a join form"""
    
    username = schema.TextLine(
        title=_('User Name'),
        required=True)
    password = schema.Password(
        title=_('Password'))
    password_check = schema.Password(
        title=_('Enter Password Again'))
    title = schema.TextLine(
        title=_('Title'))
    
    @invariant
    def checkPasswords(obj):
        if obj.password != obj.password_check:
            raise Invalid("Passwords do not match")

And then I have my implementation of form.Form:

class JoinMetroSite(form.Form):
    form_fields = form.Fields(IJoinForm)
    
    @form.action('Join')
    def handle_join_action(self, action, data):
        principal_folder = zapi.getUtility(IAuthenticatorPlugin, 'principal')
        principal = InternalPrincipal(data['username'], data['password'],
data['title'])
        principal_folder[data['username']] = principal

My form in registered with:

<page
        for="*"
        class=".metrositeforms.JoinMetroSite"
        name="join.html"
        permission="zope.View"
        menu="zmi_views" title="Join" />

When I try the join.html form I get the following error:

Traceback (innermost last):
  Module zope.publisher.publish, line 138, in publish
    result = publication.callObject(request, object)
  Module zope.app.publication.zopepublication, line 161, in callObject
    return mapply(ob, request.getPositionalArguments(), request)
  Module zope.publisher.publish, line 113, in mapply
    return debug_call(object, args)
   - __traceback_info__: <security proxied
zope.app.publisher.browser.viewmeta.JoinMetroSite instance at 0x034C9B50>
  Module zope.publisher.publish, line 119, in debug_call
    return object(*args)
  Module zope.formlib.form, line 739, in __call__
    return self.render()
  Module zope.formlib.form, line 733, in render
    self.form_result = self.template()
  Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__
    return self.im_func(im_self, *args, **kw)
  Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  Module zope.pagetemplate.pagetemplate, line 117, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations)()
  Module zope.tal.talinterpreter, line 277, in __call__
    self.interpret(self.program)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 926, in do_extendMacro
    definingName, extending)
  Module zope.tal.talinterpreter, line 908, in do_useMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 538, in do_optTag_tal
    self.do_optTag(stuff)
  Module zope.tal.talinterpreter, line 523, in do_optTag
    return self.no_tag(start, program)
  Module zope.tal.talinterpreter, line 518, in no_tag
    self.interpret(program)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 976, in do_defineSlot
    self.interpret(block)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 966, in do_defineSlot
    self.interpret(slot)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 976, in do_defineSlot
    self.interpret(block)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 538, in do_optTag_tal
    self.do_optTag(stuff)
  Module zope.tal.talinterpreter, line 523, in do_optTag
    return self.no_tag(start, program)
  Module zope.tal.talinterpreter, line 518, in no_tag
    self.interpret(program)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 872, in do_condition
    self.interpret(block)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 872, in do_condition
    self.interpret(block)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 839, in do_loop_tal
    iterator = self.engine.setRepeat(name, expr)
  Module zope.tales.tales, line 685, in setRepeat
    it = self._engine.iteratorFactory(name, expr, self)
  Module zope.tales.tales, line 110, in __init__
    self._next = i.next()
  Module zope.formlib.form, line 748, in error_views
    zope.app.form.browser.interfaces.IWidgetInputErrorView)
  Module zope.component, line 154, in getMultiAdapter
    raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((<zope.interface.exceptions.Invalid instance at
0x033ED7D8>, <zope.publisher.browser.BrowserRequest instance
URL=http://localhost/MetroSite/@@join.html>), <InterfaceClass
zope.app.form.browser.interfaces.IWidgetInputErrorView>, u'')

What am I doing wrong?

Sincerely,

Mats Nordgren


More information about the Zope3-users mailing list