[open-ils-commits] r58 - in servres/trunk/conifer: syrup templates
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Nov 26 19:59:42 EST 2008
Author: gfawcett
Date: 2008-11-26 19:59:41 -0500 (Wed, 26 Nov 2008)
New Revision: 58
Modified:
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/templates/course_detail.xhtml
Log:
Course.item_tree working, sample display code in course_detail.xhtml
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2008-11-26 22:25:46 UTC (rev 57)
+++ servres/trunk/conifer/syrup/models.py 2008-11-27 00:59:41 UTC (rev 58)
@@ -115,16 +115,32 @@
return self.code or self.title
def items(self):
- return Item.objects.filter(course=self.id)
+ return self.item_set.all()
def item_tree(self):
"""
Return a list, representing a tree of the course items, in
display order. Every element of the list is an (Item, [Item])
- tuple, where the second element is the (optional) list of
- sub-elements (if a heading) or None (if an item).
+ tuple, where the second element is a list of sub-elements (if
+ a heading) or None (if an item).
"""
- raise NotImplementedError
+ items = self.items()
+ # make a node-lookup table
+ dct = {}
+ for item in items:
+ dct.setdefault(item.parent_heading, []).append(item)
+ for lst in dct.values():
+ lst.sort(key=lambda item: item.sort_order) # sort in place
+ # walk the tree
+ out = []
+ def walk(parent, accum):
+ here = dct.get(parent, [])
+ for item in here:
+ sub = []
+ walk(item, sub)
+ accum.append((item, sub))
+ walk(None, out)
+ return out
class Member(m.Model):
Modified: servres/trunk/conifer/templates/course_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/course_detail.xhtml 2008-11-26 22:25:46 UTC (rev 57)
+++ servres/trunk/conifer/templates/course_detail.xhtml 2008-11-27 00:59:41 UTC (rev 58)
@@ -25,9 +25,20 @@
<tr py:for="item in items">
<td><a href="item/${item.id}/">${item.title}</a></td>
<td>${item.item_type}</td>
+ <td>${item.parent_heading}</td>
</tr>
</tbody>
</table>
+
+ <h2>Show-as-tree test</h2>
+
+ <ol py:def="show_tree(tree)" py:if="tree">
+ <li py:for="item, subs in tree">
+ ${item}
+ ${show_tree(subs)}
+ </li>
+ </ol>
+ ${show_tree(course.item_tree())}
</div>
</body>
</html>
More information about the open-ils-commits
mailing list