[Zope] Question about ZClass Tabs/Views (How do you make a custom edit_properties screen?)

Ronald L. Chichester complaw@hal-pc.org
Tue, 11 Sep 2001 21:47:49 -0500


This is a multi-part message in MIME format.
--------------A21D2190D68C8BC003CE0695
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have a ZClass (derived from Folder).  I want to be able to edit the
properties in the ZClass, to wit, I have created an index_html file, a
manage_editDoctrineFolderForm, and a manage_addDoctrineFolderForm that
are stored in the ./doctrineFolder subdirectory.  All of the
above-identified files, as well as the ZClass file itself, are
attached.  I have a purplexing problem.  Every time I add the ZClass,
the proper add form appears and I am able to add the ZClass Folder
derivative to the current folder.  However, My "Edit" view table does
not appear.  Moreover, when I click on the Properties tab, only the
Title property is shown, and not the other two properties of the object,
i.e., a default manage_properties is being used, not the one I
designated.  

I'm also having trouble getting Zope to recoginize my manage_editForm
rather than the default forms.  I suspect it is inheriting something,
but it won't let me override those settings.  

Another problem is that Zope won't seem to For example, in the attached
code, there is an index_html file that is to be invoked when you press
the "View" tab in the manage mode.  However, doing so presents an error
message saying that the variable "status" isn't there.  Well, I
corrected that error, but it still shows up.  (Incidentally, no errors
were present when I restarted Zope).

This problem is driving me nuts!  I'm about to junk Zope altogether
because you can't make a proper ZClass work without wiping out zope
entirely, reinstalling the thing from scratch, and then installing the
corrected class (it seems to be the only way to get Zope to forget the
previous mistake).  Zope has a memory like an elephant -- but only for
your mistakes, not for what you want!.  Surely there is a way to make
changes in a ZClass show up in Zope.  Surely there is a way to get the
ZClass to have a decent edit screen other than the default?

Diter, I implore you to write a section in your book with examples of
products that have custom edit screens/properties/methods but in a way
that you don't need a Computer Science degree to understand.  Something
along the lines of the Minimal product (great idea, but the code didn't
always work, and he finished the Sequel before he got to custom
Views/property sheets).

The files are attached.  I would appreciate (greatly) any help someone
could offer.

Best wishes,

Ron
--------------A21D2190D68C8BC003CE0695
Content-Type: text/plain; charset=us-ascii;
 name="DoctrineFolder.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DoctrineFolder.py"

##############################################################################
# Legal Doctrine Folder Class, part of the Legal Doctrine Product for Zope
#
# Copyright (C) 2001 Ronald L. Chichester, Esq.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

__doc__ = """Legal Doctrine Folder Object"""
__version__ = '0.2.4'

from OFS.Folder import Folder
import Products
import Globals
from Globals import PersistentMapping, HTMLFile, HTML, DTMLFile

manage_addDoctrineFolderForm  = DTMLFile('doctrineFolder/manage_addDoctrineFolderForm',  globals())
manage_editDoctrineFolderForm = DTMLFile('doctrineFolder/manage_editDoctrineFolderForm', globals())
manage_properties             = DTMLFile('doctrineFolder/manage_editDoctrineFolderForm', globals())


class DoctrineFolder(Folder):

     "Legal Doctrine Folder Object"

     meta_type = 'Legal Doctrine Folder'

     mange_options = (
          {'label': 'Contents',   'action': 'manage_main'},
          {'label': 'View',       'action': 'index_html'},
          {'label': 'Edit',       'action': 'manage_editDoctrineFolderForm'},
          {'label': 'Properties', 'action': 'manage_properties'},
          {'label': 'Security',   'action': 'manage_access'},
          {'label': 'Undo',       'action': 'manage_UndoForm'}
     )

     def __init__(self, id, title, topic, maintainer):
          "Initialize a new instance of the Legal Doctrine object"
          self.id         = id
          self.title      = title
          self.topic      = topic
          self.maintainer = maintainer

     # The following is used to display the object's contents...
     index_html = DTMLFile('doctrineFolder/index_html', globals())

     def manage_editDoctrineFolderAction(self, title, topic, maintainer, RESPONSE=None):
          """Change the instance values."""
          self.title      = title
          if topic == '':
               self.topic = title
          else:
               self.topic = topic
          self.maintainer = maintainer
          self._p_changed = 1
          RESPONSE.redirect('manage_editDoctrineFolderForm')

     def getDoctrineInfo(oid):
         """Return an id (for the url) and a title of a specific Legal Doctrine"""
         found    = 0
         contents = []

         # Run thorugh the objects in the folder to see if there are any Legal Doctrines...
         for obj in container.objectValues('Legal Doctrine'):
              if found == 0:
                   if oid == obj.getId():
                        url       = obj.abolute_url
                        title     = obj.title
                        thumbs_up = obj.thumbs_up
                        contents.append(namespace(url=url, title=title, thumbs_up=thumbs_up)[0])
                        found = 1   # set the flag on success to avoid repeating the loop...

         # Return indicative values if the object wasn't found...
         if found == 0:
              contents.append(namespace(url='', title='', thumbs_up=0)[0])

         vars = namespace(contents=contents)

         return vars


