You are not logged in Log in Join
You are here: Home » Zope Documentation » Books » The Zope Book Releases » The Zope Book (2.5 Edition) » Using Basic Zope Objects

Log in
Name

Password

 
Previous Page Up one Level Next Page Using Basic Zope Objects Comments On/Off Table of Contents

Chapter 3: Using Basic Zope Objects

When building a web application with Zope, you construct the application out of objects. By design, different objects handle different parts of your application. Some objects hold your content data, such as word processor documents, spreadsheets and images. Some objects handle your application's logic by accepting input from a web form, or executing a script. Some objects control the way your content is displayed, or

presented

to your viewer, for example, as a web page, or via email. In general Zope objects take three types of roles:

Content
Zope objects such as documents, images and files hold different kinds of textual and binary data. In addition to objects in Zope containing content, Zope can work with content stored externally, for example, in a relational database.

Logic
Zope has facilities for scripting business logic. Zope allows you to script behavior using Python, Perl, and SQL. "Business logic" is any kind of programming that does not involve presentation, but rather involves carrying out tasks like changing objects, sending messages, testing conditions and responding to events.

Presentation
You can control the look and feel of your site with Zope objects that act as web page templates. Zope comes with a tag based scripting language called the Document Template Markup Language (DTML) to control presentation.

Anonymous User - May 31, 2002 10:39 am:
 This three types are a bit artificial. I agree with the CONTENT. I also agree on the LOGIC section. But I am
 having some problems with the PRESENTATION layer. DTML (why did you not mention ZPT) is a mixture of LOGIC,
 CONTENT and PRESENTATION.
 After all I would say DTML belongs to the realm of LOGIC. It is a "programming" language and not "really"
 responsible for PRESENTATION. It is a means of bringing content into a site... but like HTML which mixes
STUCTURE (<p></p> etc.) and PRESENTATION (<b></b>) it is neither fish nor flesh. CSS
is an example for "pure"
 PRESENTATION.
 I read an article that said, ZOPE had a problem with the separation of CONTENT - LOGIC - PRESENTATION. To me
 it looks as if the explanation tries to show the opposite... well, it failed and creates an artifical and
 wrong separation of CONTENT, LOGIC and PRESENTATION.

Anonymous User - July 2, 2002 1:49 pm:
 Can somebody confirm this: DTML is going away and ZPT will play a bigger role?

 If this is the case, I don't want to learn DTML. Zope should have a section where both Zope and users can
 post any new "trend" or future changes.
 Thanks.

Anonymous User - Aug. 21, 2002 10:39 am:
 "...it is neither fish nor flesh." 

 Should be "neither fish nor fowl."

hansa - Sep. 20, 2002 11:15 am:
 Well, DTML is all of CONTENT/LOGIC/PRESENTATION, although only small chunks of CONTENT and LOGIC should be
 used and larger ones factored out.
 Templates synthesize the whole stuff into a (HTML) RESPONSE,
 so the separation of CONTENT/LOGIC/PRESENTATION is somewhat artificial.

Anonymous User - Nov. 29, 2002 11:44 pm:
 hgcihgug uy uoyuoy uyfuy yujhguy pyg hg y puyg

Anonymous User - Aug. 6, 2003 1:06 am:
 The seperation of content/logic/presentation has a history that predated Zope. This goes back (at least) to
 the Model/View/Control deisgn of GUIs in SmallTalk. For a full review, read Design Patterns by Gamma et
 al.(Addison-Wesley). The Zope developers are (very good) OO developers, and are using their terms quite
 accurately. The seperation may seem artificial at this point, but if you have a large project you will
 appreciate the seperation when you have to maintain or update the site.

The word object is a heavily loaded term. Depending on your background, it may mean any number of different things. In this chapter, you can think of a Zope object as an application component that you can control and edit using a web browser.

Anonymous User - July 2, 2002 1:53 pm:
 No. DTML is not going away. DTML will be around, likely forever. DTML is a more general-purpose templating
 facility than ZPT, which can only template HTML/XML content. DTML can template non-XML content like CSS and
 SQL.
Anonymous User - Nov. 7, 2002 12:43 pm:
 does dtml work with search engins?
Anonymous User - Dec. 5, 2002 2:20 pm:
Yes, Search engines see the same rendered html (meta tags and content text) as users do, the dtml code is not
 visible except at the server's management interface or via FTP views of the zope database objects appearing
 as files and folders.
Anonymous User - Jan. 4, 2003 8:48 pm:
 Surely the answer above is no - anything brought into your page dynamically by dtml would not be visible to
 search engines searching the page source - or have I misunderstood?

Zope comes with many built-in objects that help you perform different tasks. You can also install third party Zope objects to expand Zope's capabilities. This chapter explains the most basic objects and how they work. You can create fully functional Zope sites using the few basic objects that are covered in this chapter.

This chapter is loosely structured around the above three categories, Content, Logic, and Presentation. There are other kinds of objects in Zope that don't clearly fit into one of these three roles; those are explained at the end of the chapter.

hansa - Sep. 20, 2002 4:27 pm:
 This chapter largly deals with creating/editin and viewing objects through the zope managgement interface.
 The specifics of object contents are dealt in later chapters.
Anonymous User - Sep. 21, 2002 3:03 pm:
 This chapter is a grand tour through the objects of zope. Maybe here a short list of the objects treated
 below (hrefs?) might be helpful.

Using Zope Folders

Folders are the building blocks of Zope. The purpose of a folder is to contain other objects, and to organize objects by separating them into different groups.

Anonymous User - July 2, 2002 1:58 pm:
 Each time we create an object such as a folder, Zope saves everything in its database in the file Data.fs.

 Am I correct? Thanks.
Anonymous User - July 2, 2002 2:01 pm:
 Yes.
Anonymous User - Aug. 18, 2002 12:23 pm:
So are you saying that to "copy" my Zope setup to another box I could simply copy the Data.fs file? Could you
 explain the function of Data.fs.in, Data.fs.lock and Data.fs.tmp?
 Data.fs contains a lot of binary content. Is there a way to "recover" it if Zope becomes unusable?
Anonymous User - Sep. 12, 2002 5:29 pm:
 you'd at least be pretty close. worked for me once. dunno about .in, .lock, .tmp however. i guess Data.fs is
 more or less what you get if you cpickle your zope tree.
Anonymous User - Oct. 7, 2002 4:07 pm:
 If this is what you're trying to do, you're much safer using "export". It's much more likely to work.

Folders can contain all sorts of objects, including other folders, so you can nest folders inside each other to form a tree of folders. This kind of folder within a folder arrangement provides your Zope site with structure. Good structure is very important, as almost all aspects of Zope (from security to behavior to presentation) are influenced by your site's folder structure.

Folder structure should be very familiar to anyone who has worked with files and folders on their computer with a file manager program like Microsoft Windows Explorer or any one of the popular UNIX file managers like xfm, kfm, or the Gnome file manager. The Zope management interface tries to look as much as possible like these popular programs so that you are familiar with how to organize Zope objects just like you would organize files on your computer.

Anonymous User - Sep. 29, 2002 12:40 pm:
 Dies moving folders around and nesting them inside other folders to create an easy hierachy affect whether
 they can be found or not by other elements? In other words, does the exact path have to be manually changed
 in all the coding that refers to them?

Managing Folder Contents

In Chapter 2, "Using Zope" you created objects and moved objects around. In summary, you create objects in folders by choosing the type of the object you are looking for from the pull-down menu at the top of the folder's Contents view. Then you fill out the add form and submit it. A new object is then added to the current folder. You can move objects between folders using the Cut, Copy, Paste, Delete, and Rename buttons.

Importing and Exporting Objects

You can move objects from one Zope system to another using export and import. You can export all types of Zope objects to an export file. This file can then be imported into any other Zope system.

Anonymous User - Sep. 8, 2002 4:48 pm:
 "Importing and Exporting Objects" as well as the following "Temporary Folders", are unnecessary speed-bumps
 in this chapter. I realized half-way through them, "Why am I reading this? I dont care about this yet. I'm
 trying to figure out what Zope does." They should be pushed to the end of the chapter, at least.
hansa - Sep. 20, 2002 1:16 pm:
 from the top of my head i can't believe this without a grain of caveat.
 What abt missing product class or differing product class sigature?

You can think of exporting an object as cloning a piece of your Zope system into a file that you can then move around from machine to machine. You can take this file and graft the clone onto any other Zope server. Imagine you had some documents in a Zope folder. If you wanted to copy just those objects to your friend's Zope system, you could export the folder and send the export file via email to the friend, who could then import it.

Suppose you have a folder for home work that you want to export from your school Zope server, and take home with you to work on in your home Zope server. You can create a folder like this in your root folder called "homeWork". Go to the folder that contains your homeWork folder. Select the homeWork folder by checking the checkbox next to it. Then click the Import/Export button. You should now be working in the Import/Export folder view, as shown in [3-1].

Anonymous User - Aug. 15, 2002 9:40 pm:
 Just wondering what it would look like
 Wondering around
Anonymous User - Sep. 29, 2002 3:36 pm:
 fafsdf

The Import/Export View

Figure 3-1 The Import/Export View

There are two sections to this screen. The upper half is the export section and the lower half is the import section. To export an object from this screen, type the id of the object into the first form element, Export object id. In our case Zope already filled this field in for us, since we selected the homeWork folder on the last screen.

The next form option lets you choose between downloading the export file to your computer or leaving it on the server. If you check Download to local machine, and click the Export button, your web browser will prompt you to download the export file. If you check Save to file on server, then Zope will save the file on the same machine on which Zope is running, and you must fetch the file from that location yourself. The export file will be written to Zope's var directory on your server. By default export files have the .zexp file extension.

In general it's handier to download the export file to your local machine. Sometimes it's more convenient to save the file to the server instead, for example if you are on a slow link and the export file is very large, or if you are just trying to move the exported object to another Zope instance on the same computer.

Anonymous User - July 2, 2002 2:06 pm:
 Can somebody give me an example when we need another Zope instance on the same machine?
Anonymous User - July 2, 2002 2:08 pm:
 Development of Zope itself.  I have about 26 Zope instances on my machine, for instance. Really. ;-)
Anonymous User - July 2, 2002 2:14 pm:
 You are simply amazing. Thanks.

 I will not expect you to always respond this fast (just trying not to give you too much pressure). But,
 thanks, really.
Anonymous User - July 2, 2002 2:24 pm:
 Amazing, no. But comments to this book go right into my inbox, so I see them right away. ;-) - Chris
 McDonough
Anonymous User - July 2, 2002 2:46 pm:
 Chris,

 Thanks! I have been doing my research for the past week and half, trying to decide to go with
 ALOServer/OpenACS or you guys. I read the discussion between you and Don over at OpenACS. Very interesting
 and entertaining. I decided to try Zope first.
 This is the 2nd day I use Zope. It was a beautiful install yesterday. I mean very painless install (on Win
 2000). I already like it, although I know very little about it at this point.
At this point, we have a user base around 500,000 people (real people with real names & addresses). It is
 very likely we will 10x that within 2 years. I will let you know more details when we are ready.
 Zope is really a good piece of work.

 BTW, what is the easiest way to "import" a site that has about 1,000 html pages and 100 *.avi or *.mov into
 Zope? No dynamic pages or database connection in this case. Just a static site. Even run from a CD.
 Thanks again. Mike
Anonymous User - July 2, 2002 3:28 pm:
 Chris,

 Sorry. Just realize that I should post content specific questions here inside the document. You have my
 permission to remove the above one and this one.
 Thanks.

 Mike
Anonymous User - Nov. 21, 2002 3:08 pm:
 I just read the comment about comments going into Chris's inbox. 
 How could I resist commenting.

 Do you know what would be a nice feature with respect to this documentation 
 and comments? A "Make comments disappear" feature; a switch of telescoping
 script gizmo that would permit the reader to just read the documentation
 as it is without having to be constantly throwing cognitive switches that 
 say, "Ooops, there's another comment, stop concentrating and reading, jump
 visually or with the mouse or with the down arrow key, start reading again and
 (maybe) get your concentration back.

 I guess I'm showing my age but I don't think even younger people's minds
 have darwinized to parallel process this text efficiently and effectively.

 thanks.     ...edN
Anonymous User - Nov. 21, 2002 3:10 pm:
 Ooops! my bad. I just remembered that there <b>is</b> a switch to turn off
 comments. Sorry for the noise. Age is a dibilitating disease.    ...edN

The final export form element is the XML format? checkbox. Checking this box exports the object in the eXtensible Markup Language (XML) format. Leaving this box unchecked exports the file in Zope's binary format. The XML format is much bigger to download, but is human readable and XML parsable. For now, the only tool that understands this XML format is Zope itself, but in the future there may be other tools that can understand Zope's XML format. In general you should leave this box unchecked unless you're curious about what the XML format looks like and want to examine it by hand.

Anonymous User - July 2, 2002 2:20 pm:
 Would it be better for two Zope servers talk to each other over the Internet to transfer some content from
one to another, instead of exporting and importing files? I understand some programming might be necessary to
 make it happen. What is the advantage of using Import/Export versus "Internet talking"?
Anonymous User - July 2, 2002 2:22 pm:
 Security. You don't want people to be able to import code into your Zope server remotely unless they have
 filesystem access. For various and sundry reasons, allowing imports through the web (or providing a facility
 for Zopes to exchange exports) would be a huge security hole. If you want to share data between Zope
 instances, use ZEO.
Anonymous User - Aug. 2, 2002 1:44 pm:
 I found onother good (for me) reason to use XML Import/Export: remove unwanted references to products. A few
 months ago it happens that I tried a DataBase table manager product: it was not exactly what I was looking
 for, so I decided to uninstall it. But when I tried to import a small application to a distribution server,
 import was refused saying that the forementioned product was not installed (and in fact it was never
 installed on the target server).
 I had some troubles trying to tourn around the problem. Finally, I exported my piece of application using
 XML; edited it with a text editor, removing all references to the theoretically unistalled product, and
 finally I managed to get a not "contaminated" version, which this time was imported with no problem by the
 target server.
 p.t.

Click the Export button and save your homeWork.zexp export file.

Now suppose that you've gone home and want to import the file into your home Zope server. First, you must copy the export file into Zope's import directory on your server. Now, go to the Import/Export view of the folder where you want perform the import. Enter the name of the export file in the Import file name form element and click Import to import those objects into Zope.

Anonymous User - Apr. 17, 2002 4:05 am:
 When I do this, I get refused, and a comment about lacking a BTreeFolder?
Anonymous User - May 16, 2002 12:08 am:
 Considering of adding a browse/upload function?
Anonymous User - May 23, 2002 5:11 pm:
 When I do this, I get the following errors:

 Error Type: Bad Request
 Error Value: File does not exist: basic-0.9.5.zexp

 I created a root-level folder called "import". I then added a File type object from my local filesystem into
 the import folder, and set the id to the same name as the filename.
 As far as I can tell I have followed all the rules completely - any thoughts?
Anonymous User - June 12, 2002 2:57 am:
 I get the same error.  Help Please!
Anonymous User - June 12, 2002 2:34 pm:
 You need to create the import folder in the local file system (the directory where you installed Zope) and
 copy the file you want import there.
Anonymous User - Aug. 20, 2002 12:39 pm:
Can't I import files remotely? What do I do if I can not access the machine Zope is running on? c&p in
the
 text area?

Zope gives you the option to either Take ownership of imported objects or Retain existing ownership information. Ownership will be discussed more in Chapter 7, "Users and Security". For now, just leave the Take ownership of imported objects option selected.

After you import the file you should have a new object in the Zope folder where you performed the import.

To bring your homework back to school, perform the same export and import procedure. Note that you cannot import an object into a folder that has an existing object with the same id. Therefore, when you bring your homework back to school, you'll need to import it into a folder that doesn't already have a homeWork folder in it. Then, you'll need to delete your old homeWork folder and copy the newly imported one into its place.

