def items(self):
return self.item_set.all()
- def item_tree(self):
+ def item_tree(self, subtree=None):
"""
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 a list of sub-elements (if
a heading) or None (if an item).
+
+ You can provide a 'subtree', an item which is the top node in
+ a subtree of the item-tree. If subtree is provided, then
+ return either a signle (Item, [Item]) pair, where Item is the
+ subtree element, or None if there is no match.
"""
items = self.items()
# make a node-lookup table
sub = []
walk(item, sub)
accum.append((item, sub))
- walk(None, out)
+ walk(subtree, out)
return out
# it is -- e.g. a URL item would redirect to the target URL. I'd
# like this URL to be the generic dispatcher, but for now let's
# just display some metadata about the item.
- return item_metadata(request, course_id, item_id)
+ item = get_object_or_404(models.Item, pk=item_id, course__id=course_id)
+ if item.url:
+ return _heading_url(request, item)
+ else:
+ return item_metadata(request, course_id, item_id)
def item_metadata(request, course_id, item_id):
"""Display a metadata page for the item."""
- course = get_object_or_404(models.Course, pk=course_id)
- item = get_object_or_404(models.Item, pk=item_id)
- assert item.course == course, 'Item not in course'
- return g.render('item_metadata.xhtml', course=course,
- item=item)
+ item = get_object_or_404(models.Item, pk=item_id, course__id=course_id)
+ if item.item_type == 'HEADING':
+ return _heading_detail(request, item)
+ else:
+ return g.render('item_metadata.xhtml', course=item.course,
+ item=item)
+
+def _heading_url(request, item):
+ return HttpResponseRedirect(item.url)
+
+def _heading_detail(request, item):
+ """Display a heading. Show the subitems for this heading."""
+ return g.render('item_heading_detail.xhtml', item=item)
--- /dev/null
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ py:strip="">
+
+ <!-- !show_tree: display a tree of items in a hierarchical style. -->
+ <ul py:def="show_tree(tree)" py:if="tree">
+ <li py:for="item, subs in tree">
+ <a href="item/${item.id}/">${item}</a>
+ <span class="metalinks">
+ [<a href="item/${item.id}/meta">about</a>
+ • <a href="/admin/syrup/item/${item.id}/">edit</a>
+ ]
+ </span>
+ ${show_tree(subs)}
+ </li>
+ </ul>
+
+</html>
<?python
title = '%s: %s (%s)' % (course.code, course.title, course.term)
-items = course.items()
+item_tree = course.item_tree(subtree=item)
?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:py="http://genshi.edgewall.org/">
<xi:include href="master.xhtml"/>
+ <xi:include href="components/item.xhtml"/>
<head>
<title>${title}</title>
</head>
<h1>${title}</h1>
<p>${course.department}</p>
<h2>Reserve Items</h2>
- <p py:if="not items">
+ <p py:if="not item_tree">
There are no items associated with this course yet.
</p>
- <div py:if="items">
-
- <ul py:def="show_tree(tree)" py:if="tree">
- <li py:for="item, subs in tree">
- <a href="item/${item.id}/">${item}</a>
- <span class="metalinks">
- [<a href="item/${item.id}/meta">about</a>
- • <a href="/admin/syrup/item/${item.id}/">edit</a>
- ]
- </span>
- ${show_tree(subs)}
- </li>
- </ul>
- ${show_tree(course.item_tree())}
-
-
- </div>
+ ${show_tree(course.item_tree())}
</body>
</html>
--- /dev/null
+<?python
+course = item.course
+title = item.title
+course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+item_tree = course.item_tree(subtree=item)
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+ <xi:include href="master.xhtml"/>
+ <xi:include href="components/item.xhtml"/>
+ <head>
+ <title>${title}</title>
+ </head>
+ <body>
+ <h1>${title}</h1>
+ <p><a href="../../">${course_title}</a></p>
+ <p>${course.department}</p>
+ <p py:if="not item_tree">
+ There are no items associated in this subheading.
+ </p>
+ ${show_tree(item_tree)}
+ </body>
+</html>