def manage_addDoctrineFolder(self, id, title, topic, maintainer, REQUEST=None):
     """Add a Legal Doctrine Folder to another folder."""
     id         = str(id)
     title      = str(title)
     topic      = str(topic)
     maintainer = str(maintainer)
     c          = DoctrineFolder(id, title, topic, maintainer)
     self._setObject(id, c)
     if REQUEST is not None:
          return self.manage_main(self, REQUEST)

--------------A21D2190D68C8BC003CE0695
Content-Type: text/plain; charset=us-ascii;
 name="index_html.dtml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="index_html.dtml"

<dtml-var standard_html_header>

<H2 ALIGN="center"><dtml-var title></H2>

<TABLE ALIGN="center" WIDTH="95%" CELLSPACING="8" BORDER="0">
  <dtml-if expr="title <> ''">
  	<TR>
		  <TH ALIGN="right" VALIGN="top" WIDTH="20%">Title:</TH>
  		<TD WIDTH="80%"><dtml-var title></TD>
  	</TR>
  </dtml-if>
  <dtml-if expr="status <> ''">
  	<TR>
		  <TH ALIGN="right" VALIGN="top" WIDTH="20%">Topic:</TH>
  		<TD WIDTH="80%"><dtml-var topic></TD>
  	</TR>
  </dtml-if>
  <dtml-if expr="maintainer <> ''">
	<TR>
		<TH ALIGN="right" VALIGN="top" WIDTH="20%">Maintainer:</TH>
		<TD WIDTH="80%"><dtml-var maintainer></TD>
	</TR>
  </dtml-if>
</TABLE>

<dtml-var standard_html_footer>

--------------A21D2190D68C8BC003CE0695
Content-Type: text/html; charset=us-ascii;
 name="manage_addDoctrineFolderForm.dtml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="manage_addDoctrineFolderForm.dtml"

<HTML>
<HEAD>
	<TITLE>Add a new Legal Doctrine</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<H2 ALIGN="center">Add a Legal Doctrine to the Current Folder</H2>

<P ALIGN="center">This is your opportunity to customize your new legal doctrine web page.<BR>
Below, you can specify the title, initial discussion, status, and several other parameters.</P>

<P ALIGN="center">Each element of the legal doctrine web page is listed below, <BR>
along with a short explanation of the element, and an example of acceptable input.</P>

