From: gfawcett
Date: Thu, 14 Apr 2011 02:20:00 +0000 (+0000)
Subject: Browse and My Reserves now sport a "timeframe" widget
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1a74bfa3334093825f10e83dde35f72022a2a7e1;p=Syrup.git
Browse and My Reserves now sport a "timeframe" widget
You can use it to specify whether you want to look at current courses, past
ones, or future ones. For past and future, there are options to show just
nearby past/future courses, or all past/future courses.
The setting is sticky to your login session.
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1357 6d9bc8c9-1ec2-4278-b937-99fde70a366f
---
diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py
index 0c83aa5..403e00a 100644
--- a/conifer/syrup/models.py
+++ b/conifer/syrup/models.py
@@ -5,7 +5,7 @@ from collections import defaultdict
from conifer.libsystems import marcxml as MX
from conifer.plumbing.genshi_support import get_request
from conifer.plumbing.hooksystem import *
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, date
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.db import models as m
@@ -177,7 +177,31 @@ class Term(BaseModel):
def midpoint(self):
return self.start + (self.finish-self.start) / 2
-
+ @classmethod
+ def timeframe_query(cls, N=0, extent=30):
+ """
+ Returns three lists: a list of terms that recently ended, a list of
+ terms that are active, and a list of terms that are upcoming soon.
+ """
+ N = int(N)
+ today = date.today()
+ delta = timedelta(days=extent)
+ before = today - delta
+ after = today + delta
+
+ if N == 0: # active
+ return Q(start_term__start__lte=today, end_term__finish__gte=today)
+ elif N == -1: # recently finished
+ return Q(end_term__finish__lt=today, end_term__finish__gte=before)
+ elif N == -2: # all past courses
+ return Q(end_term__finish__lt=today)
+ elif N == 1: # starting soon
+ return Q(start_term__start__lte=after, start_term__start__gt=today)
+ elif N == 2: # all future courses
+ return Q(start_term__start__gt=today)
+ else:
+ raise Exception('unknown timeframe: %d' % N)
+
class Department(BaseModel):
name = m.CharField(max_length=256)
active = m.BooleanField(default=True)
diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py
index ae8cad9..d402cd7 100644
--- a/conifer/syrup/urls.py
+++ b/conifer/syrup/urls.py
@@ -11,6 +11,7 @@ urlpatterns = patterns('conifer.syrup.views',
(r'^site/$', 'my_sites'),
(r'^site/new/$', 'add_new_site'),
(r'^site/invitation/$', 'site_invitation'),
+ (r'^timeframe/$', 'timeframe'),
(r'^browse/$', 'browse'),
(r'^browse/(?P.*)/$', 'browse'),
(r'^prefs/$', 'user_prefs'),
diff --git a/conifer/syrup/views/_common.py b/conifer/syrup/views/_common.py
index 6fa8430..7f26453 100644
--- a/conifer/syrup/views/_common.py
+++ b/conifer/syrup/views/_common.py
@@ -17,6 +17,7 @@ g = TemplateSet(HERE('templates'), genshi_namespace)
import django.conf
import django.forms
+import itertools
import re
import sys
import warnings
diff --git a/conifer/syrup/views/general.py b/conifer/syrup/views/general.py
index a877567..925d11a 100644
--- a/conifer/syrup/views/general.py
+++ b/conifer/syrup/views/general.py
@@ -47,35 +47,10 @@ def user_prefs(request):
profile.save()
return HttpResponseRedirect('../')
-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 == '':
- queryset = None
- template = 'browse_index.xhtml'
- elif browse_option == 'instructors':
- queryset = models.User.active_instructors()
- # TODO: fixme, user_filters is no more.
- queryset = queryset.filter(user_filters(request.user)['instructors'])
- template = 'instructors.xhtml'
- elif browse_option == 'departments':
- queryset = models.Department.objects.filter(active=True)
- template = 'departments.xhtml'
- elif browse_option == 'courses':
- # TODO: fixme, course filter should not be (active=True) but based on user identity.
- # TODO: fixme, user_filters is no more.
- for_courses = user_filters(request.user)['courses']
- queryset = models.Site.objects.filter(for_courses)
- template = 'courses.xhtml'
-
- queryset = queryset and queryset.distinct()
- paginator = Paginator(queryset, count)
- return g.render(template, paginator=paginator,
- page_num=page_num,
- count=count)
-
+def timeframe(request):
+ tf = int(request.REQUEST.get('timeframe', '0'))
+ request.session['timeframe'] = tf
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER', '../'))
def instructor_detail(request, instructor_id):
page_num = int(request.GET.get('page', 1))
diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py
index d16d375..9edc595 100644
--- a/conifer/syrup/views/sites.py
+++ b/conifer/syrup/views/sites.py
@@ -171,7 +171,23 @@ def delete_site(request, site_id):
@login_required
def my_sites(request):
- return g.render('my_sites.xhtml')
+ timeframe = request.session.get('timeframe', 0)
+ time_query = models.Term.timeframe_query(timeframe)
+ return g.render('my_sites.xhtml', **locals())
+
+
+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))
+ 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)
+ return g.render('browse_index.xhtml', **locals())
+
#-----------------------------------------------------------------------------
# Site Invitation Code handler
diff --git a/conifer/templates/browse_index.xhtml b/conifer/templates/browse_index.xhtml
index 3820921..c71fabc 100644
--- a/conifer/templates/browse_index.xhtml
+++ b/conifer/templates/browse_index.xhtml
@@ -1,28 +1,31 @@
+
${title}
${title}
-
+ ${timeframe_nav(timeframe)}
+
(Note: some reserve materials may require you
to log in)
-
+
+
+ There are no reserves materials within the selected timeframe.
+
+
${dept}
diff --git a/conifer/templates/components/timeframe.xhtml b/conifer/templates/components/timeframe.xhtml
new file mode 100644
index 0000000..c32c282
--- /dev/null
+++ b/conifer/templates/components/timeframe.xhtml
@@ -0,0 +1,24 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/conifer/templates/my_sites.xhtml b/conifer/templates/my_sites.xhtml
index 0a1d3dd..727f79c 100644
--- a/conifer/templates/my_sites.xhtml
+++ b/conifer/templates/my_sites.xhtml
@@ -5,14 +5,16 @@ title = _('My Reserves')
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:py="http://genshi.edgewall.org/">
+
${title}
${title}
+ ${timeframe_nav(timeframe)}