Explicit support for browsing by instructor and course in addition to department.
authorArt Rhyno <art632000@yahoo.ca>
Wed, 22 Jun 2011 02:39:34 +0000 (22:39 -0400)
committerArt Rhyno <art632000@yahoo.ca>
Wed, 22 Jun 2011 02:39:34 +0000 (22:39 -0400)
Signed-off-by: Art Rhyno <art632000@yahoo.ca>
conifer/syrup/views/sites.py
conifer/templates/browse_index.xhtml

index 9b64b8e..bc4af67 100644 (file)
@@ -187,16 +187,22 @@ def my_sites(request):
     return g.render('my_sites.xhtml', **locals())
 
 
-def browse(request, browse_option=''):
+def browse(request, browse_option='Department'):
     #the defaults should be moved into a config file or something...
     page_num = int(request.GET.get('page', 1))
     count    = int(request.GET.get('count', 5))
     timeframe = request.session.get('timeframe', 0)
     time_query = models.Term.timeframe_query(timeframe)
     queryset = None
-    template = 'browse_index.xhtml'
-    sites = list(models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name').select_related().filter(time_query))
-    blocks = itertools.groupby(sites, lambda s: s.course.department)
+    if browse_option == 'Instructor':
+        sites = list(models.Site.objects.order_by('owner__last_name', 'course__department__name', 'course__code').select_related().filter(time_query))
+        blocks = itertools.groupby(sites, lambda s: s.owner.last_name)
+    elif browse_option == 'Course':
+        sites = list(models.Site.objects.order_by('course__code', 'owner__last_name', 'course__department__name').select_related().filter(time_query))
+        blocks = itertools.groupby(sites, lambda s: s.course.code)
+    else:
+        sites = list(models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name').select_related().filter(time_query))
+        blocks = itertools.groupby(sites, lambda s: s.course.department)
     return g.render('browse_index.xhtml', **locals())
 
 
index c71fabc..0082932 100644 (file)
@@ -1,5 +1,12 @@
 <?python
-title = _('All Reserves, by Department')
+option2 = _('Instructor')
+option3 = _('Course')
+if browse_option == 'Instructor':
+    option2 = _('Department')
+    option3 = _('Course')
+elif browse_option == 'Course':
+    option2 = _('Department')
+    option3 = _('Instructor')
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:xi="http://www.w3.org/2001/XInclude"
@@ -7,10 +14,12 @@ title = _('All Reserves, by Department')
 <xi:include href="master.xhtml"/>
 <xi:include href="components/timeframe.xhtml"/>
 <head>
-  <title>${title}</title>
+  <title>All Reserves by ${browse_option}</title>
 </head>
 <body>
-  <h1>${title}</h1>
+  <h1>All Reserves by ${browse_option}</h1> 
+    (list by <a href="${ROOT}/browse/${option2}">${option2}</a>, 
+    list by <a href="${ROOT}/browse/${option3}">${option3}</a>)
   ${timeframe_nav(timeframe)}
   <p py:if="user.is_anonymous() and sites">
     (Note: some reserve materials may require you