[Zope] Assigning One dtml-var to Another

Mike Renfro renfro@tntech.edu
Tue, 30 Oct 2001 09:18:51 -0600


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