Re: [Zope] Creating a DTM Document in a variable folder.
On Thu, Dec 01, 2005 at 07:40:38AM +, Chris Withers wrote: > Jonathan Cyr wrote: > >You might want to use index_html rather than index.html in this > >example. The dot means other things in Python, and index.html is a > >carryover from filesystem webservers. My impression is that the > >acquisition mechanism doesn't like ids with a dot, in some circumstances. > > Acquisition works fine irrespective of the object id. > And dotted or dashed names work fine in ZPT path: > > tal:content="here/my-folder/index.html/title" > > If you use python, most objectmanagers support dictionary-like notation: > > tal:content="python:here['my-folder']['index.html'].title" > > ...and if you object doesn't support dictionary-like notation, you can > use getattr: > > getattr(getattr(here,'my-folder'),'index.html').title > > And getattr performs Acquisition just fine... ... but __getitem__ doesn't :-) So here['my-folder']['index.html'] is semantically different from getattr(getattr(here, 'my-folder'), 'index.html'). The former works strictly by local containment and does not use acquisition. The latter may use acquisition. I know Chris knows this, but maybe other people following along don't. p.s. "here" should be deprecated, use "context" instead. -- Paul Winkler http://www.slinkp.com ___ 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 )
Re: [Zope] Creating a DTM Document in a variable folder.
J Cameron Cooper wrote: self.plone['try-me'] or getattr (which doesn't use acquisition.) Eh? What on earth gave you that idea? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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 )
Re: [Zope] Creating a DTM Document in a variable folder.
Jonathan Cyr wrote: You might want to use index_html rather than index.html in this example. The dot means other things in Python, and index.html is a carryover from filesystem webservers. My impression is that the acquisition mechanism doesn't like ids with a dot, in some circumstances. Acquisition works fine irrespective of the object id. And dotted or dashed names work fine in ZPT path: tal:content="here/my-folder/index.html/title" If you use python, most objectmanagers support dictionary-like notation: tal:content="python:here['my-folder']['index.html'].title" ...and if you object doesn't support dictionary-like notation, you can use getattr: getattr(getattr(here,'my-folder'),'index.html').title And getattr performs Acquisition just fine... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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 )
Re: [Zope] Creating a DTM Document in a variable folder.
Jonathan Cyr wrote: You might want to use index_html rather than index.html in this example. The dot means other things in Python, and index.html is a carryover from filesystem webservers. My impression is that the acquisition mechanism doesn't like ids with a dot, in some circumstances. Not trying to nit-pick, just got hung-up on that item myself once before. ...or maybe that's not true anymore and has been allowed for... That just means you can't traverse to it with attribute notation. For instance:: self.plone.index.html will not look for 'index.html' but rather the 'html' inside 'index'. Same goes for dashes:: self.plone.try-me will try to subtract the value of the 'me' variable from the value of 'self.plone.try'. But usually it will fail in trying to look up the first value. In such cases, you can use "subscript" notation:: self.plone['try-me'] or getattr (which doesn't use acquisition.) --jcc Peter Bengtsson wrote: folder = getattr(context, 'b') adder = folder.manage_addProduct['OFSP'].methodAdd adder('index.html', 'Some title') That creates it with default content. To change it you'll have to call dtmlm = getattr(context, 'index.html') dtmlm.manage_edit("bla bla bla bla bla", 'Same title') # or f = open('/tmp/foobar.html') dtmlm.manage_upload(f) On 11/25/05, Martin Koekenberg <[EMAIL PROTECTED]> wrote: Hello, I don't have any Python experience yet, so who has a solution for this 'problem'. Example: I 've 3 folders a, b & c. I want to create a dtml document in a folder by a form. The folder is a variable in my form. The formis no problem, the form action is no problem. The python script to craete that document is my problem. How can I create a DTM Document in a variable container ? Regards, Martin Koekenberg ___ 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 ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ 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 ) -- Jonathan Cyr http://www.cyr.info http://www.weddingweblog.com [EMAIL PROTECTED] ___ 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 ) -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com ___ 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 )
Re: [Zope] Creating a DTM Document in a variable folder.
You might want to use index_html rather than index.html in this example. The dot means other things in Python, and index.html is a carryover from filesystem webservers. My impression is that the acquisition mechanism doesn't like ids with a dot, in some circumstances. Not trying to nit-pick, just got hung-up on that item myself once before. ...or maybe that's not true anymore and has been allowed for... HTH, -Jon Peter Bengtsson wrote: folder = getattr(context, 'b') adder = folder.manage_addProduct['OFSP'].methodAdd adder('index.html', 'Some title') That creates it with default content. To change it you'll have to call dtmlm = getattr(context, 'index.html') dtmlm.manage_edit("bla bla bla bla bla", 'Same title') # or f = open('/tmp/foobar.html') dtmlm.manage_upload(f) On 11/25/05, Martin Koekenberg <[EMAIL PROTECTED]> wrote: Hello, I don't have any Python experience yet, so who has a solution for this 'problem'. Example: I 've 3 folders a, b & c. I want to create a dtml document in a folder by a form. The folder is a variable in my form. The formis no problem, the form action is no problem. The python script to craete that document is my problem. How can I create a DTM Document in a variable container ? Regards, Martin Koekenberg ___ 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 ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ 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 ) -- Jonathan Cyr http://www.cyr.info http://www.weddingweblog.com [EMAIL PROTECTED] ___ 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 )
Re: [Zope] Creating a DTM Document in a variable folder.
folder = getattr(context, 'b') adder = folder.manage_addProduct['OFSP'].methodAdd adder('index.html', 'Some title') That creates it with default content. To change it you'll have to call dtmlm = getattr(context, 'index.html') dtmlm.manage_edit("bla bla bla bla bla", 'Same title') # or f = open('/tmp/foobar.html') dtmlm.manage_upload(f) On 11/25/05, Martin Koekenberg <[EMAIL PROTECTED]> wrote: > > Hello, > > I don't have any Python experience yet, so who has a solution for this > 'problem'. > > Example: > > I 've 3 folders a, b & c. > I want to create a dtml document in a folder by a form. The folder is a > variable in my form. > The formis no problem, the form action is no problem. The python script to > craete that document is my problem. > > How can I create a DTM Document in a variable container ? > > Regards, > > Martin Koekenberg > > ___ > 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 ) > > > -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ 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 )