I am a new Zope user and I guess I'm missing something fundemental that I
haven't been able to glean from the documentation and various "How-to's".
As a learning tool I am trying to implement one of Brian Lloyd's examples I
found on the Web implementing a GuestBook.  

I suspect what I don't understand is how to write the external method that
would make use of this class (The one I have been playing with follows the
class definitions).  Anyhow, I've created an an external method and call
(e.g. <dtml-var guest>) after which the guestBookForm is displayed.  After
filling out the form and submitting it Zope does not seem able to find the
signGuestBook method.  What am I doing wrong??

Other than mostly trivial examples, I haven't been able to find many
complete (working) examples of using external methods.

Thanks in advance for any help.

"""Module guestbook: a simple guestbook application"""

class GuestBook:
  """A guestbook object that provides both the forms
     and the handling of submitted form data."""

  def __init__(self, title, filename):

  def guestbookForm(self):
    """Return the guestbook from to the user"""
    return """<HTML>
              Please sign our guestbook!
              <FORM ACTION="signGuestBook" METHOD="POST">
              Name: <INPUT TYPE="TEXT" NAME="name"><BR>
              Email: <INPUT TYPE="TEXT" NAME="email"><BR>
              <INPUT TYPE="SUBMIT" VALUE="Sign Guestbook">
              </HTML>""" % (self.title, self.title)

  def successPage(self):
    """Return a page to thank the user on success"""
    return """<HTML>
              <H2>Thank You!</H2>
              Thank you for signing %s!
              </HTML>""" % (self.title, self.title)

  def signGuestBook(self, name, email='not specified'):
    """Handle a submitted guestbook form"""

    # Open a file to save the guestbook entry
      file=open(self.filename, 'a')
    except IOError:
      file=open(self.filename, 'w')
    entry='Guestbook entry: %s %s\n' % (name, email)
    return self.successPage()

External method

import sys

import guestbook

def AddGuest(self):
  myGuestBook=guestbook.GuestBook('My GuestBook', 'guestbookdata.txt')
  return myGuestBook.guestbookForm()


Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to