All, I'm looking for ideas, so don't be afraid to shout any comments out. I have a hierarchy of 'documents', lots of them circa. 300 and the number will continue to grow (dramatically). These 'documents' could be of any type, XML/HTML/Images etc. What I want to do is to have some way of wrapping these documents to include a header and footer, but I want to do this at render time not before. I've got a naive Python Script (restricted) that looks like this: #=================== import string a=context.restrictedTraverse(string.join(traverse_subpath,'/'),0) if a.meta_type == 'Folder': a=a.default_html h=context.aspire_html_header_orig(None,context) f=context.aspire_html_footer_orig(None,context) c=a(None,context) return h+c+f #=================== However this has problems when rendering the header and footer (h & f), it's somehow losing the namespace and things such as PARENTS are no longer available. Any ideas? tia Phil phil.harris@zweb.co.uk
At 10:52 3/8/01 -0000, Phil Harris wrote:
I have a hierarchy of 'documents', lots of them circa. 300 and the number will continue to grow (dramatically).
These 'documents' could be of any type, XML/HTML/Images etc.
What I want to do is to have some way of wrapping these documents to include a header and footer, but I want to do this at render time not before.
Any ideas?
Lets say your pre-existing content is at folder 'documents' in several subfolders ( /documents/a, /documents/b, etc). Rename each pre-existing document to something like 'render' or 'content' or 'inside' or 'center' or whatever you want. Put a single index_html file at the Zope root. This should contain your standard layout (header, footer, sidebars, etc) Now, assuming you put each doc into its own /document subfolder and renamed it 'content', simply edit index_html (at the root) and introduce a <dtml-var content> call where the content should appear. Through the wonders of acquisition you should be able do request /document/a , /document/b , etc. and see your documents enclosed within your layout. You can still get to your documents (without layout) by goint to /document/a/content. C U! -- Mario Valente
Mario, If only things were that simple. The hierarchy is deep, wide and heavily populated at each node. The number of folders is out of my control, as is the number of 'documents' in each folder, as is the type of documents. I need a selective way of wrapping as well as all-encompassing way, e.g. I don't want to wrap Image or other binary types. Thanks for the suggestion but in this case it's a no-go. Phil phil.harris@zweb.co.uk ----- Original Message ----- From: "Mario Valente" <mvalente@ruido-visual.pt> To: "Phil Harris" <phil.harris@zope.co.uk>; <zope@zope.org> Sent: Thursday, March 08, 2001 12:00 PM Subject: Re: [Zope] Wrapping pre-existing content
At 10:52 3/8/01 -0000, Phil Harris wrote:
I have a hierarchy of 'documents', lots of them circa. 300 and the number will continue to grow (dramatically).
These 'documents' could be of any type, XML/HTML/Images etc.
What I want to do is to have some way of wrapping these documents to include a header and footer, but I want to do this at render time not before.
Any ideas?
Lets say your pre-existing content is at folder 'documents' in several subfolders ( /documents/a, /documents/b, etc).
Rename each pre-existing document to something like 'render' or 'content' or 'inside' or 'center' or whatever you want.
Put a single index_html file at the Zope root. This should contain your standard layout (header, footer, sidebars, etc)
Now, assuming you put each doc into its own /document subfolder and renamed it 'content', simply edit index_html (at the root) and introduce a <dtml-var content> call where the content should appear.
Through the wonders of acquisition you should be able do request /document/a , /document/b , etc. and see your documents enclosed within your layout. You can still get to your documents (without layout) by goint to /document/a/content.
C U!
-- Mario Valente
At 10:52 3/8/01 -0000, Phil Harris wrote:
I have a hierarchy of 'documents', lots of them circa. 300 and the number will continue to grow (dramatically).
These 'documents' could be of any type, XML/HTML/Images etc.
What I want to do is to have some way of wrapping these documents to include a header and footer, but I want to do this at render time not before.
Put a single index_html file at the Zope root. This should contain your standard layout (header, footer, sidebars, etc)
Now, assuming you put each doc into its own /document subfolder and renamed it 'content', simply edit index_html (at the root) and introduce a <dtml-var content> call where the content should appear.
Through the wonders of acquisition you should be able do request /document/a , /document/b , etc. and see your documents enclosed within your layout.
At 12:11 3/8/01 -0000, Phil Harris wrote:
If only things were that simple.
The hierarchy is deep, wide and heavily populated at each node. The number of folders is out of my control, as is the number of 'documents' in each folder, as is the type of documents.
I need a selective way of wrapping as well as all-encompassing way, e.g. I don't want to wrap Image or other binary types.
Then what about replacing that <dtml-var content> call in index_html with (aproximate code...) <dtml-in objectValues('Document')> <dtml-var sequence-item> </dtml-in> In this way you would render only the objects within a certain folder and by specifying the Meta type you should be able to select those you want. Once again remember that through acquisition index_html (which should be a method BTW) will apply the layout in index_html at the folder where its called (through the URL). C U! -- Mario Valente
On Thu, Mar 08, 2001 at 12:11:42PM -0000, Phil Harris wrote:
The hierarchy is deep, wide and heavily populated at each node. The number of folders is out of my control, as is the number of 'documents' in each folder, as is the type of documents.
I need a selective way of wrapping as well as all-encompassing way, e.g. I don't want to wrap Image or other binary types.
I haven't done it before, but I believe you could solve the problem with a Python Script, using the Subpath binding. If one of your documents is for instance /foo/bar/documents/moo/miao/quack/ye_olde_document and you have created your Python script in any other place, such as /zoo/wrapper one would reach the wrapped version of the document via the URL http://your.place/zoo/wrapper/moo/miao/quack/ye_olde_document thus invoking the `wrapper' script. The `wrapper' script would simply have to use the traverse_subpath variable in order to locate the document under /foo/bar/documents (assuming all of those to be handled by `wrapper' are stored somewhere below that folder), determine the document type, decide on how to wrap it based on its type (and eventually other document properties if you wish) and return the (conditionally) wrapped document (not forgetting to set the appropriate Content-Type header). Best regards JM
That's exactly what I've done, I'm still having some namespace problems, but I think it's mostly working. ----- Original Message ----- From: "J M Cerqueira Esteves" <jmce@artenumerica.com> To: <zope@zope.org> Sent: Thursday, March 08, 2001 1:05 PM Subject: Re: [Zope] Wrapping pre-existing content
On Thu, Mar 08, 2001 at 12:11:42PM -0000, Phil Harris wrote:
The hierarchy is deep, wide and heavily populated at each node. The number of folders is out of my control, as is the number of 'documents' in each folder, as is the type of documents.
I need a selective way of wrapping as well as all-encompassing way, e.g. I don't want to wrap Image or other binary types.
I haven't done it before, but I believe you could solve the problem with a Python Script, using the Subpath binding. If one of your documents is for instance
/foo/bar/documents/moo/miao/quack/ye_olde_document
and you have created your Python script in any other place, such as
/zoo/wrapper
one would reach the wrapped version of the document via the URL
http://your.place/zoo/wrapper/moo/miao/quack/ye_olde_document
thus invoking the `wrapper' script.
The `wrapper' script would simply have to use the traverse_subpath variable in order to locate the document under /foo/bar/documents (assuming all of those to be handled by `wrapper' are stored somewhere below that folder), determine the document type, decide on how to wrap it based on its type (and eventually other document properties if you wish) and return the (conditionally) wrapped document (not forgetting to set the appropriate Content-Type header).
Best regards JM
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Thu, Mar 08, 2001 at 10:52:18AM -0000, Phil Harris wrote:
I've got a naive Python Script (restricted) that looks like this:
#=================== import string
a=context.restrictedTraverse(string.join(traverse_subpath,'/'),0) if a.meta_type == 'Folder': a=a.default_html
h=context.aspire_html_header_orig(None,context) f=context.aspire_html_footer_orig(None,context) c=a(None,context)
return h+c+f #===================
However this has problems when rendering the header and footer (h & f), it's somehow losing the namespace and things such as PARENTS are no longer available.
Ooops, just now I noticed you were already using a wrapper script as I was suggesting... I was now going to suggest activating the namespace binding in the python script, and instead of `context' passing `_' as the second argument to the header and footer methods, but noticed that according to bindings documentation: "When the script is called from DTML, this is the caller's DTML namespace, otherwise it is an empty namespace." I can not test this now, but try to pass `context' as the first argument of the DTML methods, not as the second one. According to the documentation for the __call__ method of DTML Methods, these look up names as items in the second argument, which should be a mapping (it's common to use `_' there), but as *attributes* in the first argument. Depending on what your header and footer need in terms of namespaces, it could be necessary to pass the to-be-wrapped object to them, instead of the `context' object.
Phil Harris wrote:
I've got a naive Python Script (restricted) that looks like this:
#=================== import string
a=context.restrictedTraverse(string.join(traverse_subpath,'/'),0) if a.meta_type == 'Folder': a=a.default_html
h=context.aspire_html_header_orig(None,context) f=context.aspire_html_footer_orig(None,context) c=a(None,context)
return h+c+f #===================
However this has problems when rendering the header and footer (h & f), it's somehow losing the namespace and things such as PARENTS are no longer available.
Any ideas?
Yup, you need to bind the namespace in the above python script's bindings tab and then pass it wherever that python script is beind called, then change the last three lines to be like:
h=context.aspire_html_header_orig(None,_) f=context.aspire_html_footer_orig(None,_) c=a(None,_)
...where _ is whatever you've bound the namespace to :-) cheers, Chris
participants (4)
-
Chris Withers -
J M Cerqueira Esteves -
Mario Valente -
Phil Harris