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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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


    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


       · 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

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT