Assigning One dtml-var to Another
Hi; I have a dtml-var called *select-blueline* It reads thus: <dtml-var expr="_.whrandom.choice(images.bluelines.objectValues(['DTML Method']))"> I need to be able to assign the value generated from this method to ANOTHER method that I can call. In other words... <dtml-var x> = <dtml-var select-blueline> Then later call <dtml-var x> How do I do this? TIA, BenO
Ben Ocean wrote:
Hi; I have a dtml-var called *select-blueline* It reads thus: <dtml-var expr="_.whrandom.choice(images.bluelines.objectValues(['DTML Method']))"> I need to be able to assign the value generated from this method to ANOTHER method that I can call. In other words... <dtml-var x> = <dtml-var select-blueline> Then later call <dtml-var x> How do I do this?
Ben, you really should be using a Python Script for this kind of logic. Why on earth are you doing it in DTML? cheers, Chris
Hi Chris, Just wanted to ask a potentially quick question. I'm pretty much a moron when it comes to python as I'm new to it all, but I've worked with zope for a year and half now and I'm getting to be pretty good at it now. What I want to know is what or why is there such a big difference between dtml and straight python? I've built some pretty complex and large sites in Zope, mind you 100% in dtml. I know it can be done in python, but when you are comfortable with something, go with it.... Is there really such a vast difference? I've written some complex session management stuff in dtml and it all works well and stably. What are some reasons that I should now learn proper python to do the same job (other than a nice check on my CV and self satisfaction for learning a scripting language)? Thanks as always, Paul Zwarts
Hi Paul, Quite simply, maintenance. Yes you can do these things in DTML (as you have done), however if you were to give me the task of of maintaining or enhancing your code and it is all in DTML it will be quite "expensive" (in time, $$, whatever your scale). By moving the non-presentation parts out into python scripts you dramatically drop the cost of maintenance. The good news is if you have 1 1/2 years of experience in DTML, i'd be surprised if it took you two weeks to become proficient in python. Why? well, it seems thats how long it takes everyone to become proficient <grin> On Tue, 2001-10-30 at 08:33, Paul Zwarts wrote:
Hi Chris,
Just wanted to ask a potentially quick question. I'm pretty much a moron when it comes to python as I'm new to it all, but I've worked with zope for a year and half now and I'm getting to be pretty good at it now. What I want to know is what or why is there such a big difference between dtml and straight python?
I've built some pretty complex and large sites in Zope, mind you 100% in dtml. I know it can be done in python, but when you are comfortable with something, go with it....
Is there really such a vast difference? I've written some complex session management stuff in dtml and it all works well and stably. What are some reasons that I should now learn proper python to do the same job (other than a nice check on my CV and self satisfaction for learning a scripting language)?
Thanks as always, Paul Zwarts
_______________________________________________ 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 ) --
Tom Jenkins Development InfoStructure http://www.devis.com
On Tue, Oct 30, 2001 at 02:33:18PM +0100, Paul Zwarts wrote:
What are some reasons that I should now learn proper python to do the same job (other than a nice check on my CV and self satisfaction for learning a scripting language)?
Any reasonably complex logic is just ugly in DTML, and a pain to adminster. Here's one conversion we did into Python -- we needed a smart object called "showMyAddressbook" that would automatically redirect the user to their own address list. But we had several different places we could store the user's folder, which would contain that addressbook: a "Staff" folder for the project, a "Staff" folder for each school, or a "Team" folder for students at a particular school (which was then stored in that school's folder). Here's the relative simplicity of the Python version, with a paramter list of schooldir='', teamdir='', userdir='': # Redirects user to their addressbook # Assumes that the user will have no more than two roles of concern: # (1) a role for their team name (Team1, Team2, Staff) # (2) an optional role for their school (TTU, ETSU) # Tacks on the user name to complete the url user=context.REQUEST.AUTHENTICATED_USER for role in user.getRoles(): if role in ('ETSU', 'TTU'): schooldir="/%s" % role else: teamdir="/%s" % role userdir="/%s" % user context.REQUEST.RESPONSE.redirect("%s%s%s/addressbook" % (schooldir, teamdir, userdir)) My brain exploded before we finished the DTML version -- this particular example was one of the reasons we started migrating some of our stuff into Python scripts. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
Paul Zwarts wrote:
What I want to know is what or why is there such a big difference between dtml and straight python?
For logic, python scripts are cleaner, more powerful and much much easier to maintain than DTML.
I've built some pretty complex and large sites in Zope, mind you 100% in dtml. I know it can be done in python, but when you are comfortable with something, go with it....
Just imagine getting rid of all the crap around the "" in your DTML tags. The stuff inside the "" is just python anyway, so you'll probably find you're quite a good python programmer by now anyway ;-) cheers, Chris
Ben Ocean writes:
I have a dtml-var called *select-blueline* It reads thus: <dtml-var expr="_.whrandom.choice(images.bluelines.objectValues(['DTML Method']))"> I need to be able to assign the value generated from this method to ANOTHER method that I can call. In other words... <dtml-var x> = <dtml-var select-blueline> Then later call <dtml-var x> How do I do this? You either use "dtml-let" or '<dtml-call "REQUEST.set('x',selectBlueLine)">'.
Dieter PS: It seems to me that background reading would not be bad... <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
participants (6)
-
Ben Ocean -
Chris Withers -
Dieter Maurer -
Mike Renfro -
Paul Zwarts -
Tom Jenkins