From: gfawcett Date: Thu, 27 Nov 2008 02:35:24 +0000 (+0000) Subject: added specialized views for subheadings, items with URLs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=78131139f0cb682e8dfdcdac1aadfc1f72855036;p=syrup%2Fmasslnc.git added specialized views for subheadings, items with URLs git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@60 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index cd5cf37..49d8f80 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -117,12 +117,17 @@ class Course(m.Model): 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 @@ class Course(m.Model): sub = [] walk(item, sub) accum.append((item, sub)) - walk(None, out) + walk(subtree, out) return out diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index aeecf22..3412faa 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -80,13 +80,25 @@ def item_detail(request, course_id, item_id): # 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) diff --git a/conifer/templates/components/item.xhtml b/conifer/templates/components/item.xhtml new file mode 100644 index 0000000..e8b1dd3 --- /dev/null +++ b/conifer/templates/components/item.xhtml @@ -0,0 +1,19 @@ + + + + + + diff --git a/conifer/templates/course_detail.xhtml b/conifer/templates/course_detail.xhtml index a367880..a7f1ed9 100644 --- a/conifer/templates/course_detail.xhtml +++ b/conifer/templates/course_detail.xhtml @@ -1,11 +1,12 @@ + ${title} @@ -13,25 +14,9 @@ items = course.items()

${title}

${course.department}

Reserve Items

-

+

There are no items associated with this course yet.

-
- - - ${show_tree(course.item_tree())} - - -
+ ${show_tree(course.item_tree())} diff --git a/conifer/templates/item_heading_detail.xhtml b/conifer/templates/item_heading_detail.xhtml new file mode 100644 index 0000000..cb29b0f --- /dev/null +++ b/conifer/templates/item_heading_detail.xhtml @@ -0,0 +1,24 @@ + + + + + + ${title} + + +

${title}

+

${course_title}

+

${course.department}

+

+ There are no items associated in this subheading. +

+ ${show_tree(item_tree)} + +