Zope
  Home arrow Zope arrow Page 4 - Creating Basic Zope Applications
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ZOPE

Creating Basic Zope Applications
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 19
    2005-01-25


    Table of Contents:
  • Creating Basic Zope Applications
  • Categories
  • Topics
  • Replies

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Creating Basic Zope Applications - Replies
    ( Page 4 of 4 )

     

    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'>

          </form>

       </span>

    </span>

     

    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>

       </span>

    </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.

     

    Conclusion

     

    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
     

       

    ZOPE ARTICLES

    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek