SV: [Zope] Adding attributes to PageTemplateFile

Carsten Gehling carsten at gehling.dk
Fri Sep 12 11:27:50 EDT 2003


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 at zope.org [mailto:zope-bounces at zope.org]På vegne af
> Josef Albert Meile
> Sendt: 12. september 2003 09:34
> Til: zope at zope.org
> Emne: Re: [Zope] Adding attributes to PageTemplateFile
>
>
> --- In zope at yahoogroups.com, Chris Withers <chrisw at 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 at 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 )
>




More information about the Zope mailing list