Anonymous User - May 13, 2002 4:20 pm:
 ... or delete the old homeWork first and import the new one directly into the folder you want it in.  :)
hansa - Sep. 20, 2002 1:25 pm:
 what abt renaming the old obect?
Anonymous User - Jan. 27, 2003 11:44 pm:
 Never hurts to keep the older version until you're sure the newer one works. This seems like a "best
 practices" issue.

Temporary Folders

Temporary Folders are Zope folders that are used for storing temporary objects. Temporary Folders acts almost exactly like a regular Folder with three significant differences:

hansa - Sep. 20, 2002 1:28 pm:
 c/acts/act/

  1. Everything contained in a Temporary Folder disappears when you restart Zope.
  2. You cannot undo actions taken to objects stored a Temporary Folder.
  3. You cannot use a Version to manipulate objects in a Temporary Folder

By default there is a Temporary Folder in your root folder named temp_folder. You may notice that there is an object entitled, "Session Data Container" within temp_folder. This is an object used by Zope's default sessioning system configuration. See the "Using Sessions" section later in this chapter for more information about sessions.

Anonymous User - Jan. 4, 2003 8:55 pm:
 ref point 3 - what is a Version?

Temporary folders store their contents in RAM rather than in the Zope database. This makes them appropriate for storing small objects that receive lots of writes, such as session data. However, it's a bad idea use temporary folders to store large objects because your computer can potentially run out of RAM as a result.

Anonymous User - July 2, 2002 2:25 pm:
 How much RAM do we need to save "default" session data for each user? Thanks.
Anonymous User - July 2, 2002 2:28 pm:
 There is no such thing as "default" session data. You can estimate the amount of RAM required for each
 session by computing the size of each element you add to each session (key and value) multipled by maybe 1.5
 to account for overhead.
Anonymous User - Dec. 5, 2002 2:28 pm:
 How does a newbie determine the keys and values he/she is adding to a session/ Is there a property that
 controls this? An easy way to view what is being retained?
Anonymous User - Dec. 5, 2002 2:40 pm:
A session only retains what you put into it. Your code populates the session. If you need to see a summary of
 what's in your session, you might get away with writing a Python script that just returns the repr() of a
 session object:
 return repr(context.REQUEST.SESSION)
aathan - Jan. 24, 2003 4:02 pm:
 Note: Release 2.6.0 and 2.6.1b1 have serious session tracking bugs. Do not get frustrated if it looks like
 your session object "disappears" between requests. I will post a solution here once I have tested it.

Using Zope Page Templates

In Zope 2.5, a new, powerful type of object was added called Page Templates. Page templates allow you to define dynamic presentation for a web page by writing an HTML template. The HTML in your template is made dynamic by inserting special XML namespace elements to your HTML which define the dynamic behavior for that page.

Anonymous User - May 22, 2002 4:13 pm:
 Okay, so Page Templates are cool. But at this point in the book, we're creating Page Templates and the DTML
documents BOTH of which contain only "regular" HTML code. This paragraph/section should compare/contrast Page
 Templates and DTML documents at a high level.
Anonymous User - Sep. 8, 2002 5:04 pm:
 Before you go into the step-by-step How To, I'd like to see more interesting benefits Page Templates give
 regarding dynamic content. Something that starts with "Using templates, you'll be able to have on your Web
 site..."
hansa - Sep. 20, 2002 1:34 pm:
 In Zope 2.5, the template product is already built-in; before it was separate.
hansa - Sep. 20, 2002 1:39 pm:
 below (funny, the next paragraph shows no comment button)
 The differentiation between zope-ignorant HTML-designers and HTML-ignorant zope programmers seems a little
 bit scholastically overdrawn.
hansa - Sep. 20, 2002 2:55 pm:
 The HTML in your template is not made dynamic. 
 Your template will be used to dynamically generate HTML. This is achieved by special XML namespace elements
 you insert into into your HTML to define the dynamic rendering of that page.
 Without a little understanding of the publishing process, magic is invoked.
 And, what is "dynamic behaviour"? A pleonasm.

Page templates are powerful for a few reasons:

  • They are always valid HTML. There is no need to insert invalid code into your templates like you would with other dynamic languages.
  • Page templates separate logic from presentation. By intentionally only focusing on the goals of presentation, page templates do not allow you to use them as a general purpose programming language.
  • HTML designers do not need to be programmers. Because page templates start from an HTML mock up your HTML designers do not need to know anything about programming to develop the initial design of a page template.
  • Your programmers do not need to be HTML designers. Page templates also have a benefit the other direction, because your programmers can make your templates dynamic by just adding XML tag attributes, they can experiment with different dynamic behaviors without destroying or rewriting your original HTML.

Creating Zope Page Templates

Create a Folder called Sales in the root folder. Click on the Sales folder and then select Page Template from the add list you learned about in Chapter 2. This process will take you to the add form for a page template. Specify the id "SalesPage" and the title "Template for Sales Staff" and click Add. You have successfully created a page template. However, it's content is standard boilerplate text, so move on to the next step to edit the content.

Anonymous User - Apr. 17, 2002 10:33 am:
 This does not work with Explorer as browser on Zope 2.5.0 (both Linux and Win2K as server), you will get an
 error saying "Error Value: You are not allowed to access manage_page_header in this context not found in
 'here/manage_page_header', at line 1, column 1"
 A workaround is to use Mozilla...
Anonymous User - Apr. 22, 2002 8:26 am:
 does not work with mozilla 1.0 rc1, too. same error. a workaround is to use
 netscape 4.7 (yuck..)
Anonymous User - Apr. 29, 2002 11:12 am:
 there is no field named title
Anonymous User - May 19, 2002 1:52 pm:
 No title field, only id and file... what file? where? who wrote this and why hasn't it been checked or
 updated?
Anonymous User - June 7, 2002 5:16 pm:
 Just enter the Id as "SalesPage" and click on "Add and edit". This will take you to a new page where you can
 enter the Title. Look around a little and experiment if the instructions aren't 100% correct! :)
Anonymous User - Jan. 4, 2003 5:34 am:
 Is there a way to configure the standard boilerplate text? Where does it come from?

Editing Zope Page Templates

The easiest way to edit a page template is by clicking on its name or icon in the Zope management interface. When you click on either one of those items, you are taken to the Edit view of the page template which gives you a text-area where you can edit the template. Replace the original content that comes with the page template with the following HTML:


<html>
  <body>
    <h1>This is my first page template!</h1>
  </body>
</html>
Anonymous User - July 19, 2002 4:42 pm:
 As a complete newbie I think that it would help understanding if you actually *did* something with the ZPT
 here. Maybe this should also be right next to the DTML introduction and the example showed the major
 difference between the two. A quick line about when to use which method (DTML or ZPT) would also clarify.
 The above example is just straight HTML and doesn't actually contain any Zope Page Template functionality at
all (unlike the standard boilerplate). I could copy the same HTML into a DTML object and get the same result?
(given that there is no standard header and footer already containing the <body> and <head>
tags?). A Clearer
introduction to actually creating content ("pages" - most newbies will think in terms of what they know, that
 is HTML, CSS, JavaScript, ASP/PHP) and making it dynamic is needed IMHO. One that contrasts ZPT and DTML.

and click Save. Now you can click on the View tab to view the page template. This particular template does not do anything special or have any dynamic behavior. In later sections in this chapter, we'll add some dynamic behavior. In Chapter 5, you'll use page templates in much greater detail to create dynamic presentation.

Anonymous User - Apr. 23, 2002 3:17 am:
 Is it Test tab, instead of View tab?
Anonymous User - Apr. 25, 2002 6:20 pm:
 Looks like it is in fact the "Test" tab.
Anonymous User - Apr. 26, 2002 5:48 am:
 on a normal DTML document it's the view tab.
Anonymous User - May 6, 2002 4:13 pm:
 "... and click Save Changes..." instead "... and click Save..."
Anonymous User - July 23, 2002 10:52 pm:
 Ok. I dont get it. If there are errors found in the book, and they go into Chris's inbox, why isnt the
 documentation updated to reflect the corrections? What is the point of enabling comments if they arent used
 to improve the quality of the documentation? ...reading the comments shouldnt be required to find incorrect
 documentation.
mcdonc - July 25, 2002 9:57 am:
They comments *definitely* improve the quality of the documentation. The revision cycles just isn't aren't as
 immediate as "get comment, change docs". Instead, the comments are addressed in the prose (and removed) in
the next major editing cycle of the book. The editing cycle is meant to follow the cycle of Zope releases, so
these are meant to happen every six months or so. In the meantime, questions by way of comments are addressed
 within comments themselves, so if you are confused about something, you should probably either comment or at
 least read existing comments.
 I have found the comments invaluable and when they are addressed in prose, they make the docs much, much
 better. FWIW, you can see a (temporary) "development" version of the Zope Book 2nd edition (meant to cover
 Zope 2.6) at http://saints.homeunix.com:8081/ZopeBook. - chris
mcdonc - Sep. 21, 2002 6:43 pm:
 The saints.homeunix.com address no longer exists. The new URL for the 2.6 edition is
 http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition

Uploading Zope Page Templates

Suppose you'd prefer not to edit your HTML templates in a web browser, or you have some existing HTML pages that you'd like to bring into Zope. Zope allows you to upload your existing html files and convert them to page templates.

Select Page Template from the add menu, this will take you to the add form for page templates that we saw earlier.. The last form element on the add form is the Browse button. Click this button. Your browser will then pop up a file selection dialog box. Select the text file on your computer that you want to upload to this template.

Type in an Id for the new Document and click Add. After clicking Add, you will be taken back to the management screen. There you will see your new page template.

Anonymous User - May 16, 2002 6:58 pm:
 This section is a bit confusing. There should be a predefined template that the user loads, or not show
 expository writing that goes nowhere (erewhon?).
Anonymous User - May 19, 2002 1:55 pm:
 Well, I've read enough. I've been through a "tutorial" that doesn't appear to exist (only the samples), to
 directions on using buttons and fields that aren't there, to not knowing exactly what Zope actually contains
 (and I mean the useful things, not technospeak 'features'.)
 Thank you for alienating another upper management decisionmaker.  I'm through with Zope.
Anonymous User - May 19, 2002 2:01 pm:
That's a shame. I was looking forward to politely replying to a few more of your insulting and childish rants
 today. ;-)
Anonymous User - May 23, 2002 6:06 pm:
 This is all very easy to understand... Man, even I managed to figure out that "view" is actually "test"
unless its an actual DTML doc and didn't even slow down. So far so good. Very interesting stuff. Been waiting
 for something like this for a while (open source -- I know all the big guns have it for a much larger
 price....) :^)
