Creating a DTM Document in a variable folder.
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
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 <martin@digital-adventures.nl> 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
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 <martin@digital-adventures.nl> 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 cyrj@cyr.info
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 <martin@digital-adventures.nl> 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 cyrj@cyr.info
------------------------------------------------------------------------
_______________________________________________ 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
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
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
On Thu, Dec 01, 2005 at 07:40:38AM +0000, 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
participants (6)
-
Chris Withers -
J Cameron Cooper -
Jonathan Cyr -
Martin Koekenberg -
Paul Winkler -
Peter Bengtsson