refactored the Browse features. Marked methods proposed for deletion.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 02:05:16 +0000 (02:05 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 02:05:16 +0000 (02:05 +0000)
We have some cruft in views.py and urls.py. I'm proposing to cut it
unless artunit can think of a good reason to keep it. I've marked the
methods and URLs with "MARK".

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@207 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py
conifer/syrup/urls.py
conifer/syrup/views.py
conifer/templates/browse_courses.xhtml [deleted file]
conifer/templates/browse_index.xhtml [new file with mode: 0644]

index cb01746..e1338cd 100644 (file)
@@ -133,7 +133,7 @@ class Term(m.Model):
 class Department(m.Model):
     abbreviation = m.CharField(max_length=8,db_index=True)
     name   = m.CharField(max_length=255)
-    active       = m.BooleanField(default=True)
+    active = m.BooleanField(default=True)
 
     def __unicode__(self):
         return self.name
index 35890ab..a4e9d5a 100644 (file)
@@ -12,14 +12,17 @@ urlpatterns = patterns('conifer.syrup.views',
     (r'^course/new/$', 'add_new_course'),
     (r'^course/new/ajax_title$', 'add_new_course_ajax_title'),
     (r'^course/invitation/$', 'course_invitation'),
-    (r'^browse/$', 'browse_courses'),
-    (r'^browse/(?P<browse_option>.*)/$', 'browse_courses'),
+    (r'^browse/$', 'browse'),
+    (r'^browse/(?P<browse_option>.*)/$', 'browse'),
     (r'^prefs/$', 'user_prefs'),
     (r'^z3950test/$', 'z3950_test'),
+    #MARK: propose we kill open_courses, we have browse.
     (r'^opencourse/$', 'open_courses'),
     (r'^search/$', 'search'),
     (r'^zsearch/$', 'zsearch'),
+    #MARK: propose we kill instructors, we have browse
     (r'^instructors/$', 'instructors'),
+    #MARK: propose we kill departments, we have browse
     (r'^departments/$', 'departments'),
     (r'^course/(?P<course_id>\d+)/$', 'course_detail'),
     (r'^instructor/(?P<instructor_id>.*)/$', 'instructor_detail'),
index 6df874b..4a99a33 100644 (file)
@@ -185,6 +185,7 @@ def welcome(request):
 def setlang(request):
     return g.render('setlang.xhtml')
 
+# MARK: propose we get rid of this. We already have a 'Courses' browser.
 def open_courses(request):
     page_num = int(request.GET.get('page', 1))
     count = int(request.GET.get('count', 5))
@@ -192,7 +193,7 @@ def open_courses(request):
     return g.render('open_courses.xhtml', paginator=paginator,
                     page_num=page_num,
                     count=count)
-
+# MARK: propose we drop this too. We have a browse.
 def instructors(request):
     page_num = int(request.GET.get('page', 1))
     count = int(request.GET.get('count', 5))
@@ -208,7 +209,7 @@ def instructors(request):
                     page_num=page_num,
                     count=count)
 
-
+# MARK: propose we get rid of this. We have browse.
 def departments(request):
     raise NotImplementedError
 
@@ -235,34 +236,29 @@ def z3950_test(request):
 
     return g.render('z3950_test.xhtml', res_str=res_str)
 
-def browse_courses(request, browse_option=''):
+def browse(request, browse_option=''):
     #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))
-
-    if browse_option == 'instructors':
-        paginator = Paginator(models.User.active_instructors(),
-                              count)
-
-        return g.render('instructors.xhtml', paginator=paginator,
-            page_num=page_num,
-            count=count)
-
+    count    = int(request.GET.get('count', 5))
+
+    if browse_option == '':
+        queryset = None
+        template = 'browse_index.xhtml'
+    elif browse_option == 'instructors':
+        queryset = models.User.active_instructors()
+        template = 'instructors.xhtml'
     elif browse_option == 'departments':
-        paginator = Paginator(models.Department.objects.filter(active=True), count)
-
-        return g.render('departments.xhtml', paginator=paginator,
-            page_num=page_num,
-            count=count)
+        queryset = models.Department.objects.filter(active=True)
+        template = 'departments.xhtml'
     elif browse_option == 'courses':
         # fixme, course filter should not be (active=True) but based on user identity.
-        paginator = Paginator(models.Course.objects.all(), count)
-
-        return g.render('courses.xhtml', paginator=paginator,
-            page_num=page_num,
-            count=count)
+        queryset = models.Course.objects.all()
+        template = 'courses.xhtml'
 
-    return g.render('browse_courses.xhtml')
+    paginator = queryset and Paginator(queryset, count) or None # index has no queryset.
+    return g.render(template, paginator=paginator,
+                    page_num=page_num,
+                    count=count)
 
 @login_required
 def my_courses(request):
diff --git a/conifer/templates/browse_courses.xhtml b/conifer/templates/browse_courses.xhtml
deleted file mode 100644 (file)
index 95d40c4..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?python
-title = _('Browse the Reserves')
-?>
-<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"/>
-<head>
-  <title>${title}</title>
-</head>
-<body>
-  <h1>${title}</h1> 
-  (Note: some course materials may require you
-    to <a href="/accounts/login/?next=/syrup/">log in</a>)
-    <h2>Choose from one of the options below:</h2>
-    <ul>
-        <li><a href="courses">Browse by Course Name</a></li>
-        <li><a 
-              href="instructors">Browse by Instructor</a></li>
-        <li><a  
-               href="departments">Browse by Department</a></li>
-    </ul>
-  <div class="gap"/>
-</body>
-</html>
diff --git a/conifer/templates/browse_index.xhtml b/conifer/templates/browse_index.xhtml
new file mode 100644 (file)
index 0000000..95d40c4
--- /dev/null
@@ -0,0 +1,25 @@
+<?python
+title = _('Browse the Reserves')
+?>
+<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"/>
+<head>
+  <title>${title}</title>
+</head>
+<body>
+  <h1>${title}</h1> 
+  (Note: some course materials may require you
+    to <a href="/accounts/login/?next=/syrup/">log in</a>)
+    <h2>Choose from one of the options below:</h2>
+    <ul>
+        <li><a href="courses">Browse by Course Name</a></li>
+        <li><a 
+              href="instructors">Browse by Instructor</a></li>
+        <li><a  
+               href="departments">Browse by Department</a></li>
+    </ul>
+  <div class="gap"/>
+</body>
+</html>