[Zope] Best way to order objects in folder?

Jim Washington jwashin@vt.edu
Wed, 19 Apr 2000 09:12:05 -0400


Hi, Alexander

Here is something I did in a folderish zclass I am working on.  The idea
here is to assign a property, doc_sequence, so that you can later get
the items using "objectItems() sort=doc_sequence".  This of course does
not work with DTML Methods or other kinds of things that do not have
Properties.  Floating point values are nice because you can always order
an item between two other items without changing their values.

I have included my code here because it is pretty small.  I presume if
the code is too ugly to use, someone will please let me know before it
breeds.

order_manage:management tab for ordering documents

<dtml-call dtmldocseq>
<html><head><title><dtml-var id></title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555">
<dtml-var manage_tabs><p>
<h3>Item Ordering</h3>
<p>Items with lower numbers go earlier on the page.</p>
<form action=manage_changeOrder>
<table>
<dtml-in "objectItems(['DTML Document'])" sort=doc_sequence>
<tr><td><input type="text" size="5" name="<dtml-var id>"
value="<dtml-var doc_sequence>"></td><td><dtml-var title></td></tr>
</dtml-in>
<tr><td></td><td><input type="submit" value="Save Changes"></td></tr>
</form>
</table>
</body></html>

manage_changeOrder:take the REQUEST from order_manage and change
doc_sequence if necessary

<dtml-in "REQUEST.form.keys()">
<dtml-let anitem=sequence-item f="this()[anitem]">
<dtml-if "f.meta_type == 'DTML Document'">
<dtml-unless "f.doc_sequence==_.float(REQUEST.form[anitem])">
<dtml-call
"f.manage_changeProperties(doc_sequence=_.float(REQUEST.form[anitem]))">
</dtml-unless>
</dtml-if>
</dtml-let>
</dtml-in>
<dtml-var "MessageDialog(title='success!', message='Your changes have
been saved!', action='order_manage')">

dtmldocseq:assure all items have the doc_sequence property

<dtml-if "objectIds(['DTML Document'])">
<dtml-in "objectIds(['DTML Document'])">
<dtml-let thedoc="_.getitem(_['sequence-item'])">
<dtml-with thedoc>  
<dtml-unless "thedoc.hasProperty('doc_sequence')">
<dtml-call "thedoc.manage_addProperty('doc_sequence',1.0,'float')">
</dtml-unless>
</dtml-with>
</dtml-let>
</dtml-in>
</dtml-if>

MessageDialog:this is in the Zope source, but not really accessible.  So
we use our own copy.

<HTML>
<HEAD>
<TITLE><dtml-var title></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM ACTION="<dtml-var action>" METHOD="GET" <dtml-if
 target>TARGET="<dtml-var target>"</dtml-if>>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="10">
<TR>
  <TD VALIGN="TOP">
  <BR>
  <CENTER><B><FONT SIZE="+6" COLOR="#77003B">!</FONT></B></CENTER>
  </TD>
  <TD VALIGN="TOP">
  <BR><BR>
  <CENTER>
  <dtml-var message>
  </CENTER>
  </TD>
</TR>
<TR>
  <TD VALIGN="TOP">
  </TD>
  <TD VALIGN="TOP">
  <CENTER>
  <INPUT TYPE="SUBMIT" VALUE="   Ok   ">
  </CENTER>
  </TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>



Alexander Schonfeld wrote:
> 
> What is the best way to specify an order to objects?  It always seems to
> come down to making a token/list property with object ids.  But this is
> annoying since I have to change two places if the id changes... and it
> breaks the site if I forget.
> 
> Maybe a folder which assigns #s to its objects and allows re-arranging?
> 
> Any people doing similar stuff?  Any ideas?

-- 

Jim Washington
Center for Assessment, Evaluation and Educational Programming
Department of Teaching and Learning, Virginia Tech