Obj created in ExtMethod give "not allowed to use in this context"
Dear all: I have an External Method that creates a Formulator BasicForm on the fly and returns it to a calling PageTemplate: from Products.Formulator import Form def make_form(self, origform, addlist): """Make form on the fly""" nf = Form.BasicForm() nf.add_fields( [ field for field in origform.get_fields() if field.getId() in addlist ] ) return nf This seems to work fine -- If I run the ExternalMethod, it returns a <Formulator.BasicForm> object. My ZPT calls this using tal:define, and sets it to a variable: <div tal:define="form python:here.MakeForm(here.LuachServiceListingForm, here.AddList());"> This runs without error. However, if I try to call any of the usual method calls on the new form object, I get the error that "You are not allowed to access get_groups in this context" (get_groups is a standard method for a Formulator form). (Alternatively: the goal of all this is to be able to have one Formulator form with many widgets defined, only some of which are needed for particular forms. Rather than maintaining 15 different Formulator form objects with largely overlapping stuff--ick--I'm hoping to use this technique to create a Just-In-Time Formulator form and use that. If anyone can think of a better way to do this, that would be great.) I'm under a bit of time pressure here, so as much as I normally like to explore my way to a solution, I'd appreciate a good nudge in the right direction ASAP. Thanks! - J. -- Joel BURTON | joel@joelburton | www.joelburton.com | aim:wjoelburton Information Technology & Knowledge Management Consultant
Joel Burton writes:
I have an External Method that creates a Formulator BasicForm on the fly and returns it to a calling PageTemplate:
from Products.Formulator import Form
def make_form(self, origform, addlist): """Make form on the fly""" nf = Form.BasicForm() nf.add_fields( [ field for field in origform.get_fields() if field.getId() in addlist ] ) return nf It should return an acquisition wrapped object. Try:
return nf.__of__(self) This is wrong in the ZDG. Please fix it (through a comment for it). Dieter
I just fixed it. At least in the Security chapter. ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Joel Burton" <joel@joelburton.com> Cc: "Zope@Zope. Org" <zope@zope.org>; <chrism@zope.com> Sent: Sunday, July 28, 2002 5:42 PM Subject: ZDG bug (was: [Zope] Obj created in ExtMethod give "not allowed to use in this context")
Joel Burton writes:
I have an External Method that creates a Formulator BasicForm on the fly and returns it to a calling PageTemplate:
from Products.Formulator import Form
def make_form(self, origform, addlist): """Make form on the fly""" nf = Form.BasicForm() nf.add_fields( [ field for field in origform.get_fields() if field.getId() in addlist ] ) return nf It should return an acquisition wrapped object. Try:
return nf.__of__(self)
This is wrong in the ZDG. Please fix it (through a comment for it).
Dieter
participants (3)
-
Chris McDonough -
Dieter Maurer -
Joel Burton