PUT_factory to create ZWikiPage by default - help
Following the advice of Dieter Maurer and Tres Seaver I am trying to use PUT_factory to override the default object type and create a ZWikiPage when I create a page by ange-ftp. Because I am a zope and python newbie, I am having some trouble. I will detail what I did in hope that someone can offer me some guidance 1) Created a 'Python (Script)' object in my Wiki folder and named it PUT_factory with empty 'Parameter List'. This may be part of my problem; what is the parameter list for PUT_factory? I also tried 'self, name, typ, body' 2) Added the following content to this file: #Implement the "hookable PUT" hook. import re, ZWikiPage TEXT_PATTERN = re.compile( '^text/.*$' ) def PUT_factory( self, name, typ, body ): """ """ if TEXT_PATTERN.match( typ ): return ZWikiPage( source_string='', __name__=name ) return None 3) Tried to create a ZWikiPage from emacs using ange-ftp but got an error 426. Any advice will be appreciated. Thanks, John Hunter
"John" == John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
John> Following the advice of Dieter Maurer and Tres Seaver I am John> trying to use PUT_factory to override the default object John> type and create a ZWikiPage when I create a page by John> ange-ftp. Because I am a zope and python newbie, I am John> having some trouble. OK, I have finally got this thing working. Part of the problem was that I was trying to do this as a PythonScript instead of as an ExternalMethod. But from http://www.zope.org/Members/michel/Projects/Interfaces/NewObjectPutHandler regarding PUT_factory methods: MJ> PythonScripts cannot be used for this; you cannot give Python MJ> Scripts access to classes that have been protected by MJ> permissions. This includes any class that inherits from MJ> PropertyManager, for example. I'll run though what I did step-by-step for the benefits of other newbies such as myself who want implement this: 1) Create a file in /the/path/to/zope/Extensions called PUT_ZwikiPage.py (or name it whatever you like) with the content: def PUT_factory( self, name, typ, body ): """ Override the default PUT method to make ZWikiPage the default type for ftp uploads """ from Products.ZWiki.ZWikiPage import ZWikiPage if typ == 'text/plain': return ZWikiPage( '', __name__=name ) return None # I think that returning None will invoke the default PUT handler from # NullResources.py 2) From the ZWiki folder you are working in, add an External Method with 'Select type to add'->'External Method' 3) enter the following info in the fields in the dialog box Id PUT_factory Title (optional) Module Name PUT_ZwikiPage Function Name PUT_factory 4) You're done. You should be able to create new links via ange-ftp. Thanks to Dieter Maurer, Tres Seaver, Tim Hicks, and Brian Lloyd for useful info in previous responses and posts. John Hunter
John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
I'll run though what I did step-by-step for the benefits of other newbies such as myself who want implement this:
Thanks! Linked at http://zwiki.org/HowToCreateZWikiPagesWithPut Am I right in thinking this will work with both an ftp upload or a http put ?
On Tue, Apr 17, 2001 at 08:11:21AM -0700, Simon Michael wrote:
John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
I'll run though what I did step-by-step for the benefits of other newbies such as myself who want implement this:
Thanks! Linked at http://zwiki.org/HowToCreateZWikiPagesWithPut
Am I right in thinking this will work with both an ftp upload or a http put ?
Yup. FTP uses PUT as well. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
"John" == John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:
John> I'll run though what I did step-by-step for the benefits of John> other newbies such as myself who want implement this: I have since learned that the pages described in the method above have the default 'page_type' as structuredtext. If you want manager users operating via ange-ftp to be able to create dtml enabled ZWikiPages, you need to change the default page type in the PUT_factory. I now have created two PUT_factory 'External Methods', one dtml enabled, one not. #/usr/local/Zope/Extensions/PUT_ZWikiPage.py def PUT_factory( self, name, typ, body ): """ Override the default PUT method to make ZWikiPage the default type for ftp uploads """ from Products.ZWiki.ZWikiPage import ZWikiPage if typ == 'text/plain': ob = ZWikiPage( '', __name__=name ) return ob return None #/usr/local/Zope/Extensions/PUT_ZWikiPageDTML.py def PUT_factory( self, name, typ, body ): """ Override the default PUT method to make a DTML enabled ZWikiPage the default type for ftp uploads """ from Products.ZWiki.ZWikiPage import ZWikiPage if typ == 'text/plain': ob = ZWikiPage( '', __name__=name ) ob.page_type = 'structuredtextdtml' return ob return None I've updated the HOWTO at http://zwiki.org/HowToCreateZWikiPagesWithPut with this info. BTW this was the cause of my strange dtml-var syntax behavior reported in the thread 'calling dtml-var from ZwikiPage; strange syntax': the page was created via ange-ftp and was not dtml enabled. Cheers, John Hunter
participants (3)
-
John Hunter -
Martijn Pieters -
Simon Michael