[Zope] Organizing Zope Content

Michel Pelletier michel@digicool.com
Thu, 13 Jan 2000 14:24:40 -0500


> -----Original Message-----
> From: James W. Howe [mailto:jwh@allencreek.com]
> 
> I'm learning Zope in anticipation of using it on an upcoming 
> project.  The 
> project involves development of a web site for a weekly news 
> publication.  I've been experimenting with trying to recreate 
> a portion of 
> an existing web site which offers similar functionality to 
> what will be 
> needed for my new project.  I've started with taking some 
> existing pages in 
> HTML and refactoring them into various Zope DTML methods.  
> I'm trying to 
> restructure things so that content is separated from 
> presentation.  So far 
> I think I've been somewhat successful in building up a 
> presentation layer, 
> but I'm still using some hardwired content in places.  What I 
> want to do 
> next is set up a structure for the content which can then be 
> plugged into 
> the presentation objects.

Sounds like you're going about it the right way.
 
> I'm looking for ideas on how to structure my content.  For 
> example, one of 
> my pages needs to display headlines with little snippets of 
> the article 
> itself.  Clicking the headline would cause the full article to 
> display.  What I want to be able to do is build a structure 
> such that I 
> could iterate over items, pick up headlines, and generate the 
> headlines 
> page dynamically. 

When you have a collection of objects you want to iterate over, it is
useful to put them in a container-like data structure, like a Folder.
In your case, I think you can do everything you need by just placing all
of your articles in a Folder.  If the folder was called 'Articles' you
could do very simple iterative manipulations using the <dtml-in> tag.

<ul>
  <dtml-in Articles>
    <li><a href="<dtml-var absolute_url>"><dtml-var title_or_id></a><br>
    <dtml-var sequence-item size=200></li>
  </dtml-in>
</ul>

This will print a link to each article, showing 200 characters of the
objects body (This assumes your article objects are DTML Documents).

As an added hook point, you can write a DTML method that you pass the
object to:

  <dtml-in Articles>
    <dtml-var "displayArticle(_['sequence-item'])">
  </dtml-in>


If you place Articles and displayArticle in your root folder, then they
will be accessable from anywhere in your Zope, all objects in the root
folder are acquireable from all objects in Zope (note, when you drop to
python, you have to play by the rules of the Acquisition mechanism).


> It is also a requirement of this site that it can 
> display previous editions of the web site.  For that I would 
> like to be 
> able to invoke my headlines in such a way that it could 
> generate different 
> headlines depending on which issue of the news publication 
> was desired.

Here the catalog can help you.  If all of your article objects are
cataloged in a ZCatalog object, then you can do a very fast range search
over all of the objects' creation dates.  This is used on the Zope site
on the advanced search page when you pull down the combo box to do a
range search of objects created after a certain fixed point in the past
(day, week, month, year, ever).

The problem is that as your articles change, you need to keep cataloging
and recataloging them so that the catalog tracks any changes in the
object.  This is where things get tricky and you start developing an
application, because you need your own kind of object to do that.  This
is when you should investigate ZClasses.  There's a couple how-tos on
the Zope site on how to make your own kind of catalog aware objects.  In
fact:

http://www.zope.org/SiteIndex/search?date%3Adate=1969%2F12%2F31++16%3A00
%3A00+US%2FPacific&date_usage=range%3Amin&text_content=catalog+aware

brings up about all of them (notice the 'date' and 'range' arguments to
that URL?  All objects created after 1969!).

> Any tips on how I might structure my content (basically news 
> articles) and 
> how my presentation layer might be able to utilize the 
> content would be 
> appreciated.

Make sure that all your major components are seperated from each other
and use each other without strange dependencies (like assuming a path to
a component, why assume when it can be acquired?).  Keep collections of
similar objects in folders by themselves.  It is generally a good idea
to keep methods related to certain types of objects in the same place as
the folder that contains those objects.

Use your root folder wisely, Luke.

-Michel