Anonymous User - May 24, 2002 11:41 am:
 I'll second the above comment regarding ease of use and clarity
 of the book (and Zope). 

 If the "upper management decisionmaker" makes all decisions this
 way, I'd like to know the name of the company and go short with
 it. ;)

 (Sorry, couldn't resist the flamebait...)
Anonymous User - June 13, 2002 7:38 pm:
 Agreed. What the "upper management decision-maker" doesn't realize is that there are probably dozens of
 people here who would gladly help him/her walk through the tutorial and make sense of Zope. Note to other
 upper-management types who may be viewing this dialogue: The open-source community is generally very patient
 with people who are just getting started. Our friend who had the tantrums gave up before realizing that.
Anonymous User - June 27, 2002 5:36 pm:
 Upper Management "DECISION MAKER", that is exactly the PROBLEM!!! 
 did you ever wonder why so many tech companies are going under after wasting their money!!
 Let the technical experts make the technical decisions and you show the board the pretty pictures.
 Thank you
Anonymous User - Aug. 24, 2002 11:08 pm:
 Agreed, upper management should keep its hands off the hardware and out of the software. Pity they have to
 evaluate it to diecide whether to use it.
Anonymous User - Sep. 29, 2002 12:56 pm:
 I share some of the frustration of the decision-maker, but not being giddy from the rarefied air of the
 heights of management, am not yet ready to give up. In fact, I can;t having already paid some developers to
 create a site for me which they have not explained, so I must make sense of it all somehow.
Anonymous User - Sep. 29, 2002 12:56 pm:
 I share some of the frustration of the decision-maker, but not being giddy from the rarefied air of the
 heights of management, am not yet ready to give up. In fact, I can;t having already paid some developers to
 create a site for me which they have not explained, so I must make sense of it all somehow.
Anonymous User - Sep. 29, 2002 12:56 pm:
 I share some of the frustration of the decision-maker, but not being giddy from the rarefied air of the
 heights of management, am not yet ready to give up. In fact, I can;t having already paid some developers to
 create a site for me which they have not explained, so I must make sense of it all somehow.
Anonymous User - Sep. 29, 2002 1:00 pm:
 I was in the middle of writing the above comment when everything went wild and it posted itself three times.
 What gives?
 Anyway, I was about to say that I've found some oddities with the tutorial. For one thing, it talks about
 using the UNDO tab to, well, undo. But I cannot find any such tab on any of the possible screens. This seems
 most odd...
mcdonc - Sep. 29, 2002 4:14 pm:
 Are you logged in as a user who has  the 'Manager' role?  If not this could explain it.
AndrewJ - Dec. 6, 2002 3:44 am:
 Well so far so good. I think this is a brilliant concept of collaboration. 
 Its great to be able to have a problem and have it instantly solved by someone elses previous comment.
 Well done guys both ZOPE for bringing this together and the rest of you "US" for supporting this whole
 business in an open system environment.
Anonymous User - Dec. 17, 2002 8:26 pm:
 I understand that ZOPE is not easy, but (Wow) it is so powerfull. Everything worked gloriously so far (win98
 & XP)!
 Thanks guys!

Using Zope Documents

Documents hold text. In web applications, you generally use documents to create web pages. You can also use documents to hold text files or snippets of text or HTML code such as sidebars or headers. In addition to containing text, a document allows you to edit the text through the web. Zope has several different types of documents. The most important is DTML Document. DTML stands for Document Template Markup Language.

Anonymous User - May 27, 2002 10:26 pm:
 mengxianhui.edustar.com
Anonymous User - Sep. 8, 2002 5:09 pm:
 It would be appropriate and clarifying here to explain the difference(s) between Zope Documents and Page
 Templates. What you say above makes them seem pretty interchangeable.
hansa - Sep. 20, 2002 2:34 pm:
 The html of the server RESPONSE usually is put together from pieces, like documents. To get published,
 documents get *rendered*; for plain text or pure html, nothing needs to be done.
 Structured Text, ZPTs and DTML docs all contain instructions to some rendering preprocessor.
 The best example would be a little DTML document before and its resulting html after processing. Same for
 ZPTs. Just a condition and a small iteration with a couple of variables (like in Spicklemires/Friendly/Brand
 book p227f).
hansa - Sep. 20, 2002 2:59 pm:
 Documents do not hold text files.
 Documents hold/contain (TTW editable) text.

There are other third-party object types (generally called "Products") available from sources such as Zope.org which will extend your installation to support other types of textual and non-textual content.

Anonymous User - Sep. 8, 2002 5:10 pm:
 This bit seems out of place.  It should be expanded upon, and put in a more logical spot.
hansa - Sep. 20, 2002 2:41 pm:
 Products/classes and documents/instances/objects are different categories!
 Documents are just Objects/Instances of some document class.

DTML Documents

Use DTML Documents to create web pages and sections of documents, such as a sidebars that can be shared by web pages. DTML Documents can contain scripting commands in DTML (Zope's tag based scripting language). The mix of HTML and DTML generates dynamic web pages.

Anonymous User - Sep. 27, 2002 7:31 am:
 such as a sidebars --> such as sidebars.

DTML Documents are also useful for creating shared content, such as common document structures.

Anonymous User - Sep. 8, 2002 5:14 pm:
 This is redundant after the preceding statements. It might not be, if you explain "common document
 structures" beyond the sidebar example above.

Creating DTML Documents

Click on the Sales folder and then select DTML Document from the add list. This process will take you to the add form for a DTML Document. Specify the id "SalesStaff" and the title "The Jungle Sales Staff" and click Add. You have successfully created a DTML Document. However, its content is standard boilerplate text, so move on to the next step to edit the content.

Anonymous User - May 28, 2002 4:51 pm:
Seems to be a lot of "standard boilerplate text" when you're creating objects. Are these defaults changable?
That
 would be handy.
Anonymous User - Sep. 8, 2002 5:18 pm:
 This book would be much easier to read and understand if, in sentences like "This process will take you to
 the add form... ", you capitalized and emphasized (e.g. bold text) things like "add" in "add form...".

Editing DTML Documents

The easiest and quickest way to edit a DTML Document is through the management interface. To select a document, click on its name or icon, which will bring up the form shown in [3-2].

Editing a DTML Document

Figure 3-2 Editing a DTML Document

This view shows a text area in which you can edit the content of your document. If you click the Change button you make effective any changes you have made in the text area. You can control the size of the text area with the Taller, Shorter, Wider, and Narrower buttons. You can also upload a new file into the document with a the File text box and the Upload File button.

Anonymous User - Apr. 23, 2002 3:27 am:
 Change button --> Save Changes button
Anonymous User - May 21, 2002 11:50 am:
 well, at this point i can suppose that we have understand. If we don't see a "Change" button, may be we have
 to look at a strange-called "Save Changes" button. Don't seem to be so hard..!!
Anonymous User - June 12, 2002 10:52 pm:
 I think Zope is a very good development environment
Anonymous User - June 28, 2002 11:13 am:
 Would you please stop berating people who point out small mistakes in the documentation? For a novice user
 who isn't 100% au fait with the web it can be utterly bewildering if they're told to look for Button X and
 Button X just doesn't exist. They may assume that they've done something wrong, they're on the wrong screen,
 etc etc etc. Novice users will also quickly lose faith in documentation if the detail is actually wrong.
Anonymous User - July 14, 2002 7:13 am:
 Wider and Narrower aren't working on my Netscape 6.2 (on Linux)
 Probably some browser specific code?
Anonymous User - Sep. 8, 2002 5:29 pm:
 I agree with the "please stop berating people" person. If nothing else, this book should contain ACCURATE
 how-to steps in using Zope. Changing the button names etc. to reflect the current software should be a high
 priority for the maintainers of this book.
 Many times there are similarly-named functions presented to the user, and without an exact description, the
 user may need to guess between them. This is only bad for the adoption and evaluation of any software.

Delete the default content that is automatically inside the current SalesStaff DTML Document.

Add the following HTML content to the SalesStaff document:


<html>
<body>
<h2>Jungle Sales Staff</h2>

<ul>
  <li>Tarzan</li>
  <li>Cheetah</li>
  <li>Jane</li>
</ul>
</body>
</html>
Anonymous User - May 27, 2002 9:43 am:
 I don't know why, but sometimes I have a pbroblem with refreshing the site, after I Save the changes, the
 Test button shows me the old page. Even if i Refresh and open the folders from the Root folder again (the
 content changes are saved correctly) (using IE5)
Anonymous User - May 27, 2002 9:54 am:
 Same User:
 Right klick on View - open in new Window , Shift Refresh !
Anonymous User - June 4, 2002 11:00 am:
 I agree, there is definately a caching issue with this "dynamic" tool. You might want to change your browser
 preferences to check cache against server for every file.
Anonymous User - June 30, 2002 11:38 am:
 Could be a question of just sending some extra HTTP-headers... This is a well 
 known IE-problem which I encountered in PHP a lot... The headers can be found 
 on php.net, under the http-part of the reference-section. (check the 
 'header'-function...) These should ALWAYS be sent by any generated 
 HTML-document.
Anonymous User - Nov. 21, 2002 5:49 pm:
 >>Anonymous User - June 4, 2002 11:00 am:
 >> I agree, there is definately a caching issue 
 >>with this "dynamic" tool. You might want to 
 >>change your browser  preferences to check 
 >>cache against server for every file.
 Works well eith Opers 6.03 (Linux)

After you have completed the changes to your document, click the Change button. Zope returns with a message telling you that your changes have taken effect. Now, you can look at the document by clicking the View tab.

hansa - Sep. 20, 2002 3:09 pm:
 /_*Changes*_/_*Save Changes*_/

Congratulations! You've just used Zope to create an HTML page. You can carry out the creation and editing in one step rather than two by using the Add and Edit button on the add page.

Anonymous User - Apr. 26, 2002 12:03 am:
 Didn't we just make a DTML page?
Anonymous User - Apr. 26, 2002 10:02 pm:
 While using the DTML input template, there is nothing 'D' about the example yet.
Anonymous User - June 25, 2002 2:13 am:
 Can anyone tell me what is the difference in Page Template and DTML template as in both the cases we pasted
 some HTML code?
Anonymous User - Sep. 8, 2002 5:32 pm:
 Hello? This is a huge oversight. The only reason I'm interested in Zope is its DTML type abilities. Someone
 forgot to write this section of the book.
mcdonc - Sep. 8, 2002 11:18 pm:
 What is a huge oversight? What section of the book are you looking for? Did you notice the two chapters of
 this book with "DTML" in their titles in the book's table of contents? Did you try to read those?
Anonymous User - Sep. 9, 2002 10:09 am:
 I, like most people I'll assume who are reading this book, have come here to find out what Zope is and what
it does (and not so much the details of its interface). The heading of *this* section of the book is "Editing
 DTML Documents", leading me to believe there will be some coverage of that specific topic. From other
 comments, I know I'm not alone in that.
 What you're asking me to do (in jumping to the DTML chapters) is to already know what I'm looking for and go
straight to it. Why would I be reading this book if I already knew that? I have started from the beginning in
 order to get educated about Zope. I've read this far and I am still waiting to figure out the meat of what
 Zope does. Other comments have indicated that other readers are having the same experience.
 The very essence of this great book commenting technology should be for the maintainers to take what readers
 are saying and improve the book so that it better meets the readers' needs. Is this not so? Perhaps the
 authors are so familiar with Zope that they cannot understand the perspective of people who only have a
 tenuous idea what the software is intended to facilitate.
mcdonc - Sep. 9, 2002 12:37 pm:
 Errr... you mentioned DTML. It would make sense that you may want to read the chapters about DTML in that
 case.
Constructive criticism is of course welcome -- this is why you are encouraged to make comments to this book.
But
"it doesnt tell me what I want to know" isn't helpful because I have almost no idea what you do want to know.
 You've made it clear that the current material is insufficent. Help us make it better by telling us in
 concrete terms what can be done to make it better.
 But before you do so, know that I have tried to address the comments made to this book as best possible in
 the latest development release of the Zope Book at
 http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition. The revision of the book that you're reading
 right now is the 2.5 edition, and it hasn't had the benefit of being run through comment-editing cycle while
 the 2.6 edition has.
 As soon as we can come up for air over at Zope Corporation, Zope 2.6 will be out and that revision of the
 Zope Book will become "current". You may wish to read the 2.6 edition's first few chapters as it tones down
 some of the "gee whiz" factor of the current book's narrative. I think this tone may be at the heart of your
 complaints, and you may get a better overview of Zope from the 2.6 edition than this edition.

You can edit your HTML online and view it immediately. In fact, you can create entire Zope sites of HTML documents and folders. This process shows just the surface of Zope's benefits, but it provides a good way to familiarize yourself with Zope. You can also write some dynamic content in Zope and let those who are interested purely in design edit their own HTML web pages in this way.

hansa - Sep. 20, 2002 3:26 pm:
 Again here(and below also) HTML in the DTML section.
 Better: At the beginning of this chapter point out, that you are only explaining TTW editing using the Zope
 Management Interface (ZMI) and that the "Template" in both zpT and dTml (as well as a little bit of the
 publishing process) is explained in later chapters. Then for her&now pure HTML suffices.

Uploading an HTML File

Suppose you'd prefer not to edit your HTML files in a web browser, or you have some existing HTML pages that you'd like to bring into Zope. Zope allows you to upload your existing text files and convert them to DTML Documents.

Select DTML Document from the add menu, this will take you to the add form for DTML Documents. The last form element on the add form is the Browse button. Click this button. Your browser will then pop up a file selection dialog box. Select the text file on your computer that you want to upload to this document.

Type in an Id for the new Document and click Add. After clicking Add, you will be taken back to the management screen. There you will see your new document.

Viewing DTML Documents

The primary purpose of a DTML document is to hold useful content. This content's primary usage is to be viewed. DTML Documents can be viewed several different ways:

Management Interface
From the management interface you can Click on a Document's View tab to view the contents of the document.

Calling Directly Through the Web
Documents can be called directly through the web by going to their URL location with a web browser.

Called by Another Object
Other objects, especially other DTML objects, can display a Document's contents.

Calling Through the Web

Like all Zope objects, a DTML Document's URL is based on its id. For example, if you have a DTML Document in the root folder called Bob, then its URL would be:


http://localhost:8080/Bob

If Bob is in a sub-folder called Uncles then its URL would be:


http://localhost:8080/Uncles/Bob
hansa - Sep. 20, 2002 3:33 pm:
 Duplication. You dont want to explain folders.
 Better & shorter:
 Suppose your zope root is at http://localhost:8080 which contains a folder *Uncle* which contains a Document
 *Bob*, then the URL http://localhost:8080/Uncles/Bob
 would let you *View* the page *Bob* in a browser.

There could also be other DTML Documents in the Uncles folder called Rick, Danny and Louis. You access them through the web similarly:


http://localhost:8080/Uncles/Rick
http://localhost:8080/Uncles/Danny 
http://localhost:8080/Uncles/Louis

Translating URLs to objects isn't a new idea, web servers like Apache do it all the time. They translate URLs to files and directories on a filesystem. Zope carries this simple idea to greater heights. In Zope, URLs are always simple to read because they map easily and simply onto the way objects are organized in Zope. This is why we told you that your site's structure is key to your site's success.

hansa - Sep. 20, 2002 3:37 pm:
 This is one of the enlightening text pieces. A gem hidden in rubble.
 Give it more prominence! Show it with pride!

Going directly to the URL of a DTML Document is called calling it through the web. This causes the content of the DTML Document to be evaluated and returned to your web browser. In the next chapter on DTML, we will see what it means for DTML to be evaluated, but for now, you can easily experiment with DTML and simple HTML content to get the idea.

Calling from Another Object

In using Zope you probably have encountered examples of DTML like this:


<dtml-var standard_html_header>

  <h1>This is some simple HTML</h1>

<dtml-var standard_html_footer>
Anonymous User - July 9, 2002 1:58 am:
 Since this part of the book is introductory, assuming that the reader has "probably encountered examples of
 DTML like this" is probably incorrect.
blurg - July 14, 2002 5:29 pm:
 Zope newbies should read the docs, and experiment along, So, when you're here, you really should have seen
 this at this point. You created a DTML document previously.
 Blurg.
Anonymous User - Aug. 2, 2002 7:56 am:
 I have to agree with the July 9th post on this one. Even if you "play along" maybe it should read "One of
 your first encounters with Zope and DTML is ..." or "... right away you will encounter examples of DTML like
 this..." my 2c. --RAW--
Anonymous User - Nov. 21, 2002 11:40 am:
 Who didn't before should
 Who did should go on ...
 and comments shouldn't be made to show up different ways to say the same thing 
 without adding useful information anyway  - it makes the whole less readable

Here we see that one DTML object, standard_html_header is being called by the document that contains this code. In this case, the evaluated contents of the first document are inserted into the contents of this calling document. This is a very fundamental concept in Zope and will be used throughout the book.

Anonymous User - Sep. 8, 2002 5:49 pm:
 The terminology used is inconsistent and confusing here. If I've figured it out right, this paragraph would
 be much easier to follow if it read something like:
Here we see that a DTML object, standard_html_header, is being called by the DTML document code (?) above. In
 this case, Zope inserts the evaluated contents of the standard_html_header object into the calling document
where it reads <dtml-var standard_html_header>. This is a very fundamental concept in Zope and will be
used
 throughout the book.
 Since it's "a very fundamental concept", I think it should be spelled out more exactly. There still is some
 vagueness as to what are the DTML object(s) and the DTML document(s).

Reviewing Changes to Documents

The Undo tab lets you undo one transaction at a time, but often it is useful to undo only the change to one object. Remember, a transaction can be a group of actions all taken at the same time. If a document was edited in a transaction that also included moving an object, you may just want to undo the change to the document, but not undo moving the file. To do that, you can go to that object's History View and look at the previous states of the object, as shown in [3-4].

The History View

Figure 3-4 The History View

Anonymous User - May 27, 2002 7:19 pm:
 s/pallet/palette/

Documents even support the idea of comparing revisions, allowing you to track changes to your objects. For example, DTML Methods and Documents will allow you to select two revisions and compare them to one another. You many want to use this to see what people have done to your object, for example, let's say you had a document that contained a list of all the animals in a Zoo. If one of your co-workers then goes and edits that list and saves it, you can use the history comparison feature to compare the most recent "new" version of the file with the next most recent version.

Anonymous User - June 5, 2002 3:20 am:
 [...] You many want to use this to see what people have done to your object, [...]
 Typo: You MAY want to use...

This comparison is displayed in a popular format called diff. The diff shows you the lines that have been added to the new document (via a plus), which lines have been subtracted from the old document (via a minus), and which lines have been replaced or changed (via an exclamation point).

Anonymous User - June 20, 2002 5:46 pm:
 Where do we find these DIFF files?
Anonymous User - June 20, 2002 5:48 pm:
 Nevermind!  I should look before I ask!
Anonymous User - Sep. 21, 2002 2:22 pm:
 There is no *diff* file, there is an on the fly computed diff displayed.

Remote Editing with FTP, WebDAV, and PUT

Zope lets you edit documents directly in your web browser, though this is not the only way documents can be edited in Zope. For simple documents, editing through the web is a handy method. But for large, complex documents, or documents that have special formatting, it's useful to be able to use the editor you are most used to.

Anonymous User - July 2, 2002 1:15 am:
 this is what i wanted to now about uploadind from an ftp or golive 6.0. Its taken some time to find some
 thing this simple.
Anonymous User - July 2, 2002 8:49 am:
 If you're not patient enough to read one and a half chapters of an intro book, Zope is likely not for you.
Anonymous User - July 3, 2002 11:18 am:
 I would agree, although I enjoy reading Zope manual, it is a bit stretched and not always to the prime facts
 that a lot of people starting to use Zope look for. For those it gets too frustrating before they finish
 reading first two-three chapters and find out what it actually is.
Anonymous User - July 3, 2002 12:52 pm:
 Specific advice on how to make it better would be helpful.
Anonymous User - Aug. 10, 2002 2:22 pm:
 Is there a way to edit script files and other non-dtml object types through ftp?
 I can open any file using emacs/ftp, edit it, and save it. But any file I save
 gets turned into a DTML document, even if it was created in the Zope management 
 interface as something else. For my particular application of zope, I have more
 python scripts than DTML documents, and it would be very nice to be able to edit
 the scripts with emacs.

 On a related note, is there a way to change one object type to another through
 the management interface? I would like to turn the scripts I buggered saving thru ftp back into scripts.
hansa - Sep. 20, 2002 3:49 pm:
After (on Windows, ok) i realized CTRL-C, CTRL-V, CTRL-X for browser text areas, my life got a lot easier. On
 mass edits, still had a lot to paste.
mcdonc - Sep. 21, 2002 6:45 pm:
 Casey Duncan's "External Editor" product would help you a lot.  Search for it on Zope.org.

DTML Documents can be edited with FTP, WebDAV, and the HTTP PUT protocol. Many HTML and text editors support these protocols for editing documents on remote servers. Each of these protocols has advantages and disadvantages:

FTP
FTP is the File Transfer Protocol. FTP is used to transfer a file from one computer to another. Many text editors support FTP, so it is very useful.

WebDAV
WebDAV is a new Internet protocol based on the Web's underlying protocol, HTTP. DAV stands for Distributed Authoring and Versioning. Because DAV is new, it may not be supported by as many text editors as FTP.

PUT
The HTTP protocol supports a simple way to upload content to a server called PUT. PUT is supported by many HTML editors, such as Netscape Composer.

Using one of these methods, you can edit your content with a variety of tools. In the next couple sections, we'll show you a couple simple tools that use FTP to edit Zope content.

Anonymous User - Jan. 23, 2003 2:03 pm:
 "in the next few sections" or "in the next couple of sections"
 "show you some simple tools" or "show you a couple of simple tools"

Uploading Documents and Files with WS_FTP

WS_FTP is a popular FTP client for Windows that you can use to upload documents and files into Zope with the FTP protocol. WS_FTP can be downloaded from the Ipswitch Home Page.

Anonymous User - July 2, 2002 5:28 pm:
 I ftp a small static web site (total 50MB) into Zope. Zope database was increased by 50MB plus a bit
 overhead. I read somewhere that the current Zope has 2G limit and the development team is working to resolve
 this limitation. Can anybody confirm this? Thanks.
Anonymous User - July 2, 2002 5:42 pm:
 Zope doesn't have a 2GB limit but Python (the language in which Zope is primarily written) needs to be built
with "large file support" on platforms that allow it (Linux, Solaris, BSD, Windows NT, Windows 2K) for Python
 to be able to take advantage of files larger than 2GB. The binary distributions of Zope ship with a Python
 that is *not* large file enabled (because there is no way for us to know ahead of time whether folks will be
running on large-file capable systems). Zope's default "storage", FileStorage, keeps the Zope Object Database
(ZODB) in a single large file, which can grow to larger than 2GB if you put more than 2GB of stuff into Zope.
 This is fine if you run Zope with a Python that is compiled with large file support on a large-file-capable
 OS, but will fail if you're running Zope with a ZC-distributed Python or a Python that is otherwise not
 largefile enabled.
 The Zope development team is not working on this, per se. This issue is more one of advertising this
 limitation in the right place (for example in this book... I love being able to comment) and giving
 instructions for how to build a Python with large file support (see
 http://www.python.org/doc/current/lib/posix-large-files.html). HTH.
Anonymous User - July 2, 2002 6:55 pm:
 When I uploaded a static site into Zope, does this site have to get into ZODB? I am trying to figure out a
 way not to hit the 2GB. I have a lot of movie clips with pretty big file size.
Anonymous User - July 2, 2002 9:17 pm:
It's called "apache" or "IIS". ;-) Seriously. All content that is entered into Zope goes into the ZODB. Think
about why you're using Zope. If you want to serve out a bunch of static files... well... use apache or IIS!
Why
 not? They're perfect for this application.. however, if you want to create an application, you probably want
to try Zope. Zope is a *web application server*. Zope does not excel at being a *static file server*. There's
 nothing stopping you from combining both solutions.
Anonymous User - July 3, 2002 12:10 pm:
 That is exactly what we want to do: combining both static and dynamic pages together. Because part of our
 site is static, I am just trying to figure out the best way to ensure the best possible performance.
 90% of the site consists of static pages. Some of those static pages have links to the rest 10% dynamic
 pages. Once people "finish" the dynamic part, they will return to the 90% static content. I know Zope is
 perfect for the 10% dynamic content. I am just trying to figure out a better way to serve that 90%. However,
I do want to admit that, even if Zope is a bit worse serving static pages than Appache & IIS, overall
Zope is
 a much better solution.
Anonymous User - July 3, 2002 12:59 pm:
Use Apache in front of Zope and rewrite some of the URLs to directories that contain static files. There is a
how-to here, although I believe it may be somewhat out of date:
http://www.zope.org/Members/jec/virtual_howto_html
 . I prefer to use ProxyPass instead of PCGI or FastCGI.

There are other popular Windows FTP clients, and many web browsers like Netscape and Microsoft Internet Explorer come with FTP clients also. This section applies to other FTP clients also.

In Chapter 2, "Using Zope" you determined the URL of your Zope system by looking at the start up log. Finding out how to contact your Zope's FTP server follows a similar process:


------
2000-08-07T23:00:53 INFO(0) ZServer Medusa (V1.18) started at Mon Aug  7 
53 2000
        Hostname: peanut
        Port:8080

------
2000-08-07T23:00:53 INFO(0) ZServer FTP server started at Mon Aug  7   16:00:53 2000
        Authorizer:None
        Hostname: peanut
        Port: 8021
------
2000-08-07T23:00:53 INFO(0) ZServer Monitor Server (V1.9) started on port 8099  
Anonymous User - July 3, 2002 11:49 am:
 Is there an easy way of changing this and http ports to the default 21 (ftp) and 80 (http)? I've tried using
 z2.py script as indicated somewhere and couldn't get it done.
Anonymous User - July 8, 2002 9:56 am:
 Excerpt from the command line options for z2.py, listed in the comments at the top of z2.py:

   -P [ipaddress:]number

     Set the web, ftp and monitor port numbers simultaneously
     as offsets from the number.  The web port number will be number+80.
     The FTP port number will be number+21.  The monitor port number will
     be number+99.

 So, to get ports 80, 21 and 99, add -P 0 to your command line options for z2.py (in startup.bat on Windoze)
Anonymous User - Dec. 15, 2002 1:14 pm:
 Does this also work if Zope is being run as a service under Windows NT?

The startup log says that the Zope FTP server is listening to port 8021 on the machine named peanut. When you start WS_FTP, you will need to know the machine name and port information so you can connect to Zope via FTP. After typing in the machine name and port of your Zope server, hit the Connect button. WS_FTP will now ask you for a username and password. Enter your management username and password for the Zope management interface.

Anonymous User - Nov. 10, 2002 11:36 am:
 No go. I think my syntax in ws-ftp might be wrong. No place in ws-ftp to specify port like this. I tried for
 example peanut, peanut:8021, localhost.peanut:8021, etc (where I substituted my machine name for "peanut" in
 actual). ws-ftp has a place for port in "advanced settings" that defaults to port "21" which I presume is
 actually 8021. Tried that. Still no go.
 btw, Zope is pretty dang cool
Anonymous User - Nov. 10, 2002 11:39 am:
Oops. Read down further and found the solution. Use 127.0.0.1 instead of localhost. Worked like a charm ;-)

If you type in your username and password correctly, WS_FTP shows you what your Zope site looks like through FTP. There are folders and documents that correspond exactly to what your root Zope folder looks like through the web, as shown in [3-3].

Editing Zope through FTP

Figure 3-3 Editing Zope through FTP

Transferring files to and from Zope is a very easy task with WS_FTP. On the left-hand side of the WS_FTP window is a file selection box that represents files on your local machine. The file selection box on the right-hand side of the WS_FTP window represents objects in your Zope system. Transferring files from your computer to Zope or back again is as easy as selecting the file you want to transfer and clicking either the left arrow (download) or the right arrow (upload). WS_FTP has lots of cool features and customizations that you can use to make remote object management with Zope very easy.

Editing Zope Objects with Emacs

Emacs is a very popular text editor. In fact, Emacs is more than just a text editor, it is a whole culture. Emacs comes in two flavors, GNU Emacs and XEmacs. Both of these flavors of Emacs can work directly over FTP to manipulate Zope documents and other textual content.

zobbo - Apr. 25, 2002 10:56 pm:
 I've used both Xemacs and emacs with zope on both Windows and Linux platforms. Xemacs with cygwin is pretty
 much out of the box and ready to go. But if you want to use straight emacs be aware (as far as I can see)
 that the ftp client in windows doesn't allow you to specify a port.
 Currently I have cygwin installed and in my .emacs I have:

 (setq ange-ftp-ftp-program-name "/cygwin/bin/ftp.exe")
 (setq ange-ftp-try-passive-mode t)
 (setq ange-ftp-ftp-program-args '("-i" "-n" "-g" "-v" "--prompt" ""))

 If you don't have the last line it ain't gonna work btw ;-)

Emacs will let you treat any remote FTP system like any other local filesystem, making remote management of Zope content an easy process. Therefore, you need not leave Emacs in order to use Zope.

Emacs provides a richer set of text editing capabilities than most web browser text areas. Emacs can be used to directly edit documents and manipulate objects through FTP, therefore Emacs is a nice Zope development environment.

By default when you start up Zope, Zope runs an FTP server just as it runs an HTTP server. You can specify when you start Zope which port the FTP server should listen on, but by default this port is 8021.

To log into Zope, run Emacs. The file you visit to open an FTP connection depends on which text editor you are running: XEmacs or Emacs:

Xemacs
To visit a remote file in XEmacs, visit a file by the form:

/user@server#port:/

This will open a connection to the / folder of the FTP server running on

server

and listening on port

port

.

Emacs
To visit a remote file in Emacs, visit a file by the form:

/user@server port:/

The literal space is inserted by holding down the Control key and the Q key, and then pressing the space "C-Q ".

For the typical Zope installation with XEmacs, the filename to open up an FTP session with Zope is /user@localhost#8021:/.

Emacs will ask you for a password to log into Zope's FTP server.

Visiting the / folder of an FTP server in Zope, Emacs will list the contents of the root folder:


drwxrwx---   1 Zope     Zope            0 Dec 30  1998 Control_Panel
drwxrwx---   1 Zope     Zope            0 Dec 30  1998 QuickStart
drwxrwx---   1 Zope     Zope            0 Dec 30  1998 Sales
-rw-rw----   1 Zope     Zope         1024 May  3  1999 index_html
-rw-rw----   1 Zope     Zope         1381 May  3  1999 standard_error_message
-rw-rw----   1 Zope     Zope           55 Dec 30  1998 standard_html_footer
-rw-rw----   1 Zope     Zope           81 Dec 30  1998 standard_html_header
Anonymous User - July 22, 2002 11:44 am:
 I get the following error:

 FTP Error: OPEN request failed: ftp: localhost#8021: Unknown host.

 Any idea what might be the problem?

 Thanks.
Anonymous User - Oct. 11, 2002 9:43 pm:
 Sounds like you are using the Xemacs syntaxt in emacs.
 It seems to think the server name is "localhost#8021".
 Try using the other syntaxt.

 Another possibility to try using "127.0.0.1" instead of
 "localhost".  This will eliminate on internal step in the
 process and thereby eliminate at least one possible source
 or problems.

You can visit any of these "files" (which are really Zope objects) by selecting them in the usual Emacs way. Editing with Emacs is very useful, but for the most part, Emacs is a very complex program that is not very accessible to most people. Most Macintosh users, for example, would be very unfamiliar with a tool like Emacs. There are a number of "easier" editors that can be used that also use FTP and WebDAV. WebDAV is, in fact, designed to be used by tools like Adobe GoLive and Macromedia Dreamweaver.

Editing DTML Documents with WebDAV

WebDAV is a newer Internet protocol compared to HTTP or FTP, so there are fewer clients that support it. There is, however, a lot of momentum behind the WebDAV movement and more clients are being developed all the time. For more information on what programs support the WebDAV protocol, see the WebDAV homepage.

WebDAV is an extension to the HTTP protocol that provides rich features for many users concurrently authoring and editing content on web sites. WebDAV offers features like locking, revision control, and tagging documents or objects with properties. Because WebDAV's goals of through the web editing match some of the goals of Zope, Zope has supported the WebDAV protocol for quite a while.

The WebDAV protocol is evolving quickly, and new features are being added all the time. You can use any WebDAV client to edit your DTML Documents by simply pointing the client at your document's URL and editing it. For most clients, however, this will cause them to try to edit the result of rendering the document, not the source. For documents that use Zope's DTML template language to render dynamic content, this can be a problem.

Anonymous User - Sep. 13, 2002 3:22 pm:
 The ExternalEditor product is a great way to use webDAV to click a Zope file from the ZMI and have it open
 your favorite text editor on your computer. No more FTP uploading-- just save file in your editor and it's
 put right onto the Zope server.

Until clients catch up to the latest WebDAV standard and understand the difference between the source of a document and its result, Zope offers a special HTTP server you can enable with the -W command line option. This server listens on a different port than your normal HTTP server and returns different, special source content for WebDAV requests that come in on that port. This is an advanced feature and is explained more in the Documentation Section of Zope.org.

Using Zope Files

Zope Files contain raw data, just as the files on your computer do. Lots of information, like software, audio, video and documents are transported around the Internet and the world as files. You can use files to hold any kind of information that Zope doesn't specifically support, such as Flash files, applets, tarballs, etc.

Anonymous User - Sep. 8, 2002 5:58 pm:
 Please be more explicit that Files are another kind of Zope Object.
Anonymous User - Sep. 21, 2002 2:28 pm:
 Maybe use a different font for zope meta_type names (like "File") so these are not confused with ordinary
 parlance?

Files do not consider their contents to be of any special format, textual or otherwise. Files are good for holding any kind of binary content which is just raw computer information of some kind. Files are also good for holding textual content that doesn't need DTML scripting.

Every File object has a particular content type which is a standard Internet MIME designation for file type. When you upload a file into Zope, Zope tries to guess the content type from the name of the file, but Zope doesn't always guess correctly.

Uploading Files

Like DTML Documents and Methods, Files allow you to upload a file from your computer when you create a new object. Click the Browse button to choose a file from your local computer when creating a new Zope File. Try choosing a file such as a Word file (.doc) or a Portable Document Format (.pdf) file. Note, when uploading a file with your browser, you may have to indicate the file type you're looking for in your browser's upload dialog box. After selecting a file to upload, click Add. Depending on the size of the file you want to upload, it may take a few minutes to add the file to Zope.

Anonymous User - May 13, 2002 12:21 pm:
 I have noticed when I upload files and images using Opera 6.01 the files become corrupted. (i.e. Flash games
 will not work, images will be only half there) IE does not have the same problem.

After adding the File, click on the new File and look at its Edit view. Here you will see that Zope has guessed the content type as shown in [3-5].

File content-type property

Figure 3-5 File content-type property

If you add a Word document, the content type is application/msword. If you add a PDF file, the content type is application/pdf. If Zope does not recognize the file type, it chooses the default, generic content type of application/octet-stream.

You can change the contents of an existing File by going to the Upload view. Here you can replace the contents of the File with a new file. If you don't fill in an id and title in this form and you upload a file, Zope will use the filename as the id and the title of the object.

Editing Files

If your File holds text and is less than 64K, then Zope lets you edit it in the management interface. A text file is one that has a content-type that starts with text/, such as text/html, or text/plain. You may sometimes find it convenient to edit text files in the management interface. In any case, you can always edit files locally and then upload them to Zope.

Anonymous User - June 20, 2002 3:17 pm:
 How can I access the content of the uploaded file (text/html) using python? I uploaded a file object using

 <dtml-call expr="importArchive.manage_addFile(id='infile', file=file, content_type='text/plain')">

 and want to parse the contents of infile to insert it into a database.
Anonymous User - Oct. 4, 2002 8:46 am:
 *In any case, you can always edit files locally and then upload them to Zope.* 

What if I want to edit a file of which I don't have a local copy? Must I download it locally, edit it an then
 upload it back to the zope server every time?
Anonymous User - Nov. 8, 2002 5:24 pm:
 Anonymous User - november 08, 2002 08: 25 pm:
 <dtml-call expr* import archiv>

Viewing Files

You can view a file by going to the View tab from the management interface. You can also view a File by visiting its URL. In fact the View tab is just a way to get to a File's URL from the Zope management interface. For example, if you have a file in your Zope root folder called employeeAgreement.pdf then you can view that file in your web browser by going to the URL http://localhost:8080/employeeAgreement.pdf. Depending on the type of the file, your web browser may display the file or download it.

Anonymous User - June 4, 2002 2:26 pm:
 The viewer's browser applications/plug-ins preferences will decide how the file is displayed (ie. open
 Acrobat plug-in for pdf's). The last sentence make it sound like Zope is making the decision on what the
 browser does with the file.
Anonymous User - June 7, 2002 5:43 pm:
 It clearly states, "Your WEB BROWSER may display the file or download it." Without going into the technical
 details on browser plugins, this is clearly sufficient. Further, the sentance implies in no way that ZOPE is
responsible for the decision. However, indirectly it is. From within zopy set the context for the file, thus,
tell the browser what plugin to call. In effect Zope does make the decision, or rather, through zope you edit
 the document context which is read and interpreted by the browser.

Using Zope Images

Images display graphics such as GIF, JPEG, and PNG files. In Zope, Images are similar to File objects, but include extra behavior for managing graphic content.

Image objects have the same management interface as file objects. Everything in the previous section about using file objects also applies to images. However, Image objects show you a preview of the image when you upload them.

Viewing Images with HTML

The most common use for Images in Zope is putting pictures in web pages. To put a picture into a web page, you need to use the HTML IMG tag. Suppose you have an Image object in your root folder called logo that contains an image of your organizations logo.

Using this Image in your HTML is a straight forward process: you can reference it with an IMG tag as you'd do to include any type of image in a web page:


<dtml-var standard_html_header>

  <img src="logo">

  <h1>Welcome!</h1>

<dtml-var standard_html_footer>

In this example, you reference the logo image by creating an HTML IMG tag, but usually it is not necessary to create your own IMG tags to display images. Image objects know how to generate their own HTML tags. When you insert an Image object in DTML, it generates an IMG tag for itself.

Anonymous User - Sep. 9, 2002 10:28 am:
 Can the DTML image object insert any attributes into the IMG tag, like WIDTH or HEIGHT? This is important to
 me to have IMG tags attributed for rendering and accessibility (ALT=""). Does Zope have any facility for
 this, or do I need to continue to do it by hand?
Anonymous User - Sep. 9, 2002 10:38 am:
 Ah, this is answered below and in Appendix B.  Sorry!

Now, we want this logo to be seen on every page up in the upper left-hand corner, so put a reference to it in the standard_html_header method:


<html>
  <body>
    <dtml-var logo>
Anonymous User - June 4, 2002 2:44 pm:
 An extra note here would be in order about "Acquisition".
This file "logo" is in the same directory or it can be in any parent directory. however with the promotion of
 using folders to organize files, explaination of how an IMG link would go to a child folder would be most
 helpfull.
Anonymous User - June 21, 2002 6:06 pm:
 Suppose you have a folder at root level called "images" where image objects are, and you have and image with
 name "myImage" ..then it would be like this:
 <img src="images/myImage"  
 ...  so its folder + / + image object name
Anonymous User - June 25, 2002 1:29 pm:
 I would assume that standard ".." notation for moving up in the directory
 structure still applies?  (in other words, if "logo" is in the root directory,
 and you are in another directory within root, then you would access it with
 <img src="../logo">)
Anonymous User - Aug. 2, 2002 4:40 am:
That doesn't work for me, I have an image in Sales, so I write <dtml-var Sales/float.jpg> and I just
get an
 error, <img src=Sales/float.jpg> works, so what's wrong?
Anonymous User - Aug. 2, 2002 4:43 am:
 I tried it again with renaming it to float and it still doesn't work, it works though if it is in the root
 directory with the standardhtmlheader file, but why can't it be in any other directory to work?
Anonymous User - Sep. 9, 2002 10:33 am:
 Is standard_html_header a method or an object? Both? What kind of object would it be? I'm having trouble
 keeping these concepts clear.
hansa - Sep. 20, 2002 4:22 pm:
 Aug 2: this is a dtml-question, post to [email protected] ("Sales['float.jpg']" or so)
 Sep 9: its a method. Methods dont have properties (like "title"), they aquire them from their callers.
Anonymous User - Sep. 21, 2002 2:41 pm:
 standard_html_header is an object with a "meta_type" "DTML Method" in the zope object database, pre-built-in
 zopes root folder. It contains executable dtml.

Now, view the root folder by clicking on the View tab. If you look at the source to the web page that Zope creates, you can see that the var DTML code was turned into an HTML IMG tag for you:


<html>
  <body>
    <img src="logo" width="50"  height="30">
Anonymous User - July 22, 2002 12:17 pm:
 The image appears just fine, but the source was not converted to an img tag for me (using linux and
 netscape). It still appears as <dtml-var x>.
Anonymous User - Sep. 25, 2002 2:46 pm:
You were probably looking at the source of the file in *Zope*. To look at the HTML code that was sent to your
 browser, use the View > Source, or equivalent menu entry in your *browser*.

Using the DTML var tag to draw Images makes things simple, because Zope automatically figures out the height and width attributes of the IMG tag for you. If you don't like the way Zope constructs an IMG tag, it can be customized. See Appendix B for more information on the Image object and how it can control the IMG tag.

There are a number third party Zope object types (generally called "Products") for storing and viewing image content available from the visual section of Zope.org.

hansa - Sep. 20, 2002 4:25 pm:
 /number third/number of third/

Viewing Images Through the Web

Images can be viewed directly by going to their URL in your web browser. For example, let's say you want to view your company logo directly. The logo exists as an image object in your root folder. It is called logo, you can easily view it by going directly to its URL http://localhost:8080/logo.

Since Zope Images work just like images stored in a normal web server, you can access your Zope images from other web servers. Suppose you have a Zope Image whose URL is http://imageserver:8080/Birds/Parakeet.jpg. You can include this Image in any web page served from any web server using the Image's absolute URL in your web page:


<html>

<h1>Remote Image</h1>

<img src="http://imageserver:8080/Birds/Parakeet.jpg">         

</html>
Anonymous User - July 26, 2002 3:56 am:
 fff

This example shows how you can use Zope data from outside Zope using standard Internet protocols. Later in Chapter 10, "Advanced Zope Scripting" you'll see how most Zope objects can provide services to the outside world.

Using Object Properties

Properties are ways of associating information with objects in Zope. Many Zope objects, including folders and documents, support properties. Properties can label an object in order to identify its contents (many Zope content objects have a content type property). Another use for properties is to provide meta-data for an object such as its author, title, status, etc.

Properties can be more complex than strings; they can also be numbers, lists, or other data structures. All properties are managed via the Properties view. Click on an object's Properties tab and you will be taken to the properties management view, as seen in [3-6].

The Properties Management View

Figure 3-6: The Properties Management View

A property consists of a name, a value and a type. A property's type defines what kind of value or values it can have.

In [3-6] you can see that the folder has three properties, title, Author, KeyWords. The title and Author property are string properties, while the KeyWords property has a type of tokens. A tokens property is like a sequence of words.

Anonymous User - June 4, 2002 2:52 pm:
 You might want to state that these are NOT default settings. Author and KeyWords have been added to the
 default list of properties.
Anonymous User - Oct. 17, 2002 7:57 am:
 is there a way of "acquisiton" properties? if you build up already a whole tree with pages, you probably
 don�t want to add these new properties to all your pages or folders manually...
 FRS

Zope supports a number of property types. Each type is suited to a specific task. This list gives a brief overview of the kinds of properties you can create from the management interface:

string
A string is an arbitrary length sequence of characters. Strings are the most basic and useful type of property in Zope.

int
An int property is an integer, which can be any positive or negative number that is not a fraction. An int is guaranteed at least 32 bits long.

long
A long is like an integer that has no range limitation.

float
A float holds a floating point, or decimal number. Monetary values, for example, often use floats.

lines
A lines property is a sequence of strings.

tokens
A tokens property is list of words separated by spaces.

text
A text property is just like a string property, except that Zope normalizes the line ending characters (different browsers use different line ending conventions).

selection
A selection property is special, it is used to render an HTML select input widget.

multiple selection
A multiple selection property is special, it is used to render an HTML multiple select form input widget.

Properties are very useful tools for tagging your Zope objects with little bits of data or information. In conjunction with methods and scripts, properties make extending simple objects like Folders a very powerful technique.

Anonymous User - Aug. 31, 2002 2:19 am:
 You haven't mentioned here that the "selection" and "multiple selection" property types require method names
rather than literal data. Perhaps it would be useful to give an example of a method being used for this task,
 even if the example is placed in a chapter on scripting and mentioned here only as a "see the section [name]
 for an example".
Anonymous User - Sep. 25, 2002 2:50 pm:
 It is a *very* bad idea to represent money amounts with floats. You'll likely end up with rounding errors!
 You'll much better be using longs for that purpose, e.g. counting the cents instead of counting the dollars.

Coding Logic with Scripts

In traditional programming lingo, a script is a short piece of code written in a programming language. As of version 2.3, Zope now comes with two kinds of script objects: one that lets you write scripts in Python and one that lets you write scripts in Perl.

Anonymous User - May 28, 2002 7:32 pm:
 Any plans for PHP?
Anonymous User - May 28, 2002 7:52 pm:
 No plans from the publisher (Zope Corp) as of now, but several community members have made products which
 allow you to manage your PHP scripts in Zope:
   http://www.zope.org/Members/mjablonski/PHParser

   http://www.zope.org/Members/Mamey/PHP http://www.zope.org/Members/Ioan/PHPObject
Anonymous User - July 25, 2002 6:44 pm:
I would like to see an extension to this section which shows how one uses Perl scripts from within Zope. I am
a <I>newbie</I> so forgive me if I missed something obvious. From my perspective, as an
individual who has
started learning Zope, it appears as though Perl scripting ability needs to be added as a product in addition
 to the default installation. This may only be a caveat associated with NT as I have not yet tried a Unix
 based installation. In either case I feel it would be helpful to point out any issues or potential
 misunderstandings regarding this. As an out of band comment, I would like to say that this document seems to
 switch styles between aiming at "I've never used a computer before" users and "I'm already knee deep in this
 realm, just give me the buzzwords and the pointers" users.
Anonymous User - Sep. 9, 2002 10:59 am:
I'd like to side with the "out of band comment" above, and suggest that the document focus on the "I've never
 used Zope or any other Content Management System" users.

Both Python and Perl are very popular and powerful programming languages. Both Python and Perl share many similar feature: both offer powerful, rapid development, simple syntax, many add-on libraries, strong community following, and copious amounts of free, online documentation. Both languages are also open source.

Anonymous User - May 18, 2002 4:50 am:
 > Both Python and Perl share many similar feature
 > [...]
 > , simple syntax, ...

 Perl and simple syntax? :)
Anonymous User - June 15, 2002 11:12 am:
 It would really be usefull to get some more differences of these two programming languages listed here, not
 just similarities cause they really don't help in choosing. I'd crave for something like: " Python resembles
 this and that other languages where as Perl is more like YYY" and "The other is easier for beginners and the
 other more flexible if you have more experience" etc.
Anonymous User - June 15, 2002 2:48 pm:
 Me again... A Python page offers links to comparisons:
 http://www.python.org/doc/Comparisons.html#perl
 It would be nice if you linked one of those here.
Anonymous User - Sep. 9, 2002 11:17 am:
 Should read "... many similar features: ..."

Because scripts are so powerful and flexible, their possible uses are endless. Scripts are primarily used to write what is called business logic. Business logic is different than presentation logic. Presentation logic is usually written in a presentation language, like DTML, and its purpose is to display information to a user. Business logic is usually written in a scripting language, and its purpose is to manipulate information that comes from content sources (like documents or databases) or manipulate other objects. Often, presentation logic is based on top of business logic.

Anonymous User - July 3, 2002 3:14 pm:
 I don't know whether "business logic" is a standard term for the scripting languages and the programs that
 work with the information delivery, but I don't really agree with it. Not all, and nearly not all the
scripting is business related and its logic isn't always dealing with e-commerse-type of functionality. Thus,
 for example some script doing firewall log parcing and delivering it to the web-interface does more of an
 administrative task then business with its logic.
 Just an opinion.
Anonymous User - Sep. 9, 2002 11:04 am:
A good point. Not that you should use a different term than Business Logic (if that's the standard term), but
 you should note that it's not just for "business" processes. Otherwise, some readers will worry that - since
 they aren't primarily interested in financial code - they're in the wrong place.

A simple example of using scripts is building an online web form to help your users calculate the amount of compound interest on their debts. This kind of calculation involves the following procedure:

  1. You need the following information: your current account balance (or debt) called the "principal", the annual interest rate expressed as a decimal (like 0.095) called the "interest_rate", the number of times during the year interest in compounded (usually monthly), called the "periods" and the number of years from now you want to calculate, called the "years" .
  2. Divide your "interest_rate" by "periods" (usually 12). We'll call this result "i".
  3. Take "periods" and multiply it by "years". We'll call this result "n".
  4. Raise (1 + "i") to the power "n".
  5. Multiply the result by your "principal". This is the new balance (or debt).

For this example, you will need two page templates named interestRateForm and interestRateDisplay to collect the information from the user and display it, respectively. You will also need a Python-based script called calculateCompoundingInterest that will do the actual calculation. The first step is to create a web form in interestRateForm that collects "principal", "interest_rate", "periods" and "years" from your users. Here's an example interestRateForm page templates:


<html>
  <body>

  <form action="interestRateDisplay" method="POST">
  <p>Please enter the following information:</p>

  Your current balance (or debt): <input name="principal:float"><br>
  Your annual interest rate: <input name="interest_rate:float"><br>
  Number of periods in a year: <input name="periods:int"><br>
  Number of years: <input name="years:int"><br>
  <input type="submit" value=" Calculate "><br>
  </form>

  </body>
</html>
Anonymous User - June 5, 2002 5:22 am:
 I had to name my template as interestRateForm_html before Zope 2.4.0 will allow it to be displayed without
 errors.
Anonymous User - July 4, 2002 9:30 pm:
 How about:
 i = interest_rate / (100 * periods)
 n = periods * years
 return ((1 + i) ** n) * principal
Saman - Nov. 12, 2002 7:18 am:
 I get the folowing error:
 Error Type: KeyError
 Error Value: years
 can enybody help
 thank you
Anonymous User - Dec. 31, 2002 9:46 am:
 I encountered the same error.  Any help?
Anonymous User - Jan. 5, 2003 5:46 pm:
 I get the same KeyError on Years???

This form collects information and calls the interestRateDisplay template. Now, create a Python-based script called calculateCompoundingInterest that accepts four parameters, "principal", "interest_rate", "periods" and "years" with the following python code:


## Script (Python) "calculateCompoundInterest"
##parameters=principal, interest_rate, periods, years
##
""" 
Calculate compounding interest.
"""
i = interest_rate / periods
n = periods * years
return ((1 + i) ** n) * principal 
Anonymous User - July 25, 2002 4:25 pm:
 Urgent!!!

 I did exactly as instructed here. However, I got "Error Type: Undefined
  Error Value: years not found in 'years', at line 5, column 3
 ." It seems that Python script is not getting the parm "years." Anybody knows why?
Anonymous User - July 27, 2002 1:24 pm:
 I had the same problem. Solved by hacking not by science :(
 I change the variable 'years' to 'yrs' and it worked.
 Maybe the illuminati founding fathers can shed some light...
Anonymous User - July 27, 2002 2:50 pm:
 Apologize for the previous information � had the page in the cache � 
 It does not work!
Anonymous User - Aug. 13, 2002 3:49 am:
 I'm having the same problem but I don't think the problem is in the python script I think its in the
 interestRateDisplay file. I wonder if I'm having this problem because I'm running win98.
Anonymous User - Aug. 28, 2002 7:35 pm:
 Don't forget to enter param names into the Parameter List field  on the script edit form 
 (it should look like  

 Parameter List [principal, interest_rate, periods, years]

 where [ and ] mean the boundaries of entry box
Anonymous User - Sep. 21, 2002 2:52 pm:
 Are the "##" lines convention or do they carry any semantic significance?
Anonymous User - Nov. 18, 2002 2:58 pm:
 I am rather disappointed in this example. It required me to put in lines converting the parameters from
 strings to numbers. It seems that the form tags regarding variable types are being ignored.
Anonymous User - Nov. 28, 2002 2:17 am:
 When I go to edit the python script document or whatever document, I always get the initial text that comes
 when we create any document, but not the changed text/code. But when I view it, it shows the saved text.Does
 any one know why??

Enter the parameters into the Parameters List field, and the code in the body text area. The comments shown at the beginning of the code are not necessary when editing through the web. (However these comments are useful for editing scripts via FTP.)

Anonymous User - June 20, 2002 6:40 pm:
 Cool! If you enter it all in the body of the script, Zope will auto move the parameters to the parameters
 list.
hansa - Sep. 20, 2002 4:42 pm:
 Here a screenshot would be nice!

This will return the balance or debt compounded over the course of "years". Next, create a interestRateDisplay page template that calls calculateCompoundingInterest and returns the result:


<html>
  <body>

  <p>Your total balance (or debt) including compounded interest over
  <span tal:content="years">2</span> years is:</p>
  <p><b>$<span tal:content="python: here.calculateCompoundingInterest(principal, 
                                                     interest_rate,
                                                     periods,
                                                     years)" >1.00</span></b></p>

  </body>
</html>                                                           
Anonymous User - Apr. 6, 2002 10:39 am:
 Zope Error
 Zope has encountered an error while publishing this resource.

 Error Type: Undefined
 Error Value: years not found in 'years', at line 5, column 3
 ....
 ....

 # I got this error message, please help me to correct this error.
Anonymous User - Apr. 8, 2002 4:33 pm:
 i refer to the ch.9.
 and change the python expression to 
 python: here.calculateCompoundingInterest(request.form['principal'],... 
 that should be able to work.

 i'm a rookie.
Anonymous User - Apr. 11, 2002 9:53 am:
 You also need to change 
 tal:content="years" to
 tal:content="request/years"

 See ch.5
Anonymous User - Apr. 22, 2002 10:11 pm:
 create a interestRateDisplay page template that calls calculateCompoundingInterest and returns the result:
 <html>
   <body>

   <p>Your total balance (or debt) including compounded interest over
   <span tal:content="request/years">2</span> years is:</p>
   <p><b>$<span tal:content="python: here.calculateCompoundingInterest 
                                    (request.form['principal'],
                                     request.form['interest_rate'],
                                     request.form['periods'],
                                     request.form['years'])">1.00</span></b></p>

   </body>
 </html>
 #from Apr. 6, 2002 10:39 am:thank you! it works!
Anonymous User - June 5, 2002 5:19 am:
 My interestRateDisplay page template doesn't seem to be calling the Python Script.
 It just shows:

 Your total balance (or debt) including compounded interest over 2 years is:

 $1.00

 I must be missing something.
Anonymous User - June 5, 2002 5:43 pm:
 Ok, I realised that Zope Templates were not installed on my Zope. I had thot it was there by default. After
 proper installation, the scripts are now being called nicely. Thanks.
Anonymous User - June 13, 2002 9:05 pm:
I suggest improving the information given in error output. I know this makes me sound dumb, but it took me 15
 minutes to realize that the problem I had was that I'd spelled calculate incorrectly in my script name. Why
 not have a message "error: script file calculteCompoundingInterest not found"
Anonymous User - June 24, 2002 10:51 am:
 I cannot understand the syntax for the interestRateDisplay template. What is the "..tal:content=..."
attribute. Why do we have the number "2" between the openining and closing <span> tag and what is the
"1.00"
before the last closing </span> tag? Besides why do we need the "here" when we call the python python
script?
Anonymous User - July 7, 2002 12:06 am:
 For properly namespaced XML, it would be appropriate to have an xmlns:tal attribute attached to the document
 root element. However, setting any value for xmlns:tal seems to disable the dynamic features on the server
 side.
 Is there an official namespace for the tal prefix?
Anonymous User - July 7, 2002 12:19 am:
 Disregard last comment:  found it in Appendix C.  

 xmlns:tal="http://xml.zope.org/namespaces/tal"
Anonymous User - July 11, 2002 11:34 am:
I am getting the same problem as was posted by Anonymous User on the June 5th with my win98 installation. The
 python script returns with $1.00. I have tried to find more info on installing Zope Templates but have not
 succeeded. Please help!
Anonymous User - July 24, 2002 5:19 pm:
 My I humbly suggest eliminating the errors in this example as they appear so eary in this document, a user
 such as myself who has less than average familiarity with these technologies may waste an hour or so trying
 to figure out why they keep getting error messages when they cut and paste directly from the examples. It
 might lead a novice to postulate that they had installed Zope incorrectly, somehow.
Anonymous User - Aug. 3, 2002 1:54 pm:
I'm thinking that a novice is more likely not to trust anything in this book, after this bad example. --RAW--
Anonymous User - Aug. 14, 2002 1:53 pm:
 THANK YOU whoever put in the full html a while back. It worked, and it only took me a few tries to check my
 own work against it
Anonymous User - Aug. 18, 2002 3:50 pm:
 I managed to get it running by pasting the "Anonymous User - Apr. 22, 2002 10:11 pm" comment's code. But it
 would be good for the book to take at least a sentence each to define:
 tal:
 request.
 request/
 <span>

 As far as I can tell, none of those are defined previously in the document, and they're not obvious.
Anonymous User - Sep. 9, 2002 11:46 am:
 Do not assume that your readers understand what happens at

 <span tal:content="python: ...

 I am a full-time webmaster, and this is Greek to me. I can guess what's happening, but I'd much rather have
 it explained to me.
Anonymous User - Sep. 10, 2002 11:21 am:
 I now find that the tal:content element is covered in Chapter 5 (under "How Page Templates Work"). Here, at
the very least, a link to that explanation of tal syntax is necessary. You're really tripping up your readers
 by using it in example code, but not explaining it.
hansa - Sep. 20, 2002 4:54 pm:
 Well i know tal is pushed by zope folks, 
 but would a dtml-example not be more understandable?
 And maybe use local variables for request/years etc (in DTML: "let").
 To a newbie this all is still pure magic (and rookies dont know the spells).
Anonymous User - Oct. 9, 2002 8:00 am:
I think it should be emphasized here that a PAGE TEMPLATE must be used for the interestRateDisplay form.
Prior
 to this topic, there was a discussion about DTML document. So all along I thought that the
 interestRateDisplay form is a DTML document. The PAGE TEMPLATE is still new to me at this point.
If you use a DTML document, even with the suggested code for interestRateDisplay , the outcome will be wrong.
 It will always spill out 1.00 as the result.
Anonymous User - Nov. 13, 2002 4:35 pm:
 I'll try the code suggested above (April 2002) tonight. I too typed the example in as specified and triple
 checked everything for 30 minutes before giving up. For a "book" that is in revision 2.5, there is certainly
no excuse for an example that doesn't work, especially considering the error has been identified quite a long
 time ago and I downloaded the most recent e-version of the book.
 This reeks of the "gotta feel the pain" mentality, someone rationalizing that this is not a big deal and if
 you're "truly committed" you'll get over it and learn how to use it. Yes I can overcome it and learn this
tool and framework, but when the Zope World wants to know why there's only x number of programmers instead of
 x+1,000, one has to look no further than this example.
Andrew82 - Nov. 21, 2002 1:15 pm:
 The solution to the problem is to remove the spaces and quotes surrounding the expression, as follows:

 <dtml-var standard_html_header>

<p>Your total balance (or debt) including compounded interest over <dtml-var years> years
is:</p>
<p><b><dtml-var
expr=calculateCompoundingInterest(principal,interest_rate,periods,years)></b></p>

 <dtml-var standard_html_footer>
shunting - Dec. 3, 2002 3:04 pm:
 MANY THANKS to Anonymous User - Apr. 22, 2002 -- this worked for me (though I am using version 2.3.3 of Zope
 to stick with Python 1.5.2, so YMMMV).
 meta-comments:

 "yrs"->"years" not needed, probably a typo got fixed in the course of this change.

 The book says "calculateCompoundingInterest" one place and "calculateCompoundInterest" in another. That was
 MY typo.
 I sympathize with "Anonymous User - Nov. 13, 2002" -- this book is SLOPPY. Guido isn't sloppy...

 The fact that users are adding fixes is great, but wouldn't it be great if the energy was going into helping
 at a higher level than fixing typos?
 There's a lot to be said for the process of conventional publishing if it leads to examples that work "first
 time, every time."

First view the interestRateForm page template. Now, type in some information about your balance or debt and click Calculate. This will cause interestRateForm to submit the collect information to interestRateDisplay, which calls the Python-based script calculateCompoundingInterest. The display method uses the value returned by the script in the resulting display.

As we said earlier, the possibilities for using scripts is almost endless. This example, however, gives you a good idea of the most common pattern for presentation objects to collect and display information, and using business logic objects to make calculations.

Anonymous User - Sep. 10, 2002 5:38 pm:
 Would somebody PLEASE give me an example of how to alter an object's property? from a ScriptPython? from a
 PageTemplate? from a DTML<yuk>method?
 Example, I am the Owner of a folderish object with a property of id:Num, type:int, value:2000

 I would like to be able to CHANGE the value, not display it, nor use it.

 When I try from a PythonScript located in the folder...
    container.Num = 2002
 I get
    Error Value: attribute-less object (assign or del)

 This would be valid python code outside of Zope, and is the standard way to assign a variable. Is there some
 secret API I haven't found?

Using Methods

Methods are objects in Zope that hold special executable content. The name "Method" is actually a bit of a misnomer, and its use in Zope is slowly being phased out for more common terms like Script and Template.

Anonymous User - Apr. 22, 2002 4:12 pm:
 If "Method" is a misnomer and is being phased out, why is used extensively here? Why not just call them
 scripts and templates, with a little note at the beginning indicating that we used to call these "Methods"
 but that the name is deprecated?
Anonymous User - Apr. 23, 2002 6:04 pm:
 Well, he did say "slowly".  :)
hansa - Sep. 20, 2002 5:17 pm:
 In OOP parlance, an object *has* methods (with 1st parameter "self").

In Zope use here a ZODB object *is a* method object applicable to other objects if its content is executable,
 the latter usually called *Scripts* if derived from PythonScript.
 But there is also DTML Method (the executed language being DTML).
 Misnomers confuse.

Zope comes with two kinds of methods, DTML Methods and SQL Methods. DTML Methods are used to define presentation templates that you can apply to content objects like DTML Documents and Files. A very common and popular way to use DTML Methods is to define presentation layout separate from your content.

SQL Methods are used to contain database queries that you can reuse throughout your web application. SQL Methods are explained in Chapter 12, "Relational Database Connectivity", where an example of creating a web application using a relational database is given.

Anonymous User - Sep. 21, 2002 3:12 pm:
 How abt factoring ZSQL Methods out and treat only DTML Methods here?

All the various objects in Zope can be manipulated by calling methods on those objects. For example, Folder objects have an objectValues method that returns the objects contained by the folder. DTML Methods can be used to write simple scripts that call these Zope API methods. These methods are documented in the Help System, under API Documentation.

hansa - Sep. 20, 2002 5:30 pm:
The "objectValues" is a bad example in this context in so far as it is a method of the Folder class and *not*
 a zope (ZODB) method object.
 Above DTML Methods were supposed to be *presentation* only,
 while (before the introduction of PythonScripts) they were the only means of separating *logic* into one
 place.
Anonymous User - Sep. 21, 2002 2:59 pm:
 What is the difference between "methods" and "Methods"?
Anonymous User - Dec. 17, 2002 5:27 am:
 where can i get lists of all "object method" and their usage

Before Zope 2.3, DTML Methods were the only way to write scripts in Zope with your web browser. While DTML is useful for very simple scripts and for presenting information with templates, this approach had a number of limitations because DTML isn't as flexible as other programming languages.

hansa - Sep. 20, 2002 5:38 pm:
 DTML sure is flexible enuff to write even large scripts, but it was not meant for that, its clumsy and not
 elegant and meanwhile there are better ways.

Zope 2.3 introduces two new kinds of Script objects based on two very popular programming languages, Python (which Zope is written in) and Perl. You should use Python and Perl-based scripts to write more complex scripts instead of a DTML Method. While browsing through past Zope documentation, mail list archives, and other resources on "Zope.org"http://www.zope.org, you may find a lot of references to very complex DTML scripts. These pre-date Python and Perl-based scripts. In general, complex scripts should be written in either Python or Perl. Python and Perl-based scripts are described later in this chapter, and many examples of their use is given in Chapter 10, "Advanced Zope Scripting".

A simple example of using DTML Methods is to create a DTML Method in the root folder called objectList:


<dtml-var standard_html_header>

<ul>
  <dtml-in objectValues>
    <li><dtml-var getId></li>
  </dtml-in>
</ul>

<dtml-var standard_html_footer>  
kaleissin - May 16, 2002 2:01 pm:
 DTML Methods are much more handy than DTML Documents, which sometimes behave folderishly or in similarly
 unexpected ways
Anonymous User - July 25, 2002 5:25 pm:
 I am still confused with DTML document and DTML method. What is the main difference?
Anonymous User - Aug. 31, 2002 3:23 am:
 There is a section which compares DTML documents/methods further down.
hansa - Sep. 20, 2002 5:51 pm:
 Again a bad example. Better use a breadcrumbs method.
 Something having both a *_header and *_footer i would use as DTML Document. 

 From which templates should this be called? 
 To which objects should this method apply?
 Is this an index_html?

 A DTML Method doesnt have properties (like title), but acquires them from caller.

When you view this method, it calls the objectValues method on the root folder and this shows you a simple HTML list of all the objects in the root folder, as shown in [3-7].

Anonymous User - Aug. 2, 2002 9:45 am:
 The method objectValues(type-None) was described in API Reference Appendix B -> module ObjectManager.

 in the description, it mentions that this method accept ONE argument.
 But why in this example this doesn't accept any single element? and what is the difference?

 I must admit, I used to read JAVA API. But I'm confused reading this API reference.

 regards,
 H. Tan
hansa - Sep. 20, 2002 6:02 pm:
 This one argument has a defaut value ("=None"), which implies in python it is optional. Magic ;-) If given,
 parameter is either one string or a list of strings, the strings the names of object meta_types to be
 filtered. If omitted, ojbectValues() gives *all* objects in the ObjectManager. Folder derives from
 ObjectManager.
hansa - Sep. 20, 2002 6:06 pm:
 If it is a *method*. it is callable in other *contexts* than *root*, thats what methods are about, to be
 callable on different objects. The example gets shy here.

Results of the objectList DTML Method

Figure 3-7 Results of the objectList DTML Method

All folders implement the objectValues method. The objectValues method is part of an interface that all folders implement called ObjectManager.

hansa - Sep. 20, 2002 6:15 pm:
 Class *ObjectManager* _has a_ method *objectValues*. Class *Folder* inherits from *ObjectManager*, hence
 every Folder object has a method *objectValues*.
 ObjectManager is a class. Is it an Interface?

In addition to calling API methods on objects, DTML Methods can also be used in a certain way to extend any Zope object. This will be explained in more detail in the next chapter. In effect, this allows you to extend the Zope API by simply creating DTML Methods.

You just saw the objectList method, which resides in the root folder, and makes a simple list of the contents of the root folder. Because the method is in the root folder, it is now usable by any other objects in or below the root folder. This method extends the Zope API for these objects since it provides them with another callable method.

To demonstrate, let's create a subfolder called Primates and add three documents, Monkeys, Apes, Humans. You can call the objectList method on the Primates folder by visiting the URL Primates/objectList. You can see the effect of calling the objectList method on the Primates folder differs from the effect of calling it on the root folder. The objectList method is defined in the root folder, but here we are using it to display the contents of the Primates folder. This mechanism of reusing objects is called acquisition and will be explained more in Chapter 4, "Dynamic Content with DTML".

Anonymous User - June 3, 2002 2:11 pm:
 subfolder? Up until now we've called them folders. And the dropdown says "Folder". While it is proper
 English, I think you'd have less confusion if you used the term folder.
Anonymous User - June 20, 2002 6:40 pm:
 I believe the author is using subfolder to denote that the folder is inside the current folder and
 distinguishing it from a folder existing somewhere else ; for trying to invoke that method a folder that is
 not a subfolder of the current one will not work. In this sense, he has used the term subfolder properly.
Anonymous User - July 25, 2002 6:55 pm:
 If I create a DTML document and put in the code from the above example (objectList), this DTML document will
 not display anything. There is a difference between the DTML document and DTML method. What is it?

DTML Methods mainly serve as presentation templates. DTML Methods can act as templates tying reusable bits of content together into dynamic web pages. The template features of DTML Methods will be discussed in further detail in the next chapter.

Comparing DTML Documents and Methods

DTML Methods have the same user interface as DTML Documents, which can be a bit confusing to the beginner. All of the procedures that you learned in the last chapter for adding, editing, viewing and uploading DTML Documents are identical for DTML Methods.

A source of frequent confusion for Zope beginners is the question of when to use a DTML Document versus when to use a DTML Method. On the surface, these two options seem identical. They both hold DTML and other content, they both execute DTML code, and they both have a similar user interface and a similar API, so what's the difference?

DTML Documents are meant to hold document-like content. For example, the various chapters of a book could be held in a DTML Document. A general rule is: if your content is mostly document-like and you want to present it on your site, then it should go into a DTML Document.

hansa - Sep. 20, 2002 6:23 pm:
 ... the various chapters of a book could be held in corresponding DTML Documents.

DTML Methods are meant to manipulate and display other objects. DTML Methods don't usually hold a lot of content, unless the content is meant to change or manipulate other content.

Don't worry if you're still unclear on the differences between DTML Document and Methods. Even the most experienced Zope programmers need to think a little before deciding which type of object to use. In Chapter 8, "Variables and Advanced DTML", you'll learn about the technical differences between DTML Documents and DTML Methods (they look up variables differently since they have different "client" objects). Here are some general rules to help you decide between DTML Documents and Methods:

  • If it's content, use a DTML Document, or a File if it doesn't require any DTML scripting.
  • If it's simple logic, use a DTML Method.
  • If it's meant to be presented by other objects, use a DTML Document.
  • If it's meant to present other objects, use a DTML Method.
  • If it's complex behavior, use a Python or Perl-based script.

As you've seen DTML Methods are a useful tool for presentation and quick scripting, but eventually you're going to want to power of a fully expressive programming language, and that's where Scripts come in.

twalter - Apr. 20, 2002 7:59 pm:
As a beginner, I needed more information here so that later I would make index_html a DTML Method rather than
 a Document. From an earlier comment, it sounds like the differences are in a later chapter. Just add a
sentence that says, to get the folder objects, you need to use a DTML Method rather than a DTML Document.
Specifically,
 I was tripped in the "Creating Basic Zope Applications" chapter, creating the navigation Method. It did not
 easily occur to me that it might be due to this differentiation.
Anonymous User - June 5, 2002 4:31 pm:
I'm still waiting for the "Why are they different." definition. This book would be much more usefull if there
 were some explaination of WHY things are rather than "cause i said so" descriptions offered so far.
Anonymous User - Aug. 31, 2002 3:45 am:
 One additional basic and obvious difference that has not been mentioned here: DTML documents have a property
 sheet; DTML methods do not.
A DTML document is intended to be a fairly complete and autonomous object, whereas a DTML method is primarily
 intended to be referenced from other objects, providing a means for other objects to use some functionality
 provided by the method.
 -
 To put it in a slightly more advanced way, most of the DTML variables available to a DTML document refer to
that document or its properties, whereas the same variables in a DTML method more often refer to the document
 which is using the method at the time, not the method itself.
 -
 Note that at the most basic level DTML documents and methods behave in an identical manner -- it's only when
 you start doing tricks with DTML markup that the differences become apparent. So which to use? If all you're
 doing is dishing up static HTML (with or without standard_html_header type substitutions), it really doesn't
 matter -- indeed, you would do well to consider using a Page Template instead, or even a File if the content
is completely static. In other cases the differences described above should guide you: use DTML documents for
 things which have properties, and DTML methods for things which form a component of something else.
hansa - Sep. 20, 2002 6:31 pm:
 Again:this is still an Introductory chapter, readers growing impatient.
 Remedy 1: tell at the start of this chapter, that its only a grand tour throgh zope without going into
 details.
 Remedy 2: repeat tell again: still intro and give href forward refs.

Using Sessions

Sessions allow you keep track of site visitors. Web browsers use a protocol named HTTP to exchange data with a server such as Zope. HTTP is does not provide a way for the server to keep track of a user's requests; each request is considered completely independent.

Anonymous User - Apr. 27, 2002 5:54 pm:
 You may want to change "HTTP is does" with "HTTP does"
aathan - Jan. 24, 2003 4:05 pm:
 Caveat Emptor.  Zope 2.6.0 and 2.6.1b1 releases have serious session tracking bugs.

Sessions overcome this limitation of HTTP. The term "session" means a series of related HTTP requests that come from the same client during a given time period. Zope's sessioning system makes use of cookies and/or HTTP form elements "in the background" to keep track of user sessions. Zope's sessioning system allows you to avoid manually managing user sessions.

Anonymous User - June 6, 2002 8:20 am:
 What will we do if cookies aren't allowed?
mcdonc - June 6, 2002 8:44 am:
 You can use query strings as well as cookie values to keep a session alive.
Anonymous User - June 13, 2002 9:31 pm:
 I'm curious whether there is a performance penalty for using sessions in Zope relative to using cookies in
 other kinds of CGI scripts.
mcdonc - June 14, 2002 12:48 am:
 Yes... sessions use resources that cookies dont.  But they also do more.
Anonymous User - June 30, 2002 1:21 pm:
 And you can still use cookies as well, I presume?
Anonymous User - June 30, 2002 1:51 pm:
 Sure. Sessions and cookies are completely independent. Sessions can *use* cookies but they don't replace
 them.
Anonymous User - July 26, 2002 11:46 am:
 A link to some resources concerning Session/web farms/failover/etc. would be nice. As a Note or something.

You can use sessions to keep track of anonymous users as well as those who have Zope login accounts.

Data associated with a session is called "session data". Session data is valid only for the duration of one site visit as determined by a configurable inactivity timeout value. Session data is used to keep track of information about a user's visit such as the items that a user has put into a "shopping cart", or which pages a user has seen on his trip to your site.

It is important to realize that keeping sensitive data in a session data object is potentially insecure unless the connection between browsers and Zope is encrypted in some way. Don't store sensitive information such as phone numbers, addresses, account numbers, credit card numbers or any other personal information about your site visitors unless you've secured the connection between Zope and site visitors via SSL.

Anonymous User - Sep. 24, 2002 8:49 am:
 So the actual session data is stored on the client side (in a cookie or form variables)? Wouldn't it be
 better (more secure and less traffic) if the session data was instead stored on the server, where the client
 kept/transmitted only the session id?
Anonymous User - Sep. 24, 2002 9:11 am:
 No. The session data is stored on the server. It is referred to only by a cookie on the client. The security
 risk revolves around the fact that if an interceptor gets the cookie value, they have access to the data on
 the server.
Anonymous User - Sep. 24, 2002 9:23 am:
Well then it doesn't seem that the interceptor would necessarily have *access* to the data (in the sense that
 he could see, for example, the credit card number). But he could pose as the user, which would allow him to
 *use* the credit card number.
Anonymous User - Sep. 24, 2002 9:37 am:
 Yes, the user could use the credit card number. He might not be able to see the credit card number if you're
 absolutely sure that the user can never see a representation of the session data. But if the interceptor
 found another hole in the system, he might be able to see the credit card number.
Anonymous User - Nov. 28, 2002 8:35 pm:
 "It is important to realize that keeping sensitive data in a session data object is potentially insecure
 unless the connection between browsers and Zope is encrypted in some way."
 How ironic, when passwords are transmitted effectively in the clear. Even the CookieCrumbler product stores
 the base64(username:password) in the cookie.

Session Configuration

Zope versions after 2.5 come with a default sessioning environment configured "out of the box", so there's no need to change these objects unless you're curious or want to change how sessions are configured. For information on changing sessioning configuration, use the Zope help system.

Zope uses several different types of objects to manage session data, and brief explanations of their purpose follow.

Browser ID Manager
This object manages how visitors' browsers are identified from request-to-request, and allows you to configure whether this happens via cookies or form variables, or via a combination of both. The default sessioning configuration provides a Browser Id Manager as the /browser_id_manager object.
Transient Object Container
This object holds session data. It allows you to set how long session data lasts before it expires. The default sessioning configuration provides a Transient Object Container named /temp_folder/session_data. The session data objects in the default session_data Transient Object container are lost each time Zope is restarted.
Session Data Manager
This object connects the browser id and session data information. When a folder which contains a session data manager is traversed, the REQUEST object is populated with the SESSION, which is a session data object. The default sessioning configuration provides a Session Data Manager named /session_data_manager.

Using Session Data

You will typically access session data through the SESSION attribute of the REQUEST object.

Here's an example of how to work with a session using a Python-based Script:


## Script (Python) "lastView"
secs_per_day=24*60*60
session=context.REQUEST.SESSION
if session.has_key('last view'):
    # The script has been viewed before, since the 'last view'
    # has been previously set in the session.
    then=session['last view']
    now=context.ZopeTime()
    session['last view']=now # reset last view to now
    return 'Seconds since last view %.2f' % ((now - then) * secs_per_day)
# The script hasn't been viewed before, since there's no 'last
# view' in the session data. 
session['last view']=context.ZopeTime()
return 'This is your first view'
Anonymous User - Aug. 20, 2002 8:43 am:
 As far as I remember, "context" as in context.REQUEST.SESSION has not yet been discussed.

 For the sake of understanding a sentence on "context" might be in order.

 SL
Anonymous User - Aug. 27, 2002 7:16 am:
 Is it also possible to use container.REQUEST.SESSION in order to connect to the Session-Scope?! And what is
 the exact difference between 'context' and 'container'?
Anonymous User - Aug. 29, 2002 11:00 am:
 Context
This is the object on which the script is being called, also known as the "acquisition parent" of the script.
 This may be the container, but varies according to the path through which the script is accessed.
  Container
 This is the Folder "Auto Lunch Order", in which this script is located. This doesn't change unless you move
 the script. If the script is in a ZClass, the Container is the class instance.
Remember how we used a DTML method from root in a subfolder? Root would be the container, while the subfolder
 is the context.
Anonymous User - Dec. 6, 2002 1:51 pm:
 Something need to be "imported from".
 What ?
 Error Type: NameError
 Error Value: global name 'SessionIdManagerErr' is not defined

View this script, and then reload it a couple of times. It keeps track of when you last viewed the script and calculates how long it has been since you last viewed it. Notice that if you quit your browser and come back to the script it forgets you. However, if you simply visit some other pages and then return, it still remembers the last time you viewed it.

Anonymous User - Aug. 3, 2002 3:55 pm:
 Maybe "View this script" should read cut and paste this text into a new script that you've added to your
 folder. Click "Save Changes" button and then click on the "Test" tab. My 2c --RAW--

This example shows the basic features of working with session data: session data objects act like Python dictionaries. You will almost always use session data that consists of normal Python lists, dictionaries, strings, and numbers. The only tricky thing about sessions is that when working with mutable session data (for example dictionaries or lists) you need to save the session data by reassigning it. Here's an example:


## Script (Python) "sessionExample"
session=context.REQUEST.SESSION
# l is a list
l=session['myList']
l.append('spam')
# If you quit here, your changes to the list won't
# be saved. You need to save the session data by 
# reassigning it to the session.
session['myList']=l
Anonymous User - July 28, 2002 2:12 pm:
 Beginner's question:
 How do we use this script? 
 If I try to use it by itself I get:
 Error Type: KeyError
 Error Value: myList
Anonymous User - July 28, 2002 2:31 pm:
 You can't use it standalone. It is just meant as an example to show that if you modify a mutable object from
 a session, you need to store it again.

For more information about persistence and mutable data, see the Zope Developer's Guide.

Anonymous User - June 5, 2002 4:40 pm:
 A link or reference where to find this information would be nice.
Anonymous User - Sep. 21, 2002 5:24 pm:
 At http://www.zope.org/Documentation youl find Zope Developers Guide as
 http://www.zope.org/Documentation/Books/ZDG/current/index_html

You can use sessions in Page Templates and DTML Documents, too. For example, here's a template snippet that displays the users favorite color (as stored in a session):


<p tal:content="request/SESSION/favorite_color">Blue</p>
Anonymous User - Sep. 21, 2002 5:37 pm:
 You can use sessions wherever you have something executable with access to the REQUEST object, that is
 everything called through the web, even code of products you write yourself.
 Rather than 1000 examples give me 1 rule.
Anonymous User - Sep. 25, 2002 3:14 pm:
 Give me one rule, but don't forget the examples!

Here's how to do the same thing in DTML:


<dtml-with SESSION mapping>
  <p><dtml-var favorite_color></p>
</dtml-with>

Sessions have a plethora of additional configuration parameters and usage patterns. For further information about the session application programming interface, see the Zope help system. For an additional example of using sessions, see the "shopping cart" example that comes with Zope 2.5 and above (in the Examples folder).

Anonymous User - Aug. 19, 2002 2:21 pm:
 How can I reference the container of a session object (i.e., I presume, the sessionDataManager object) from
 within a python script? And from a DTML method?
mcdonc - Aug. 19, 2002 2:22 pm:
 See http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Sessions.stx for more info about sessions.

Using Versions

Version objects help coordinate the work of many people on the same set of objects. While you are editing a document, someone else can be editing another document at the same time. In a large Zope site hundreds or even thousands of people can be using Zope simultaneously. For the most part this works well, but problems can occur. For example, two people might edit the same document at the same time. When the first person finishes their changes they are saved in Zope. When the second person finishes their changes they over write the first person's changes. You can always work around this problem using Undo and History, but it can still be a problem. To solve this problem, Zope has Version objects.

Anonymous User - Sep. 21, 2002 5:47 pm:
 Why not make a copy, work on the copy and finally replace the original?
Anonymous User - Sep. 25, 2002 3:18 pm:
 It would be more tedious, and it wouldn't change the problem: the second person would also overwrite the
 first person's work.

Another problem that you may encounter is that you may wish to make some changes, but you may not want to make them public until you are done. For example, suppose you want to change the menu structure of your site. You don't want to work on these changes while folks are using your site because it may break the navigation system temporarily while you're working.

Anonymous User - June 24, 2002 2:38 pm:
 When I work in the Version and Zope uses Sessions I reisive error - the Version tries to trace changes in
 temp_folder (but temp_folder incompatible with Version).
 How to me to exclude the temp_folder from Version?
Anonymous User - June 25, 2002 1:22 am:
 <Zope_Install_dir>/lib/python/Products/TemporaryFolder/TemporaryStorage.py
 Find method "store" and replace

 if version:
     raise POSException.Unsupported, (
     "TemporaryStorage is incompatible with versions"
     )
 with
  if version: return 0
 #    raise POSException.Unsupported, (
 #    "TemporaryStorage is incompatible with versions"
 #    )

 Restart Zope.
Anonymous User - July 1, 2002 7:08 pm:
 What version of Python are you using?  Upgrading from 2.1.1 to 2.2.1 did the trick for me it seems...
Anonymous User - July 1, 2002 7:28 pm:
 Upgrading Python won't help.  This restriction is removed in Zope 2.6.

Versions are a way of making private changes in Zope. You can make changes to many different documents without other people seeing them. When you decide that you are done you can choose to make your changes public, or discard them. You can work in a Version for as long as you wish. For example it may take you a week to put the finishing touches on your new menu system. Once you're done you can make all your changes live at once by committing the version.

Create a Version by choosing Version from the product add list. You should be taken to an add form. Give your Version an id of MyChanges and click the Add button. Now you have created a version, but you are not yet using it. To use your version click on it. You should be taken to the Join/Leave view of your version as shown in [3-8].

Joining a Version

Figure 3-8 Joining a Version

The Version is telling you that you are not currently using it. Click on the Start Working in MyChanges button. Now Zope should tell you that you are working in a version. Now return to the root folder. Notice that everywhere you go you see a small message at the top of the screen that says You are currently working in version /MyChanges. This message lets you know that any changes you make at this point will not be public, but will be stored in your version. For example, create a new DTML Document named new. Notice how it has a small red diamond after its id. Now edit your standard_html_header method. Add a line to it like so:


<HTML>
  <HEAD>
    <TITLE><dtml-var title_or_id></TITLE>
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">
  <H1>Changed in a Version</H1>
Anonymous User - June 5, 2002 5:02 pm:
 Cookie acceptance of - Zope-Version="MyChanges" - is REQUIRED when you click on the "Start working in
 MyChanges" and "Quit working in ..."

Any object that you create or edit while working in a version will be marked with a red diamond. Now return to your version and click the Quit working in MyChanges button. Now try to return to the new document. Notice that the document you created while in your version has now disappeared. Any other changes that you made in the version are also gone. Notice how your standard_html_header method now has a small red diamond and a lock symbol after it. This indicates that this object has been changed in a version. Changing an object in a version locks it, so no one else can change it until you commit or discard the changes you made in your version. Locking ensures that your version changes don't overwrite changes that other people make while you're working in a version. So for example if you want to make sure that only you are working on an object at a given time you can change it in a version. In addition to protecting you from unexpected changes, locking also makes things inconvenient if you want to edit something that is locked by someone else. It's a good idea to limit your use of versions to avoid locking other people out of making changes to objects.

Now return to your version by clicking on it and then clicking the Start working in MyChanges button. Notice how everything returns to the way it was when you left the Version. At this point let's make your changes permanent. Go to the Save/Discard view as shown in [3-9].

Committing Version changes.

Figure 3-9 Committing Version changes.

Enter a comment like This is a test into the comment field and click the Save button. Your changes are now public, and all objects that you changed in your Version are now unlocked. Notice that you are still working in your Version. Go to the Join/Leave view and click the Quit Working in MyChanges button. Now verify that the document you created in your version is visible. Your change to the standard_html_header should also be visible. Like anything else in Zope you can choose to undo these changes if you want. Go to the Undo view. Notice that instead of many transactions one for each change, you only have one transaction for all the changes you made in your version. If you undo the transaction, all the changes you made in the version will be undone.

Versions are a powerful tool for group collaboration. You don't have to run a live server and a test server since versions let you make experiments, evaluate them and then make them public when you decide that all is well. You are not limited to working in a version alone. Many people can work in the same version. This way you can collaborate on version's changes together, while keeping the changes hidden from the general public.

Anonymous User - Sep. 16, 2002 3:37 am:
I encountered a problem using versions such that there was some kind of deadlock: I could not save or discard
 changes in a version, because ZOPE told me that there was a lock from somewhere else. I was not able to find
 out how to cope with that problem. Perhaps it would be useful to add some paragraph to the book how the
 handling of exceptional situations should be handled, and what means ZOPE provides to find out the source of
 such an exception.

Versions and ZCatalog

Versions don't work well with ZCatalog. This is because versions lock objects when they are modified in a version, preventing changes outside the version. This works well when changes are isolated.

Anonymous User - May 14, 2002 6:55 pm:
 Zcatalog has not been introduced to us newbies yet, nor does it say where to find out more about Zcatalog.

ZCatalog has a way of connecting changes made to disparate objects. This is because cataloging an object must, by necessity change the catalog. Objects that automatically catalog themselves when they are changed propigate their changes to the catalog. If such an object is changed in a version, then the catalog is changed in the version too, thus locking the catalog. This property makes the catalog and versions get along poorly. As a rule, versions should not be used in applications that use the catalog.

Anonymous User - May 29, 2002 12:08 pm:
 `propagate'
Anonymous User - Sep. 21, 2002 5:56 pm:
 Again: what is the advantage of using Version against working on a copy and finally overwriting original?
Anonymous User - Sep. 25, 2002 3:26 pm:
 While this could work if you were editing some of the content of your site, just think of how it would work
if you were indeed working on the menu of the site. You could work on something called menu_copy or new_menu,
 but then, how to test it? All the pages in your site still use the original menu, so you can't really test
 your menu.
 Using versions allows you to test new code and templates and to see how they affect the whole site. You (and
 the person that work with you on that version) are the only ones that see the new site, while your users
 still enjoy the old one.

Improving Performance with Caching

A cache is a temporary place to store information that you access frequently. The reason for using a cache is speed. Any kind of dynamic content, like a DTML page or a Python Script, must be evaluated each time it is called. For simple pages or quick scripts, this is usually not a problem. For very complex DTML pages or scripts that do a lot of computation or call remote servers, accessing that page or script could take more than a trivial amount of time. Both DTML and Python can get this complex, especially if you use lots of looping (such as the in tag or the Python for loop) or if you call lots of scripts, that in turn call lots of scripts, and so on. Computations that take a lot of time are said to be expensive.

Anonymous User - May 27, 2002 7:18 pm:
 I think the topic of caching should be introduced at a later 
 chapter. A user new to Zope has other problems than caching 
 when he reads this chapter.
Anonymous User - June 5, 2002 5:16 pm:
 also... is this server-side caching or client caching?
Anonymous User - Sep. 21, 2002 6:07 pm:
 what is a "trivial amount of time" ?
 /trivial/tolerable/
Anonymous User - Sep. 25, 2002 3:29 pm:
 The author is talking about server-side caching.

A cache can add a lot of speed to your site by calling an expensive page or script once and storing the result of that call so that it can be reused. The very first person to call that page will get the usual slow response time, but then once the value of the computation is stored in the cache, all subsequent users to call that page will see a very quick response time because they are getting the cached copy of the result and not actually going through the same expensive computation the first user went through.

Anonymous User - June 5, 2002 5:18 pm:
 ahh, Server-side.

To give you an idea of how caches can improve your site speed, imagine that you are creating www.zopezoo.org, and that the very first page of your site is very complex. Let's suppose this page has complex headers, footers, queries several different database tables, and calls several special scripts that parse the results of the database queries in complex ways. Every time a user comes to www.zopezoo.org, Zope must render this very complex page. For the purposes of demonstration, let's suppose this complex page takes one-half of a second, or 500 milliseconds, to compute.

Anonymous User - Aug. 5, 2002 1:12 pm:
 www.zopezoo.org is currently Under Construction. Please check back soon...  > from the site< --RAW--

Given that it takes a half of a second to render this fictional complex main page, your machine can only really serve 120 hits per minute. In reality, this number would probably be even lower than that, because Zope has to do other things in addition to just serving up this main page. Now, imagine that you set this page up to be cached. Since none of the expensive computation needs to be done to show the cached copy of the page, many more users could see the main page. If it takes, for example, 10 milliseconds to show a cached page, then this page is being served

50 times faster

to your web site visitors. The actual performance of the cache and Zope depends a lot on your computer and your application, but this example gives you an idea of how caching can speed up your web site quite a bit. There are some disadvantages to caching however:

Cache lifetime
If pages are cached for a long time, they may not reflect the most current information on your site. If you have information that changes very quickly, caching may hide the new information from your users because the cached copy contains the old information. How long a result remains cached is called the cache lifetime of the information.

Personal information
Many web pages may be personalized for one particular user. Obviously, caching this information and showing it to another user would be bad due to privacy concerns, and because the other user would not be getting information about them, they'd be getting it about someone else. For this reason, caching is often never used for personalized information.

Zope allows you to get around these problems by setting up a cache policy. The cache policy allows you to control how content gets cached. Cache policies are controlled by Cache Manager objects.

Adding a Cache Manager

Cache managers can be added just like any other Zope object. Currently Zope comes with two kinds of cache managers:

HTTP Accelerated Cache Manager
An HTTP Accelerated Cache Manager allows you to control an HTTP cache server that is external to Zope, for example, Squid. HTTP Accelerated Cache Managers do not do the caching themselves, but rather set special HTTP headers that tell an external cache server what to cache. Setting up an external caching server like Squid is beyond the scope of this book, see the Squid site for more details.

(RAM) Cache Manager
A RAM Cache Manager is a Zope cache manager that caches the content of objects in your computer memory. This makes it very fast, but also causes Zope to consume more of your computer's memory. A RAM Cache Manager does not require any external resources like a Squid server, to work.

For the purposes of this example, create a RAM Cache Manager in the root folder called CacheManager. This is going to be the cache manager object for your whole site.

Anonymous User - July 3, 2002 12:21 pm:
 Is it possible to specify part of my size to be cached, instead of the whole site?
Anonymous User - July 3, 2002 1:01 pm:
 The explanation should say "This is going to be the cache manager for your whole site *in the following
 examples*." A cache manager can be associated with any number of Zope objects, and it doesn't necessarily
 need to be associated with any of them.

Now, you can click on

CacheManager

and see its configuration screen. There are a number of elements on this screen:

Title
The title of the cache manager. This is optional.

REQUEST variables
This information is used to store the cached copy of a page. This is an advanced feature, for now, you can leave this set to just "AUTHENTICATED_USER".

Threshold Entries
The number of objects the cache manager will cache at one time.

Cleanup Interval
The lifetime of cached results.

For now, leave all of these entries as is, they are good, reasonable defaults. That's all there is to setting up a cache manager!

Anonymous User - Sep. 12, 2002 11:38 am:
 A description should be given of how the REQUEST variables
 are used as keys (eg. how to use form data/query strings
 as part of the key).  

 /path/to/url?month=Jan should not hit /pth/to/url?month=Feb in the cache.
Anonymous User - Sep. 12, 2002 11:48 am:
 Normally query string parameters can be placed directly into the 
 "REQUEST variables" area.  For example, with the following request:
 http://www.zope.org/stuff?month=Jan&day=23
 if the "REQUEST variables" area has a single line "month" (instead of
 the default "AUTHENTICATED_USER"), then
 a single "Path" will show up in the Statistics page; however, there
 will be a different entry accounted for in the "Entries" column
 of the statistics page: one for each distinct month value that
 has been cached.  No distinction will be made upon the "day" query
 string (unless an additional line is given for "day" in the "REQUEST
 variables" area).

 Note that if a Zope directory houses an "index_html" file, and the
 URL does not explicity give the "index_html" (i.e. http://www.zope.org/path?month=xxx instead of
 http://www.zope.org/index_html?month=xxx), then
 the query string will not be able to serve as a key for the cache manager.
 Therefore, if you want to cache index_html, keying on query strings, then
 you must give fully qualified paths to the .../index_html object rather
 than assuming index_html as the default.

There are a couple more views on a cache manager that you may find useful. The first is the Statistics view. This view shows you the number of cache "hits" and "misses" to tell you how effective your caching is.

There is also an Associate view that allows you to associate a specific type or types of Zope objects with a particular cache manager. For example, you may only want your cache manager to cache DTML Documents. You can change these settings on the Associate view.

At this point, nothing is cached yet, you have just created a cache manager. The next section explains how you can cache the contents of actual documents.

Caching a Document

Caching a document is very easy. First, before you can cache a document you must have a cache manager like the one you created in the previous section.

To cache a document, create a new DTML Document object in the root folder called Weather. This object will contain some weather information. For example, let's say it contains:


<dtml-var standard_html_header>

  <p>Yesterday it rained.</p>

<dtml-var standard_html_footer>

Now, click on the Weather DTML Document and click on its Cache view. This view lets you associate this document with a cache manager. If you pull down the select box at the top of the view, you'll see the cache manager you created in the previous section, CacheManager. Select this as the cache manager for Weather.

Now, whenever anyone visits the Weather document, they will get the cached copy instead. For a document as trivial as our Weather example, this is not much of a benefit. But imagine for a moment that Weather contained some database queries. For example:


<dtml-var standard_html_header>

  <p>Yesterday's weather was <dtml-var yesterdayQuery> </p>

  <p>The current temperature is <dtml-var currentTempQuery></p>

<dtml-var standard_html_footer>

Let's suppose that yesterdayQuery and currentTempQuery are SQL Methods that query a database for yesterdays forecast and the current temperature, respectively (for more information on SQL Methods, see Chapter 12, "Relational Database Connectivity"). Let's also suppose that the information in the database only changes once every hour.

Now, without caching, the Weather document would query the database every time it was viewed. If the Weather document was viewed hundreds of times in an hour, then all of those hundreds of queries would always contain the same information.

If you specify that the document should be cached, however, then the document will only make the query when the cache expires. The default cache time is 300 seconds (5 minutes), so setting this document up to be cached will save you 91% of your database queries by doing them only one twelfth as often. There is a trade-off with this method, there is a chance that the data may be five minutes out of date, but this is usually an acceptable compromise.

For more information about caching and using the more advanced options of caching, see the Zope Administrator's Guide.

Virtual Hosting Objects

Zope comes with three objects that help you do virtual hosting, SiteRoot, Set Access Rule, and Virtual Host Monster. Virtual hosting is a way to serve many web sites with one Zope server. Virtual hosting is an advanced administration function, that is beyond the scope of this book. See the Zope Administrator's Guide for more information on virtual hosting.

Anonymous User - July 14, 2002 3:54 pm:
 I wouldn't say that all virtual hosting is outside the scope of this book and leave it at that... I spend a
long time trying to figure out how to install Zope and leave all the default stuff up to learn on while still
making an active site on port 80(or whatever port). Also how to set up the site on port 80 and the management
stuff on another port for firewall reasons (firewalls are like condoms - you should recommend them as part of
 zope setup and show a bit of howto or simple configuration suggestions). This should either be standard a
 install option or in the first couple of chapters of this document since I think it would be pretty standard
 stuff. It should be in the 'using Zope' section, and most of that section should be in an 'Installing Zope'
 section.
Anonymous User - Dec. 5, 2002 2:47 pm:
 There is a section on virtual hosting in the 2.6 Zope Book
 (http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition)

Sending mail with MailHost

Zope comes with an object that is used to send outbound e-mail, usually in conjunction with the DTML sendmail tag, described more in Chapter 8, "Variables and Advanced DTML".

Anonymous User - June 5, 2002 5:36 pm:
 add link please?
Anonymous User - July 8, 2002 11:25 am:
 It's chapter 9, actually!  The link is:

 http://www.zope.org/Documentation/ZopeBook/AdvDTML.stx#2-77

Mailhosts can be used from either Python or DTML to send an email message over the Internet. They are useful as gateways out to the world. Each mailhost object is associated with one mail server, for example, you can associate a mailhost object with yourmail.yourdomain.com, which would be your outbound SMTP mail server. Once you associate a server with a mailhost object, the mailhost object will always use that server to send mail.

To create a mailhost object select MailHost from the add list. You can see that the default id is "MailHost" and the default SMTP server and port are "localhost" and "25". make sure that either your localhost machine is running a mail server, or change "localhost" to be the name of your outgoing SMTP server.

Now you can use the new MailHost object from a DTML sendmail tag. This is explained in more detail in Chapter 8, "Variables and Advanced DTML". The API for MailHost objects also allows you to send mail from Python scripts. For more information, see the online help system.

Anonymous User - June 3, 2002 3:18 pm:
To be complete, I think you should show a simple example here. If not, don't have the reader set the MailHost
 now unless he's going to get to use it right away. It leaves the reader with an unsatisfied thirst.
Anonymous User - June 13, 2002 7:04 am:
 I have the same feeling!
Anonymous User - June 22, 2002 9:39 am:
 But I have beer!
Anonymous User - Aug. 28, 2002 12:30 am:
 Catch regarding MailHost:

 Seems (in Linux, at least) that MailHost forcefully requires entries in the /etc/hosts file having the ip
 address and hostname of the machine where it runs. Somehow there seems to be a dependency on /etc/hosts
 nevertheless there is a DNS service running that can resolve the MailHost's host name/address. Can someone
 elaborate on this issue? Is there a way of just having DNS (not /etc/hosts) for MailHost to function
 correctly?

Previous Page Up one Level Next Page Using Basic Zope Objects Comments On/Off Table of Contents