<FORM NAME="add_form" ACTION="manage_addDoctrineFolder" METHOD="post">
  <TABLE ALIGN="CENTER" WIDTH="95%" CELLSPACING="8">

    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">ID:</TH>
      <TD WIDTH="85%">
        <INPUT TYPE="text" NAME="id:string" SIZE="40" VALUE=""><BR>
         For example, if you have a legal topic called "Software Patents," then a good id
         would be "<strong>insanity_defense</strong>".

         <P>The id is a string of characters that identify this object to the server.  This is an
         important property.  Judicious selection of an id can make it easy to reference
         this particular legal doctrine to yourself and other users.  For one, the application
         server utilizes the id in order to display the doctrine to web users.  That's right,
         you can reference this legal doctrine via hyperlink simply by referring to its id.

         <P>Note, you may not have blanks, periods, or similar characters in an id.  Just
         stick to characters (A-Z, a-z) and numbers (0-9) and the underscore ('_') character,
         and you will do just fine.</P>
      </TD>
    </TR>

    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Title:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="title:string" SIZE="60" VALUE=""><BR>
        For example, if you have a legal topic called "Software Patents," then a good title
        would be "<strong>Software Patents</strong>."  Try to keep the title short, but descriptive.</P>
      </TD>
    </TR>

    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Topic:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="topic:string" SIZE="60" VALUE=""><BR>
        The field contains a few words that summarize the point of the cases and doctrines discussed.
        Examples include "<strong>Insanity Defense</strong>," or
        "<strong>Software Patents</strong>."
     </TD>
    </TR>

    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Maintainer:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="maintainer:string" SIZE="60" VALUE=""><BR>
        This is the name of the person who maintains this page.  This is an optional field.  If left blank,
        no name will appear.  However, people viewing the site may wish to speak to the expert that assembled
        this web page.  Good advertisement for the partner or associate who assembled the site.

        <P><em>Hint:</em>You can include a hyperlink to your e-mail by embedding your e-mail address in your
        name.  For example, simply type in the following code into the Maintainer field:</P>
        <P><PRE>&lt;A HREF="mailto:firstname.lastname@myfirm.com"&gt;Firstname Lastname&lt;/A&gt;</PRE></P>
      </TD>
    </TR>

    <TR>
      <TD ALIGN="right" VALIGN="top" WIDTH="15%"></TD>
      <TD WIDTH="85%"><INPUT TYPE="submit" NAME="submit" VALUE=" Submit "></TD>
    </TR>

  </TABLE>

</FORM>

</BODY>
</HTML>

--------------A21D2190D68C8BC003CE0695
Content-Type: text/html; charset=us-ascii;
 name="manage_editDoctrineFolderForm.dtml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="manage_editDoctrineFolderForm.dtml"

<HTML>
<HEAD>
	<TITLE>Edit the Legal Doctrine</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<H2 ALIGN="center">Edit the Legal Doctrine in the Current Folder</H2>

<P ALIGN="center">This is your opportunity to customize your legal doctrine web page.<BR>
Below, you can modify any of the parameters in the object.</P>

<FORM NAME="manage_editDoctrineFolderForm" ACTION="manage_editDoctrineFolderAction" METHOD="post">
  <TABLE ALIGN="CENTER" WIDTH="95%" CELLSPACING="8">
    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Title:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="title:string" SIZE="60" VALUE="<dtml-var title>"></TD>
    </TR>
    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Topic:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="topic:string" SIZE="60" VALUE="<dtml-var status>"></TD>
    </TR>
    <TR>
      <TH ALIGN="right" VALIGN="top" WIDTH="15%">Maintainer:</TH>
      <TD WIDTH="85%"><INPUT TYPE="text" NAME="maintainer:string" SIZE="60" VALUE="<dtml-var maintainer>"></TD>
    </TR>
    <TR>
      <TD ALIGN="right" VALIGN="top" WIDTH="15%"></TD>
      <TD WIDTH="85%"><INPUT TYPE="submit" NAME="submit" VALUE=" Save Changes "></TD>
    </TR>
  </TABLE>
</FORM>

</BODY>
</HTML>

--------------A21D2190D68C8BC003CE0695
Content-Type: text/plain; charset=us-ascii;
 name="__init__.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="__init__.py"

import DoctrineFolder
import Doctrine
import Case

def initialize(context):
     """This is the Legal Doctrine Product"""

     context.registerClass(
          DoctrineFolder.DoctrineFolder,
          permission='Add Legal Doctrine Folder',
          constructors = (
               DoctrineFolder.manage_addDoctrineFolderForm,
               DoctrineFolder.manage_addDoctrineFolder
          ),
          icon = 'images/doctrineFolder.jpg',
     )

     context.registerClass(
          Doctrine.Doctrine,
          permission='Add Legal Doctrines',
          constructors = (
               Doctrine.manage_addDoctrineForm,
               Doctrine.manage_addDoctrine
          ),
          icon = 'images/doctrine.jpg',
     )

     context.registerClass(
          Case.Case,
          permission='Add Legal Cases',
          constructors = (
               Case.manage_addCaseForm,
               Case.manage_addCase
          ),
          icon = 'images/case.jpg'
     )

--------------A21D2190D68C8BC003CE0695--