[open-ils-commits] r60 - in servres/trunk/conifer: syrup templates templates/components

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Nov 26 21:35:25 EST 2008


Author: gfawcett
Date: 2008-11-26 21:35:24 -0500 (Wed, 26 Nov 2008)
New Revision: 60

Added:
   servres/trunk/conifer/templates/components/
   servres/trunk/conifer/templates/components/item.xhtml
   servres/trunk/conifer/templates/item_heading_detail.xhtml
Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/course_detail.xhtml
Log:
added specialized views for subheadings, items with URLs


Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2008-11-27 00:59:44 UTC (rev 59)
+++ servres/trunk/conifer/syrup/models.py	2008-11-27 02:35:24 UTC (rev 60)
@@ -117,12 +117,17 @@
     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
@@ -139,7 +144,7 @@
                 sub = []
                 walk(item, sub)
                 accum.append((item, sub))
-        walk(None, out)
+        walk(subtree, out)
         return out
 
 

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2008-11-27 00:59:44 UTC (rev 59)
+++ servres/trunk/conifer/syrup/views.py	2008-11-27 02:35:24 UTC (rev 60)
@@ -80,13 +80,25 @@
     # 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)
     

Added: servres/trunk/conifer/templates/components/item.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/item.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/components/item.xhtml	2008-11-27 02:35:24 UTC (rev 60)
@@ -0,0 +1,19 @@
+<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>
+	&bull; <a href="/admin/syrup/item/${item.id}/">edit</a>
+	]
+      </span>
+      ${show_tree(subs)}
+    </li>
+  </ul>
+
+</html>

Modified: servres/trunk/conifer/templates/course_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/course_detail.xhtml	2008-11-27 00:59:44 UTC (rev 59)
+++ servres/trunk/conifer/templates/course_detail.xhtml	2008-11-27 02:35:24 UTC (rev 60)
@@ -1,11 +1,12 @@
 <?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>
@@ -13,25 +14,9 @@
     <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>
-	    &bull; <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>

Added: servres/trunk/conifer/templates/item_heading_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_heading_detail.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/item_heading_detail.xhtml	2008-11-27 02:35:24 UTC (rev 60)
@@ -0,0 +1,24 @@
+<?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>



More information about the open-ils-commits mailing list