[open-ils-commits] r941 - in servres/trunk/conifer: integration/linktool integration/linktool/templates static syrup templates (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 28 23:08:05 EDT 2010
Author: gfawcett
Date: 2010-07-28 23:08:02 -0400 (Wed, 28 Jul 2010)
New Revision: 941
Modified:
servres/trunk/conifer/integration/linktool/app.py
servres/trunk/conifer/integration/linktool/templates/associate.xhtml
servres/trunk/conifer/static/main.css
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/templates/tabbar.xhtml
Log:
more on linktool (sakai)
The darn model is trickier than I expected.
Modified: servres/trunk/conifer/integration/linktool/app.py
===================================================================
--- servres/trunk/conifer/integration/linktool/app.py 2010-07-29 03:06:19 UTC (rev 940)
+++ servres/trunk/conifer/integration/linktool/app.py 2010-07-29 03:08:02 UTC (rev 941)
@@ -42,38 +42,53 @@
possibles = list(models.Site.taught_by(user))
current = [s for s in possibles if s.term.midpoint() >= today]
ancient = [s for s in possibles if s.term.midpoint() < today]
+ extsite = ExternalSiteInfo(request)
return g.render('associate.xhtml', **locals())
else:
# TODO: implement me
return g.render('choose_dest.xhtml', **locals())
+class ExternalSiteInfo(object):
+ def __init__(self, request):
+ extsite = request.session['clew-site']
+ extgroups = callhook('external_memberships', request.user.username)
+ extsite = [d for d in extgroups if d['group'] == extsite][0]
+ self.__dict__.update(extsite)
+ self.termcode = self.terms and self.terms[0] or None
+ self.coursecode = extsite['course']
+ try:
+ course = models.Course.objects.get(code=self.coursecode)
+ except models.Course.DoesNotExist:
+ course = None
+ course = models.Course.objects.all()[0]
+ try:
+ term = models.Term.objects.get(code=self.termcode)
+ except models.Term.DoesNotExist:
+ term = None
+ term = models.Term.objects.order_by('-start')[0]
+ self.course_obj = course
+ self.term_obj = term
+ def is_currentish(self):
+ today = date.today()
+ return self.course_obj is not None and \
+ self.term_obj and self.term_obj.midpoint() >= today
+
def linktool_new_site(request):
- extsite = request.session['clew-site']
extrole = request.session['clew-role']
assert extrole == 'INSTR'
assert request.user.can_create_sites(), \
'Sorry, but you are not allowed to create sites.'
+ extsite = ExternalSiteInfo(request)
extgroups = callhook('external_memberships', request.user.username)
- extsite = [d for d in extgroups if d['group'] == extsite][0]
- coursecode = extsite['course']
- termcode = extsite['terms'][0]
- try:
- course = models.Course.objects.get(code=coursecode)
- term = models.Term.objects.get(code=termcode)
- except:
- # note, this doesn't have to be an exception. I could provide
- # them with a form to specify the correct course and term
- # codes. But for now, we bail.
- return g.render('new_site_cannot.xhtml', **locals())
site = models.Site.objects.create(
- course = course,
- term = term,
+ course = extsite.course_obj,
+ term = extsite.term_obj,
owner = request.user,
service_desk = models.ServiceDesk.default())
group = models.Group.objects.create(
site = site,
- external_id = extsite)
+ external_id = extsite.group)
models.Membership.objects.create(
group = group,
user = request.user,
@@ -89,12 +104,57 @@
today = date.today()
assert site.term.midpoint() >= today, \
'Sorry, but you cannot associate to such an old site.'
- return HttpResponse('associate: not implemented yet')
+ extsite = request.session['clew-site']
+ extrole = request.session['clew-role']
+ assert extrole == 'INSTR', \
+ 'Sorry, you are not an instructor on this Sakai site.'
+ group = models.Group.objects.create(
+ site = site,
+ external_id = extsite)
+ models.Membership.objects.create(
+ group = group,
+ user = request.user,
+ role = 'INSTR')
+ return HttpResponseRedirect(site.site_url())
+
def linktool_copy_old(request):
- site = models.Site.objects.get(pk=request.GET['site'])
- assert site in request.user.sites(role='INSTR'), \
+ oldsite = models.Site.objects.get(pk=request.GET['site'])
+ assert oldsite in request.user.sites(role='INSTR'), \
'Not an instructor on this site! Cannot copy.'
assert request.user.can_create_sites(), \
'Sorry, but you are not allowed to create sites.'
- return HttpResponse('copy old: not implemented yet')
+
+ extsite = request.session['clew-site']
+ extrole = request.session['clew-role']
+ assert extrole == 'INSTR', \
+ 'Sorry, you are not an instructor on this Sakai site.'
+
+ extgroups = callhook('external_memberships', request.user.username)
+ extsite = [d for d in extgroups if d['group'] == extsite][0]
+ coursecode = extsite['course']
+ termcode = extsite['terms'][0]
+
+ course = oldsite.course # fixme, this isn't right.
+ try:
+ #course = models.Course.objects.get(code=coursecode)
+ term = models.Term.objects.get(code=termcode)
+ except:
+ # note, this doesn't have to be an exception. I could provide
+ # them with a form to specify the correct course and term
+ # codes. But for now, we bail.
+ return g.render('new_site_cannot.xhtml', **locals())
+ site = models.Site.objects.create(
+ course = course,
+ term = term,
+ owner = request.user,
+ service_desk = models.ServiceDesk.default())
+ group = models.Group.objects.create(
+ site = site,
+ external_id = extsite)
+ models.Membership.objects.create(
+ group = group,
+ user = request.user,
+ role = 'INSTR')
+ site.copy_resources_from(oldsite)
+ return HttpResponseRedirect(site.site_url())
Modified: servres/trunk/conifer/integration/linktool/templates/associate.xhtml
===================================================================
--- servres/trunk/conifer/integration/linktool/templates/associate.xhtml 2010-07-29 03:06:19 UTC (rev 940)
+++ servres/trunk/conifer/integration/linktool/templates/associate.xhtml 2010-07-29 03:08:02 UTC (rev 941)
@@ -4,37 +4,50 @@
<xi:include href="linktoolmaster.xhtml"/>
<head>
<style type="text/css">
- li { margin-top: 0.5em; }
+ ol ul { margin-bottom: 1.5em; }
+ ul li { margin-top: 0.5em; }
+ ol { margin: 1em; }
</style>
</head>
<body>
- <h1>No associated reserves list.</h1>
- <p>There is currently no set of reserves materials associated with
- this site. As an instructor in this site, you can choose one of
- the following options:</p>
- <ol>
- <li>
- <div><b>Link to one of my current reserves list</b></div>
- <ul>
- <li py:if="not current">None available</li>
- <li py:for="site in current">
- <a href="associate?site=${site.id}">${site}</a>
- </li>
- </ul>
- </li>
- <li>
- <div><b>Copy a reserves list I've used in the past</b></div>
- <ul>
- <li py:if="not ancient">None available</li>
- <li py:for="site in ancient">
- <a href="copy_old?site=${site.id}">${site}</a>
- </li>
- </ul>
- </li>
- <li>
- <div><b><a href="new_site">Create a new reserves list for this site</a></b></div>
- </li>
- </ol>
-
+ <h1>No associated reserves items.</h1>
+ <div py:if="extsite.is_currentish()">
+ <p>There are no reserves materials associated with this course
+ site. As an instructor, you can choose one of the following
+ options:</p>
+ <ol>
+ <li>
+ <div><b>Link to one of my current reserves list</b></div>
+ <ul>
+ <li py:if="not current">None available.</li>
+ <li py:for="site in current">
+ <a href="associate?site=${site.id}">${site}</a>
+ </li>
+ </ul>
+ </li>
+ <li>
+ <div><b>Copy a reserves list I've used in the past</b></div>
+ <ul>
+ <li py:if="not ancient">None available.</li>
+ <li py:for="site in ancient">
+ <a href="copy_old?site=${site.id}">${site}</a>
+ </li>
+ </ul>
+ </li>
+ <li>
+ <div><b><a href="new_site">Start a new reserves list for this site</a></b></div>
+ </li>
+ </ol>
+ <p>Or, you can just <a href="${ROOT}/browse/">browse the reserves</a>.</p>
+ </div>
+ <div py:if="not extsite.is_currentish()"
+ py:with="t=extsite.term_obj or 'unknown'; c=extsite.coursecode or 'unknown'">
+ <p>There are no reserves materials associated with this course
+ site.</p> <p>You can create reserves lists for course sites
+ associated with a current or future term. But this site is
+ associated with the term "${t}" and the course "${c}" — so
+ a reserves list cannot be created.</p>
+ <p><a href="${ROOT}/browse/">Browse the reserves</a></p>
+ </div>
</body>
</html>
Modified: servres/trunk/conifer/static/main.css
===================================================================
--- servres/trunk/conifer/static/main.css 2010-07-29 03:06:19 UTC (rev 940)
+++ servres/trunk/conifer/static/main.css 2010-07-29 03:08:02 UTC (rev 941)
@@ -128,6 +128,8 @@
#tabbar li { display: inline; margin: 0; }
#tabbar li a { padding: 15px 18px 5px 18px; background-color: #ddf; color: black; text-decoration: none; }
#tabbar li a:hover { background-color: #fc8; }
+#tabbar li.important a { background-color: #fc8; }
+#tabbar li.important a:hover { background-color: #fa6; }
/*
#tabbar li.active a { background-color: #fa6; font-weight: bold; }
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2010-07-29 03:06:19 UTC (rev 940)
+++ servres/trunk/conifer/syrup/models.py 2010-07-29 03:08:02 UTC (rev 941)
@@ -144,6 +144,7 @@
def midpoint(self):
return self.start + (self.finish-self.start) / 2
+
class Department(BaseModel):
name = m.CharField(max_length=256)
active = m.BooleanField(default=True)
@@ -342,7 +343,8 @@
def taught_by(cls, user):
"""Return a set of Sites for which this user is an Instructor."""
return cls.objects.filter(group__membership__user=user,
- group__membership__role='INSTR')
+ group__membership__role='INSTR') \
+ .distinct().select_related()
#--------------------------------------------------
Modified: servres/trunk/conifer/templates/tabbar.xhtml
===================================================================
--- servres/trunk/conifer/templates/tabbar.xhtml 2010-07-29 03:06:19 UTC (rev 940)
+++ servres/trunk/conifer/templates/tabbar.xhtml 2010-07-29 03:08:02 UTC (rev 941)
@@ -7,12 +7,12 @@
use one for now
-->
<ul id="tabbar">
- <li py:if="'clew-site' in request.session">
+ <li py:if="'clew-site' in request.session" class="important">
<a href="https://clew.uwindsor.ca/xsl-portal/site/${request.session['clew-site']}/page/0/">Return to CLEW</a>
</li>
<!-- !<li><a href="${ROOT}/">Home</a></li> -->
+ <li class="active"><a href="${ROOT}/site/">My Reserves</a></li>
<li><a href="${ROOT}/browse/">Browse</a></li>
- <li class="active"><a href="${ROOT}/site/">My Reserves</a></li>
<div py:strip="True"
py:if="request.user.is_staff">
<li><a href="${ROOT}/admin/">Admin Options</a></li>
More information about the open-ils-commits
mailing list