[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Dynamic Content with DTML

webmaster@zope.org webmaster@zope.org
Wed, 20 Nov 2002 14:58:03 -0500


A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/DTML.stx#2-91

---------------

    Just for completeness sake, here's an implementation of the
    *hasVisitedZoo* method as a Python-based Script::

      ## Script(Python) "hasVisitedZoo"
      ##parameters=REQUEST, RESPONSE
      ##
      """
      Returns true if the user has previously visited
      the Zoo. Uses cookies to keep track of zoo visits.
      """
      if REQUEST.has_key('zooVisitCookie'):
          return 1
      else:
          RESPONSE.setCookie('zooVisitCookie', '1')
          return 0

      % Anonymous User - Apr. 20, 2002 2:50 pm:
       I think this needs to be updated.  I did get this to work though:

       ## Script (Python) "hasVisitedZoo"
       ##bind container=container
       ##bind context=context
       ##bind namespace=
       ##bind script=script
       ##bind subpath=traverse_subpath
       ##parameters=
       ##title=hasVisitedZoo
       ##
       """
       Returns true if the user has previously visited
       the zoo.  Uses cookies to keep track of zoo visits.
       """
       from Products.PythonScripts.standard import html_quote
       request = container.REQUEST
       RESPONSE =  request.RESPONSE

       if request.has_key('zooVisitCookie'):
         return 1
       else:
         RESPONSE.setCookie('zooVisitCookie', '1')
         return 0

      % krump - Aug. 27, 2002 12:12 am:
       Cutting and pasting seems to work so long as it is pasted into a Python script.

      % Anonymous User - Nov. 20, 2002 2:58 pm:
       The reason why cutting and pasting the above code does not work is because there are two spaces in front of
       each line. Deleting the spaces will fix the problem.