From c501651d4ecb5b8a0485c6a6f8b4fcec6a203b04 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 15 Jul 2010 00:55:06 +0000 Subject: [PATCH] admin: refresh terms from external system. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@916 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/integration/hooks.py | 14 ++++++++++++++ conifer/syrup/urls.py | 1 + conifer/syrup/views/admin.py | 28 ++++++++++++++++++++++++---- conifer/syrup/views/sites.py | 20 ++++++++++---------- conifer/templates/admin/index.xhtml | 3 +++ 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/conifer/integration/hooks.py b/conifer/integration/hooks.py index f228c3b..4ab4fe5 100644 --- a/conifer/integration/hooks.py +++ b/conifer/integration/hooks.py @@ -1,4 +1,5 @@ from conifer.integration._hooksystem import * +from datetime import date #---------------------------------------------------------------------- # Your hooks go here. @@ -26,3 +27,16 @@ def department_course_catalogue(): ('Social Work','02-47-370','Mothering and Motherhood'), ('Social Work','02-47-456','Social Work and Health'), ] + +@hook +def term_catalogue(): + """ + Return a list of rows representing all known terms. Each row + should be a tuple in the form: ('term-code', 'term-name', + 'start-date', 'end-date'), where the dates are instances of the + datetime.date class. + """ + return [ + ('2011S', '2011 Summer', date(2011,5,1), date(2011,9,1)), + ('2011F', '2011 Fall', date(2011,9,1), date(2011,12,31)), + ] diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index f8737bf..afb2501 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -50,6 +50,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^admin/config/' + GENERIC_REGEX, 'admin_configs'), (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'), (r'^admin/update_depts_courses/$', 'admin_update_depts_courses'), + (r'^admin/update_terms/$', 'admin_update_terms'), (r'^phys/$', 'phys_index'), (r'^phys/checkout/$', 'phys_checkout'), diff --git a/conifer/syrup/views/admin.py b/conifer/syrup/views/admin.py index 2b27022..cea88ce 100644 --- a/conifer/syrup/views/admin.py +++ b/conifer/syrup/views/admin.py @@ -1,6 +1,7 @@ from _common import * from django.utils.translation import ugettext as _ from conifer.integration._hooksystem import * +from datetime import date #----------------------------------------------------------------------------- # Administrative options @@ -120,14 +121,33 @@ def admin_update_depts_courses(request): desk = models.ServiceDesk.objects.get(pk=defaultdesk) if catalogue is None: - return HttpResponse('Sorry, cannot perform this operation at this time: ' - 'hook %r not found.' % HOOKNAME) + return HttpResponse( + 'Sorry, cannot perform this operation at this time: ' + 'hook %r not found.' % HOOKNAME) else: for deptname, ccode, cname in catalogue: if not (deptname.strip() and ccode.strip() and cname.strip()): continue dept, x = models.Department.objects.get_or_create( name=deptname, service_desk=desk) - course, x = models.Course.objects.get_or_create( + models.Course.objects.get_or_create( department=dept, name=cname, code=ccode) - return HttpResponse('Updated.') # TODO: make a nice confirmation message. + return simple_message('Courses and departments updated.', '') + +def admin_update_terms(request): + HOOKNAME = 'term_catalogue' + catalogue = callhook(HOOKNAME) + if catalogue is None: + return HttpResponse( + 'Sorry, cannot perform this operation at this time: ' + 'hook %r not found.' % HOOKNAME) + else: + for tcode, tname, start, finish in catalogue: + tcode = tcode.strip(); tname = tname.strip() + if not (tcode and tname and isinstance(start, date) \ + and isinstance(finish, date)): + raise Exception(('bad-row', tcode, tname, start, finish)) + models.Term.objects.get_or_create( + code = tcode, + defaults = dict(name=tname, start=start, finish=finish)) + return simple_message('Terms updated.', '') diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index ea8c1c6..4489f10 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -23,16 +23,16 @@ class NewSiteForm(ModelForm): COURSE_CODE_LIST = bool(models.campus.course_code_list) COURSE_CODE_LOOKUP_TITLE = bool(models.campus.course_code_lookup_title) -if COURSE_CODE_LIST: - from django.forms import Select - course_list = models.campus.course_code_list() - choices = [(a,a) for a in course_list] - choices.sort() - empty_label = u'---------' - choices.insert(0, ('', empty_label)) - NewSiteForm.base_fields['code'].widget = Select( - choices = choices) - NewSiteForm.base_fields['code'].empty_label = empty_label +# if COURSE_CODE_LIST: +# from django.forms import Select +# course_list = models.campus.course_code_list() +# choices = [(a,a) for a in course_list] +# choices.sort() +# empty_label = u'---------' +# choices.insert(0, ('', empty_label)) +# NewSiteForm.base_fields['code'].widget = Select( +# choices = choices) +# NewSiteForm.base_fields['code'].empty_label = empty_label #-------------------- diff --git a/conifer/templates/admin/index.xhtml b/conifer/templates/admin/index.xhtml index 9f963c6..e7547ec 100644 --- a/conifer/templates/admin/index.xhtml +++ b/conifer/templates/admin/index.xhtml @@ -30,6 +30,9 @@ title = _('Administrative Options')
  • Automatically update departments and courses
  • +
  • + Automatically update terms +
  • -- 2.11.0