Home arrow Zope arrow Page 4 - Creating Basic Zope Applications

Replies - Zope

While some people immediately understand the usefulness of Zope, others don't understand how to apply their skills. In this article, Peyton McCullough explains how to apply the skills to create a simple forum.

  1. Creating Basic Zope Applications
  2. Categories
  3. Topics
  4. Replies
By: Peyton McCullough
Rating: starstarstarstarstar / 19
January 25, 2005

print this article




We're now on the final part of our forum system: replies. As I said eariler, each reply will have its own file within the topic's folder. Create a Zope Page Template object named topic in our forum's main folder and insert this into it:


<span metal:use-macro='container/base/macros/base'>

   <h1 metal:fill-slot='title' tal:content='context/title'>Title</h1>

   <span metal:fill-slot='content'>

      <span tal:replace='structure context/getReplies'></span>

      <b>New Reply</b><br />

      <form method='POST' action='newReply'>

         <label>Author:</label><br />

         <input type='text' name='author'><br />

         <label>Message:</label><br />

         <textarea name='message' rows='10' cols='40'></textarea><br />

         <input type='submit' value='Add Reply'>





This calls the file getReplies in the current context and then outputs a forum to add replies. The form sends its data to the file newReply. This is very similar to the cat file.


The next step is to create a Script ( Python ) object by the name of getReplies. Like the getTopics script, this handles the dirty work. It gathers the replies and formats them, quoting any HTML code and handling linebreaks.


from Products.PythonScripts.standard import html_quote, newline_to_br

for reply in context.objectValues():

   print '<b>%s</b><br />' % ( reply.getProperty ( 'author' ) )

   print '%s<br /><br />' % ( newline_to_br ( html_quote ( reply ) ) )

return printed


Finally, we need to create the files required to add new replies. Create a Zope Page Template object named newReply.


<span metal:use-macro='container/base/macros/base'>

   <h1 metal:fill-slot='title' tal:content='context/title'>Title</h1>

   <span metal:fill-slot='content'>

      <span tal:replace='structure context/addReply'></span>




The only thing the page does worth noting is that it calls the file addReply in the current context. Create a Script ( Python ) object named addReply. Fill it with the following code:


id = str ( len ( context.objectIds() ) + 1 )

context.manage_addProduct [ 'OFSP' ].manage_addFile ( id, file = context.REQUEST.message )

replyObject = getattr ( context, id )

replyObject.manage_addProperty ( 'author', context.REQUEST.author, 'string' )

return 'Your reply has been added.<br />'


The script creates a new file in the topic's folder, fills it with the reply and adds an author property, giving it the appropriate value.




Your forum is now fully functional! Go ahead and test it out. Notice how easy it was to create the forum. This illustrates how easy Zope makes the creation of Web applications.


Feel free to expand the forum for extra practice. Now that you understand the basics of creating applications in Zope, you should find it quite easy. Try adding a user database or moderation and administration functions.

>>> More Zope Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: