ZopeMag's mascot the ZOPE fish


Article Finder
People
Issue 1 - Revision 5  /   June 14, 2002 


 
  ZopeMag Links:
Home Page
About the Fish
Issue 09
Issue 08
Issue 07
Issue 06
Issue 05
Issue 04
Issue 03
Issue 02
Issue 01
Latest Issue

 
 
Downloads
     
  Letter from the Editor:
   Welcome

Interviews:
In our first issue we interview the father of the Wiki and the inventor of Extreme Programming.

 Ward Cunningham

Tutorials:
Throughout the quarter we cover topics of interest to Zope developers, designers, and users.

  MetaFlow
  Databases and ZPTs
  Custom User Folders
  Zope and CSS
  Intranets

Product Review:
Every two weeks we review a new Zope Product

  Z Shrink
  External File
  DocumentLibrary
  ZWiki


 
 
Downloads
     
  Downloads:
Products we talk about in this issues Articles and Reviews

  ZShrink
  Zope Page Templates
  LocalFS
  SimpleZPTmyAdmin
  Extended User Folder
  MetaFlow
 
     

Illustration by Brendan Davis
tutorial
Creating a Database User Interface with Zope Page Templates.

Databases and Zope Page Templates
Creating a Database User Interface with Zope Page Templates
- - - - - - - - - - - -

By Kristoph Kirchner | March 28, 2002



The Idea

A couple of weeks ago I had to take over as the webmaster of a homepage which was using a mySQL database to manage news, a forum, a chat, a guestbook and some other things. I administrated this database using phpMyAdmin. It was the first time I had worked with phpMyAdmin and I was fascinated by it. For those of you who do not know phpMyAdmin, it is an easy to use interface which not only provides access to the data within the database tables so that you can add, edit or delete entries, but it also lets you redefine the table rows, add new ones or delete existing ones, add new tables easily, make dump files of your database and much more. You do all this by using the forms of phpMyAdmin, and you can also use a textarea to execute SQL statements.

When I was asked to write an article about using ZPTs with databases, I immediately thought of phpMyAdmin and decided to adapt it so it could be used with Zope and (if possible) with all databases for which there is an adapter for Zope. In my case, I started out using Microsoft Access for a database because I found it fairly easy to use and I already had it installed on my machine.

Since phpMyAdmin is a powerful tool, I’ve decided, for the sake of this article, to make a simple Zope version. I’m going to continue to try to improve it such that it is as good as the original phpMyAdmin. In the coming months I will write more about my experience doing that.

Giving the Pages an Identical Face


Since I did not want to repeatedly write the same code and I wanted to have all pages look alike, I used a Zope Page Template in which the header and body where defined. To use this predefined code for all pages, it had to be a macro. ZPT macros are defined using METAL, the Macro Expansion for the Template Attribute Language (TAL). As with TAL, METAL attributes are defined in normal HTML-tags:

ZPT standard_template.pt

<html metal:define-macro="main_page">
...
</html>

I defined the main macro in the ZPT standard_template.pt. Thereafter, I called this macro in each of the templates which make up the SimpleZPTmyAdmin site:

e.g. ZPT tab_properties.html

<html metal:use-macro="here/standard_template.pt/macros/main_page">
...
</html>

As this code overwrites everything on a page (thus all pages using this macro would look exactly the same), I had to define slots in the macro where different content could be placed on each page. Slots are defined within a macro, i.e. between the start-tag and the end-tag of a macro, as follows:

<html metal:define-macro="main_page">
...
<body bgcolor="#F5F5F5" text="#000000" background="images/bkg.gif">
<div metal:define-slot="main_content">
...
</div>
</body>
</html>


Now I had a space within the body of a page to fill with different forms and tables to show, for example, a database table’s properties or its content or whatever else I wanted to show. But to be able to use that, I had to say in each page specifically that I wanted to make use of the slot: <html metal:use-macro="here/standard_template.pt/macros/main_page">
...
<"body bgcolor="#F5F5F5" text="#000000" background="images/bkg.gif">
<div metal:define-slot="main_content">
...
</div>
</body>
</html>


Next, I was ready to create the pages that would make it possible to see, create, edit and delete databases, their tables and contents.

.  1  2  3
Next page  |  Getting Database Information



shim
shim  ZopeMag is committed to bringing you the best in Zope Documentation. shim
shim


Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT