Newbe question concerning using python classes and external methods
All, 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): self.title=title self.filename=filename def guestbookForm(self): """Return the guestbook from to the user""" return """<HTML> <HEAD><TITLE>%s</TITLE></HEAD> <BODY> <H2>%s</H2> Please sign our guestbook! <P> <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"> </FORM> </BODY> </HTML>""" % (self.title, self.title) def successPage(self): """Return a page to thank the user on success""" return """<HTML> <HEAD><TITLE>%s</TITLE></HEAD> <BODY> <H2>Thank You!</H2> Thank you for signing %s! </BODY> </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 try: file=open(self.filename, 'a') except IOError: file=open(self.filename, 'w') entry='Guestbook entry: %s %s\n' % (name, email) file.write(entry) file.close() return self.successPage() External method import sys sys.path.append('/usr/local/src/Zope-2.1.6-linux2-x86/lib/python/Shard/jscap e/winsat') import guestbook def AddGuest(self): myGuestBook=guestbook.GuestBook('My GuestBook', 'guestbookdata.txt') return myGuestBook.guestbookForm() Brad
participants (1)
-
Gaspard, Bradley S