ZPT with Zope 3 queries - repeat over contained items; accessing adapters
Hello, I'm building an application in Zope 3. I have a container object called a PropertyFolder, which holds Property objects. * Repeating over contained items. I'm trying to create a view which displays a list of all the Property objects in a property folder. I've tried doing this as described in the ZPT chapter of the Zope Book (2.6 edition), using a tal:repeat statement, but I can't seem to get it working. Has something changed in Zope 3? I've tried looking in the Zope 3 book, but none of the references to tal:repeat in there seem to be used for this type of thing. * Accessing adapters in ZPT I've created an adapter that provides a method called getStars that can be used on Property objects. Can I access this directly from my ZPT, as I can any other attribute of a property object? At the moment I've got it implemented via a Python view class, so my ZPT accesses it like: <div class="field" tal:content="view/stars" /> but other attributes can be accessed like: <div class="field" tal:content="context/description" /> so I guess I want to be able to do: <div class="field" tal:content="context/getStars" /> and negate the need for the Python View Class, which only says: def stars(self): """Get the stars for the property""" rate = IPropertyRate(self.context) stars = rate.getStars() return stars Thanks in advance for any tips. Thanks, Jim ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
Hello, Re-reading this, I realised I'd not provided much information on the "repeat" problem, so I'm filling in some gaps. This works as I would expect: <table border="1" width="80%"> <tr> <th>Number</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> </tr> </table> i.e., if it is repeating over a property folder with four objects in it, it produces a table headed "Number" and with 4 further rows with numbers 1, 2, 3, and 4 in. However, as soon as I add any meat to it, e.g.: <table border="1" width="80%"> <tr> <th>Number</th> <th>Name</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> <td tal:content="item/Name">Name</td> </tr> </table> I get an error which shows up on the error log as: "TypeError: tuple indices must be integers" I have tried the second <td> element as all sorts: <td tal:content="item/name">Name</td> and: <td tal:content="item/title">Name</td> and: <td tal:content="item/getId">Name</td> and: <td tal:content="item/street">Name</td> (all of the objects in the PropertyFolder have a "street" attribute) These all give the same error. Since my simple test case works, it seems like I'm setting the loop up correctly, but am asking for the data in the wrong way later on. getId and title certainly look from the Zope 2.6 book like they should work, and I tried the rest as "guesses". Where should I be looking to find the correct information on how to do this in Zope 3? Thanks, Jim
Hello,
I'm building an application in Zope 3. I have a container object called a PropertyFolder, which holds Property objects.
* Repeating over contained items.
I'm trying to create a view which displays a list of all the Property objects in a property folder. I've tried doing this as described in the ZPT chapter of the Zope Book (2.6 edition), using a tal:repeat statement, but I can't seem to get it working. Has something changed in Zope 3? I've tried looking in the Zope 3 book, but none of the references to tal:repeat in there seem to be used for this type of thing.
___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jim Vine wrote:
Hello,
Re-reading this, I realised I'd not provided much information on the "repeat" problem, so I'm filling in some gaps.
This works as I would expect:
<table border="1" width="80%"> <tr> <th>Number</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> </tr> </table>
i.e., if it is repeating over a property folder with four objects in it, it produces a table headed "Number" and with 4 further rows with numbers 1, 2, 3, and 4 in.
However, as soon as I add any meat to it, e.g.:
<table border="1" width="80%"> <tr> <th>Number</th> <th>Name</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> <td tal:content="item/Name">Name</td> </tr> </table>
I get an error which shows up on the error log as:
"TypeError: tuple indices must be integers"
Likely, 'context' is a dict, or a workalike, whose 'items' method returns a sequence of tuples. Therefore, during the tal:repeat, 'item' is a tuple, (key, value). Try using 'values' instead of 'items'. Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCynuh+gerLs4ltQ4RAl5uAKCRzRzV+g1M8gcbV07jSNfCQbWbhgCg0nL4 2POVN4oUQepYUIQ+pR1IPRU= =fBFx -----END PGP SIGNATURE-----
Thanks for that info. I've tried a couple of extra things (below) and if I'm reading the output right I thing you're correct about "items" returning a tuple, and "values" returning the object. When I do the repeat like this: <tr tal:repeat="item context/items"> <td tal:content="item">Name</td> </tr> The data presented look like this: (u'Property', <lettings.property.Property object at 0x027ABEF0>) However when I repeat over "values" instead of "items" like this: <tr tal:repeat="item context/values"> <td tal:content="item">Name</td> </tr> ... they change to this format: <security proxied lettings.property.Property instance at 0x027ABEF0> So, it looks to me like values is returning the contained item as single item, rather than a tuple of it... However, I still can't drag anything out of it. Having changed the tal:repeat to "item context/values", I have tried item/name, item/Name, item/getName, item/title, item/Title... All return "NotFoundError". I've googled, but am yet to find any Zope 3 specific documentation for ZPT - could anyone point me in the direction of some? (Or am I just doing something wrong that wouldn't have worked in Zope 2 either?!?) Thanks, Jim --- Tres Seaver <tseaver@palladion.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Jim Vine wrote:
Hello,
Re-reading this, I realised I'd not provided much information on the "repeat" problem, so I'm filling in some gaps.
This works as I would expect:
<table border="1" width="80%"> <tr> <th>Number</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> </tr> </table>
i.e., if it is repeating over a property folder with four objects in it, it produces a table headed "Number" and with 4 further rows with numbers 1, 2, 3, and 4 in.
However, as soon as I add any meat to it, e.g.:
<table border="1" width="80%"> <tr> <th>Number</th> <th>Name</th> </tr> <tr tal:repeat="item context/items"> <td tal:content="repeat/item/number">#</td> <td tal:content="item/Name">Name</td> </tr> </table>
I get an error which shows up on the error log as:
"TypeError: tuple indices must be integers"
Likely, 'context' is a dict, or a workalike, whose 'items' method returns a sequence of tuples. Therefore, during the tal:repeat, 'item' is a tuple, (key, value).
Try using 'values' instead of 'items'.
Tres. - --
===================================================================
Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCynuh+gerLs4ltQ4RAl5uAKCRzRzV+g1M8gcbV07jSNfCQbWbhgCg0nL4
2POVN4oUQepYUIQ+pR1IPRU= =fBFx -----END PGP SIGNATURE-----
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
participants (2)
-
Jim Vine -
Tres Seaver