From d320763759a4e15582615e7d20a46f38cf370444 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 29 Jul 2010 03:08:02 +0000 Subject: [PATCH] more on linktool (sakai) The darn model is trickier than I expected. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@941 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/integration/linktool/app.py | 98 +++++++++++++++++----- .../integration/linktool/templates/associate.xhtml | 71 +++++++++------- conifer/static/main.css | 2 + conifer/syrup/models.py | 4 +- conifer/templates/tabbar.xhtml | 4 +- 5 files changed, 128 insertions(+), 51 deletions(-) diff --git a/conifer/integration/linktool/app.py b/conifer/integration/linktool/app.py index 05cb929..4619418 100644 --- a/conifer/integration/linktool/app.py +++ b/conifer/integration/linktool/app.py @@ -42,38 +42,53 @@ def linktool_welcome(request): 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 @@ def linktool_associate(request): 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()) diff --git a/conifer/integration/linktool/templates/associate.xhtml b/conifer/integration/linktool/templates/associate.xhtml index 3a04ac8..78917b2 100644 --- a/conifer/integration/linktool/templates/associate.xhtml +++ b/conifer/integration/linktool/templates/associate.xhtml @@ -4,37 +4,50 @@ -

No associated reserves list.

-

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:

-
    -
  1. -
    Link to one of my current reserves list
    - -
  2. -
  3. -
    Copy a reserves list I've used in the past
    - -
  4. -
  5. -
    Create a new reserves list for this site
    -
  6. -
- +

No associated reserves items.

+
+

There are no reserves materials associated with this course + site. As an instructor, you can choose one of the following + options:

+
    +
  1. +
    Link to one of my current reserves list
    +
      +
    • None available.
    • +
    • + ${site} +
    • +
    +
  2. +
  3. +
    Copy a reserves list I've used in the past
    +
      +
    • None available.
    • +
    • + ${site} +
    • +
    +
  4. +
  5. + +
  6. +
+

Or, you can just browse the reserves.

+
+
+

There are no reserves materials associated with this course + site.

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.

+

Browse the reserves

+
diff --git a/conifer/static/main.css b/conifer/static/main.css index 20c711e..baac96f 100644 --- a/conifer/static/main.css +++ b/conifer/static/main.css @@ -128,6 +128,8 @@ a:hover { text-decoration: underline; } #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; } diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 21a4e4c..07dbffa 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -144,6 +144,7 @@ class Term(BaseModel): 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 @@ class Site(BaseModel): 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() #-------------------------------------------------- diff --git a/conifer/templates/tabbar.xhtml b/conifer/templates/tabbar.xhtml index 2601e17..b33314d 100644 --- a/conifer/templates/tabbar.xhtml +++ b/conifer/templates/tabbar.xhtml @@ -7,12 +7,12 @@ use one for now -->