[open-ils-commits] r1357 - in servres/trunk/conifer: syrup syrup/views templates templates/components (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 13 22:20:02 EDT 2011
Author: gfawcett
Date: 2011-04-13 22:20:00 -0400 (Wed, 13 Apr 2011)
New Revision: 1357
Added:
servres/trunk/conifer/templates/components/timeframe.xhtml
Modified:
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/urls.py
servres/trunk/conifer/syrup/views/_common.py
servres/trunk/conifer/syrup/views/general.py
servres/trunk/conifer/syrup/views/sites.py
servres/trunk/conifer/templates/browse_index.xhtml
servres/trunk/conifer/templates/my_sites.xhtml
Log:
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.
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/syrup/models.py 2011-04-14 02:20:00 UTC (rev 1357)
@@ -5,7 +5,7 @@
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 @@
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)
Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/syrup/urls.py 2011-04-14 02:20:00 UTC (rev 1357)
@@ -11,6 +11,7 @@
(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_option>.*)/$', 'browse'),
(r'^prefs/$', 'user_prefs'),
Modified: servres/trunk/conifer/syrup/views/_common.py
===================================================================
--- servres/trunk/conifer/syrup/views/_common.py 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/syrup/views/_common.py 2011-04-14 02:20:00 UTC (rev 1357)
@@ -17,6 +17,7 @@
import django.conf
import django.forms
+import itertools
import re
import sys
import warnings
Modified: servres/trunk/conifer/syrup/views/general.py
===================================================================
--- servres/trunk/conifer/syrup/views/general.py 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/syrup/views/general.py 2011-04-14 02:20:00 UTC (rev 1357)
@@ -47,36 +47,11 @@
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))
+def timeframe(request):
+ tf = int(request.REQUEST.get('timeframe', '0'))
+ request.session['timeframe'] = tf
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER', '../'))
- 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 instructor_detail(request, instructor_id):
page_num = int(request.GET.get('page', 1))
count = int(request.GET.get('count', 5))
Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/syrup/views/sites.py 2011-04-14 02:20:00 UTC (rev 1357)
@@ -171,8 +171,24 @@
@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
Modified: servres/trunk/conifer/templates/browse_index.xhtml
===================================================================
--- servres/trunk/conifer/templates/browse_index.xhtml 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/templates/browse_index.xhtml 2011-04-14 02:20:00 UTC (rev 1357)
@@ -1,28 +1,31 @@
<?python
title = _('All Reserves, by Department')
-
-sites = models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name').select_related()
-blocks = itertools.groupby(sites, lambda s: s.course.department)
?>
<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/timeframe.xhtml"/>
<head>
<title>${title}</title>
</head>
<body>
<h1>${title}</h1>
- <div py:if="user.is_anonymous()">
+ ${timeframe_nav(timeframe)}
+ <p py:if="user.is_anonymous() and sites">
(Note: some reserve materials may require you
to <a href="${ROOT}${settings.LOGIN_URL}?next=${ROOT}/">log in</a>)
- </div>
+ </p>
<img py:def="lock(condition=True)"
py:if="condition"
src="${ROOT}/static/tango/lock.png"
alt="lock" title="This resource is access-controlled."/>
+ <p py:if="not sites">
+ There are no reserves materials within the selected timeframe.
+ </p>
+
<div py:for="(dept, ss) in blocks">
<h2>${dept}</h2>
<div py:for="site in ss">
Added: servres/trunk/conifer/templates/components/timeframe.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/timeframe.xhtml (rev 0)
+++ servres/trunk/conifer/templates/components/timeframe.xhtml 2011-04-14 02:20:00 UTC (rev 1357)
@@ -0,0 +1,24 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ py:strip="">
+
+ <form py:def="timeframe_nav(timeframe)"
+ action="${ROOT}/timeframe/" method="post" id="timeframe">
+ <select name="timeframe" style="font-size: 115%;">
+ <option py:def="opt(n,title,bold=False)" value="${n}"
+ py:attrs="{'style':'font-weight:bold;' if bold else '', 'selected':'selected' if n==timeframe else None}">
+ ${title}
+ </option>
+ ${opt(-2, _('Past courses'))}
+ ${opt(-1, _('Recently finished'))}
+ ${opt( 0, _('Active courses'), True)}
+ ${opt( 1, _('Starting soon'))}
+ ${opt( 2, _('Future courses'))}
+ </select>
+ <script>
+ $(function() { $('#timeframe select').change(function () { $('#timeframe')[0].submit(); }); });
+ </script>
+ </form>
+
+</html>
\ No newline at end of file
Modified: servres/trunk/conifer/templates/my_sites.xhtml
===================================================================
--- servres/trunk/conifer/templates/my_sites.xhtml 2011-04-14 00:51:26 UTC (rev 1356)
+++ servres/trunk/conifer/templates/my_sites.xhtml 2011-04-14 02:20:00 UTC (rev 1357)
@@ -5,14 +5,16 @@
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:py="http://genshi.edgewall.org/">
<xi:include href="master.xhtml"/>
+<xi:include href="components/timeframe.xhtml"/>
<head>
<title>${title}</title>
</head>
<body>
<h1>${title}</h1>
+ ${timeframe_nav(timeframe)}
<?python
if user.is_authenticated():
- my_sites = user.sites()
+ my_sites = user.sites().filter(time_query)
else:
my_sites = []
?>
More information about the open-ils-commits
mailing list