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,
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())
<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>