Re: [Zope] Adding attributes to PageTemplateFile
--- In zope@yahoogroups.com, Chris Withers <chrisw@n...> wrote:
Carsten Gehling wrote:
I have a product in which I have the following constructor
------------------------------------ software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
manage_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
Any ideas? TIA
Simplest way I can think of is:
software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
def manage_addSoftwareForm(self,*args,**kw): kw['software_type_list']=software_type_list return self._addSoftwareForm(*args,**kw) There is one even much simpler. I've used it on my JMZPTMacros product and it worked perfect:
manage_addSoftwareForm.software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ] You don't have to define the method manage_addSoftwareForm as previously suggested. You just create the attribute on the fly. Then you can call it as an attribute of your ZPT. I have tested it with simple types, but I think with a dictionary should work too. _________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
I looked at your JMZPTMacros product, and I cannot find any code, that uses the solution you presented. Anyway it doesn't work. I've tried with the list of dictionaries AND also tried with a simple string type instead. On both occasions I get an "Attribute Error", meaning that Zope cannot find the specified attribute. I use the reference "here/attribute-name". Should I use something else instead of "here" ? - Carsten
-----Oprindelig meddelelse----- Fra: zope-bounces@zope.org [mailto:zope-bounces@zope.org]På vegne af Josef Albert Meile Sendt: 12. september 2003 09:34 Til: zope@zope.org Emne: Re: [Zope] Adding attributes to PageTemplateFile
--- In zope@yahoogroups.com, Chris Withers <chrisw@n...> wrote:
Carsten Gehling wrote:
I have a product in which I have the following constructor
------------------------------------ software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
manage_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
Any ideas? TIA
Simplest way I can think of is:
software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
def manage_addSoftwareForm(self,*args,**kw): kw['software_type_list']=software_type_list return self._addSoftwareForm(*args,**kw) There is one even much simpler. I've used it on my JMZPTMacros product and it worked perfect:
manage_addSoftwareForm.software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
You don't have to define the method manage_addSoftwareForm as previously suggested. You just create the attribute on the fly.
Then you can call it as an attribute of your ZPT. I have tested it with simple types, but I think with a dictionary should work too.
_________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Sorry, it isn't an "Attribute Error", it is of course a "Key Error": Error Type: KeyError Error Value: software_type_list - Carsten
-----Oprindelig meddelelse----- Fra: zope-bounces@zope.org [mailto:zope-bounces@zope.org]På vegne af Josef Albert Meile Sendt: 12. september 2003 09:34 Til: zope@zope.org Emne: Re: [Zope] Adding attributes to PageTemplateFile
--- In zope@yahoogroups.com, Chris Withers <chrisw@n...> wrote:
Carsten Gehling wrote:
I have a product in which I have the following constructor
------------------------------------ software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
manage_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
Any ideas? TIA
Simplest way I can think of is:
software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
_addSoftwareForm = PageTemplateFile("www/software_form_add", globals())
def manage_addSoftwareForm(self,*args,**kw): kw['software_type_list']=software_type_list return self._addSoftwareForm(*args,**kw) There is one even much simpler. I've used it on my JMZPTMacros product and it worked perfect:
manage_addSoftwareForm.software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
You don't have to define the method manage_addSoftwareForm as previously suggested. You just create the attribute on the fly.
Then you can call it as an attribute of your ZPT. I have tested it with simple types, but I think with a dictionary should work too.
_________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Carsten Gehling wrote:
Sorry, it isn't an "Attribute Error", it is of course a "Key Error":
Error Type: KeyError Error Value: software_type_list
- Carsten
If you do this, you need to iterate over template/software_type_list... Chris
Josef Albert Meile wrote:
manage_addSoftwareForm.software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
That's pretty reckless, you'll need to be careful what names you use and you may run into security assertion problems... Chris
Josef Albert Meile wrote:
manage_addSoftwareForm.software_type_list = [ {'value': 'OS'}, {'value': 'Applikation'}, {'value': 'Service'} ]
That's pretty reckless, you'll need to be careful what names you use and you may run into security assertion problems... Hi Chris, I'm just wondering what's different from your approach and what kind of problem I could have.
Thanks, Josef.
Josef Meile wrote:
Hi Chris, I'm just wondering what's different from your approach and what kind of problem I could have.
In my approach, I'm replaciong a defined method with a method of the same name, and a carefully named help method. These can both be protectde by security assertions easily. In your method, you're slapping an arbitarily named attribute into a class object. They're difficult to protect in a fine grained fashion, and if you're careless with your variable names you may squish something important that you didn't mean to... Chris
In my approach, I'm replaciong a defined method with a method of the same name, and a carefully named help method. These can both be protectde by security assertions easily. I don't know what "security assertions" means, but the next paragraph makes the risks clear.
In your method, you're slapping an arbitarily named attribute into a class object. They're difficult to protect in a fine grained fashion, and if you're careless with your variable names you may squish something important that you didn't mean to... Ok, I see, I could replace something that the zope guys defined in the ZPTs source code.
You conviced me :-) If it's more secure, I'll use it, although it's a longer way. Thanks for your time, Josef
participants (4)
-
Carsten Gehling -
Chris Withers -
Josef Albert Meile -
Josef Meile