[Zope] - RE: Zope programming idioms

Amos Latteier amos@aracnet.com
Thu, 17 Dec 1998 15:56:53 -0800


Jeff Bauer wrote:
>Here's a question for the HowTo, now all it requires 
>is an answer :-)
>
>Seriously, my question is more Bobo related than Zope
>material, so I don't know how appropriate this is, but
>I think it will be easy to answer.
>
>----------------------------------------------------------------
>assessment_app.py:
>
>  confirm_html = DocumentTemplate.HTMLFile(dtml + "confirm.dtml")
>  
>  def assessment_validate(self, RESPONSE=None):
>    """assessment validation"""
>    # do some really important work here ...
>    if RESPONSE is not None:
>        msg = "Some important message"
>        return self.confirm_html(message=msg)  
>----------------------------------------------------------------
>
>Let's say I have a DocumentTemplate, new_assessment.dtml,
>and it's form submit method calls "assessment_validate".
>
>When the form is submitted, assessment_validate is
>called as expected.  The confirm_html document is
>explicitly called by assessment_validate with the 
>arguments manually pasted in.  This doesn't feel right, 
>however.  I'm not sure that I want to do a redirect, but 
>there must be a more natural way to:
>
>    dtml -> object method -> dtml -> whatever

Hmm, it looks alright to me, I'm not sure what the problem it.

Maybe it the '-> whatever' bit. I don't understand that part of the flow.

In general I write methods that should be accessed from the web the same
way as you do:

def spice(self,salt,pepper,REQUEST=None):
  "spice the meal"
  ...
  if REQUEST is not None:
    return self.some_dtml_class_attribute(self,REQUEST,
      message="meal successfully spiced")

If there is no need to specifically confirm the spicing operation, you
could return a different method, like index_html, the PARENT's index_html,
or manage_main, etc. depending on context.

If you wanted to you could just have some generic status method that would
display the object's current status. Then you could return this method
after each invocation of a method that might change the object's state.

Figuring out which links to return from methods is a tricky business, and
maybe is more fit for a user interface designer than a programmer.

However, I seldom find it necessary to redirect the request. I guess it
could be necessary if a method creates a new object, and you want to
display a method of that object. But then again, you could just call a
method on the object and return that... I think the only difference between
the two would be the URL displayed and the BASE.

Does this answer your question?

-Amos