Hello, I wondered what is the simples (and efficient) way of implementing subj. Let I explain first what it may be needed for. Suppose we'd like to create a class modeling an article (newspaper article, for example). An article has attributes 'title' and 'body' and can contain zero or more photos. Article's body contains some HTML text exposing those photos, if any. Note the images are aggregated by article and should not be exposed anywhere else. The simplest way is to subclass our Article from (Z)ObjectManager and implement title and body as properties. On this way we are losing the DTML capabilities which we were have in DTML document/method. This is a big lost, indeed (at least we have to write <img src=img width=... height=... alt=...> instead of just <dtml-var img>). The one way to keep object DTML-aware is to subclass DTML method also. I tryed this approach and found this working, but with one exception: <dtml-var img> does not work. It does not work on _any_ callable objects. The workaround is <dtml-var "img.tag()"> or something equivalent. This is also not so good. Another approach is to render properties as DTML strings using external method: from DocumentTemplate import HTML def render_dtml (text='',mapping={},**kw) : html = HTML(text) return html(client=None,mapping=mapping) This also works fine but also has a dark side. As I found in sources, Zope stores DTML methods and documents in parsed form, this was done not just for fun, I guess. I think the parser is very expensive thing so on this way we get a great performance impact, right? Does anybody have any solution or just mention on it? Best, Mike P.S. Why nobody asked this before???
Hi Mike, Hmmm.. how about just letting each instance of your ObjectManagerish ZClass contain a "DTML Method" called story_dtml or something. Then the index_html method of the Zclass could (among other things possibly..) call <dtml-var story_dtml> which can then us all the tags your're talking about freely? more soon I'm sure... ;-) -steve
"Mike" == Mike <mike@if-site.com> writes:
Mike> Hello, Mike> I wondered what is the simples (and efficient) way of Mike> implementing subj. Mike> Let I explain first what it may be needed for. Mike> Suppose we'd like to create a class modeling an article Mike> (newspaper article, for example). An article has attributes Mike> 'title' and 'body' and can contain zero or more Mike> photos. Article's body contains some HTML text exposing Mike> those photos, if any. Note the images are aggregated by Mike> article and should not be exposed anywhere else. Mike> The simplest way is to subclass our Article from Mike> (Z)ObjectManager and implement title and body as Mike> properties. On this way we are losing the DTML capabilities Mike> which we were have in DTML document/method. This is a big Mike> lost, indeed (at least we have to write <img src=img Mike> width=... height=... alt=...> instead of just <dtml-var Mike> img>). The one way to keep object DTML-aware is to subclass Mike> DTML method also. I tryed this approach and found this Mike> working, but with one exception: <dtml-var img> does not Mike> work. It does not work on _any_ callable objects. The Mike> workaround is <dtml-var "img.tag()"> or something Mike> equivalent. This is also not so good.
participants (2)
-
Mike -
Steve Spicklemire