[Zope-dev] ZPatterns patches

Steve Alexander steve@cat-box.net
Sat, 20 Jan 2001 12:55:19 +0000


I've put an extensive patch to ZPatterns 0-4-3b2 here:

   http://www.cat-box.net/steve/ZPatterns.patch

The patch includes the following:

* Fix to _memento class so it works with Zope 2.3

* Alteration to GAPMixin so the the attributes it says it provides come 
from the union of the assignments and the defaults.

* Add style="width: 100%;" to SkinScript edit textarea, in line with 
other zope textareas.

* Add syntax to SkinScript "INVALIDATE FOR". You can put an optional 
invalidate-for clause at the end of a compute statement. This causes the 
attributes provided by the statement to be invalidated from the 
dataskin's attribute cache when any of the attributes named after 
INVALIDATE FOR change. It is easier to demonstrate than to explain :-)


There's also an updated PlugIns/www/main.dtml file at:

   http://www.cat-box.net/steve/main.dtml


An example of the new SkinScript syntax:

WITH SELF COMPUTE
   name='%s %s' % (forename, surname)
INVALIDATE FOR
   forename, surname

This is useful if you're providing attributes from another DataSkin. 
Here's an example from some school management software. This is an 
attribute provider for Pupils. A Pupil may have an Instructor. This is 
implemented by the attribute instructor_id of Pupil.

# the instructor is only valid if the pupil is current
WITH SELF COMPUTE
   has_instructor=instructor_id or 0 and current and 1

# don't use has_instructor below, or the instructor details for
# cataloging won't get updated when the assigned instructor changes
# from no instructor to having an instructor.
WITH self.instructor_id and self.current and
   Instructors.getItem(self.instructor_id) or NOT_FOUND COMPUTE
   instructor_name=name,
   instructor_name_link='<a href="%s">%s</a>' %
     (absolute_url(), html_quote(name)),
   instructor_sort_key=sort_key,
   instructor=RESULT
OTHERWISE LET
   instructor_name='no instructor',
   instructor_name_link='no instructor',
   instructor_sort_key='----',
   instructor=_.None


The problem here is that I can't use has_instructor in the WITH clause, 
if I'm also using has_instructor in the same transaction as I'm updating 
instructor_id. I have to use "self.instructor_id and self.current" 
instead, as above.

However, with the new syntax, I don't have to worry about that:

# the instructor is only valid if the pupil is current
WITH SELF COMPUTE
   has_instructor=instructor_id or 0 and current and 1
INVALIDATE FOR
   current, instructor_id

WITH has_instructor and Instructors.getItem(self.instructor_id)
   or NOT_FOUND COMPUTE
   instructor_name=name,
   instructor_name_link='<a href="%s">%s</a>' %
     (absolute_url(), html_quote(name)),
   instructor_sort_key=sort_key,
   instructor=RESULT
OTHERWISE LET
   instructor_name='no instructor',
   instructor_name_link='no instructor',
   instructor_sort_key='----',
   instructor=_.None


Thanks to PJE for pointing me in the right direction on how to implement 
this.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net