Zope
  Home arrow Zope arrow Page 3 - 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 - Topics
    ( Page 3 of 4 )

     

    Let's now create a list of topics in a given category. As you saw in the previous script, we need to create a file named cat. Go ahead and create a Zope Page Template named cat. Insert the following text into it:

     

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

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

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

          <span tal:condition='here/objectValues'>

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

          </span>

          <span tal:condition='not:here/objectValues'>

             Sorry, this category contains no topics.<br />

          </span>

          <br />

          <b>New Topic</b><br />

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

             <label>Subject:</label><br />

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

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

          </form>

       </span>

    </span>

     

    Again, we use the macro to make our page's layout match the layouts of the other files. Feel free to edit the macro and experiment with different styles.

     

    We use a conditional expression to determine whether the category contains any topics. If it does, we call the file getTopics in the current context. If the folder contains no objects, we display a message which explains that there are no topics available. Finally, we create a form that allows us to add new topics. The form sends its data to a file called newTopic.

     

    Create a Script ( Python ) object with the name of getTopics. This script will create a list of topics and format them. Insert the following script into it:

     

    for topic in context.objectValues():

       if topic.meta_type == 'Folder':

          print '<a href=\'%s/topic\'>%s</a>' % ( topic.getId(), topic.getProperty ( 'title' ) )

          print '<br />By %s<br />' % ( topic.getProperty ( 'author' ) )

    return printed

     

    This script is very similar to the last script. Notice how we retrieve an author property, however.

     

    We'll now make the file newTopic. Create a Zope Page Template named newTopic and insert the following code:

     

    <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/addTopic'></span>

       </span>

    </span>

     

    We don't do anything amazing, as you can see. We only call the file addTopic in the current context. Create a Script ( Python ) named addTopic. It will do the real work. Insert the following text:

     

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

    context.manage_addProduct [ 'OFSP' ].manage_addFolder ( id, title = context.REQUEST.subject )

    replyFolder = getattr ( context, id )

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

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

    replyObject = getattr ( replyFolder, '1' )

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

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

     

    Although the code may look complicated, its function is pretty simple. First, it counts the number of topics currently in the category. For simplicity's sake, the topic folder Ids will just be numbers. The first topic will be 1, the second 2, the third 3 and so on.

     

    We then create a folder for the topic with the appropriate title. Next, we add an author property, and, finally, we create the first reply and add its author property.

     



     
     
    >>> 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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek