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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
ZOPE

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Quite a nice guide!
       · This is awesome. =)Before I saw this article I couldn't really grasp the...
       · Thanks for the comments.I wrote the article because a friend of mine was...
       · Nice article - it's always refreshing to see someone covering something other than...
       · Great article. Code 90% works on my instance, but it won't compile with this:...
       · From PicMaster: May be templates are parsed and validated internally by a XML DOM...
       · Is there any way to not have it ask for a username and password when people add a...
     

       

    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-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway