[Zope-dev] TALES idea: tuple unpacking

Paul Winkler pw_lists@slinkp.com
Wed, 23 Jul 2003 03:08:38 -0400


On Wed, Jul 23, 2003 at 03:59:58PM +1000, Richard Jones wrote:

> Say a method listFilesByUser returns a list of (user, [files]) 
> it'd be nice to > be able to::
> 
>    tal:repeat="user,files here/listFilesByUser"
> 
> or similar. Currently we would have to use a python: expression to manually 
> unpack the tuple. Kinda yucky.
> 
> Any comments?

hmm... so you want to extend the language so you can write:

  <span tal:repeat="user,files here/listFilesPerUser">
    <div tal:content="user"> 
      user goes here 
    </div>
    <div tal:repeat="file files"
         tal:content="file"> 
      file goes here 
    </div>
  </span>


I disagree... There's probably a million little things that
"would be nice" in ZPT. Rather than feature-creep TAL/TALES, which
are pretty simple currently, let's leave the heavy lifting to
our favorite tried-and-true general-purpose language.

In this case, consider a trivial change to (or wrapper around) 
listFilesByUser to make it return a sequence of dictionaries
like {'user': some_user, 'files': (file1, file2...)}
Then your zpt could look like:

  <span tal:repeat="fpu here/listFilesPerUser">
    <div tal:content="fpu/user"> 
      user goes here 
    </div>
    <div tal:repeat="file fpu/files"
         tal:content="file"> 
      file goes here 
    </div>
  </span>


-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's TWINKLY-GIANT WOMAN!
(random hero from isometric.spaceninja.com)