From: gfawcett Date: Thu, 15 Jul 2010 00:54:58 +0000 (+0000) Subject: admin: refresh dept/course list from external system X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f1b6a32649e001e0e91cb7f25fafd2ff97baf893;p=Syrup.git admin: refresh dept/course list from external system Right now I have a hardcoded list of externals, accessed using the 'hook' system. This needs to change of course. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@915 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/genshi_namespace.py b/conifer/genshi_namespace.py index ac9dedb..be91276 100644 --- a/conifer/genshi_namespace.py +++ b/conifer/genshi_namespace.py @@ -3,6 +3,7 @@ # Toplevel definitions in this module will be available in when # rendering a Genshi template. +from conifer.integration._hooksystem import gethook, callhook import itertools from itertools import cycle from conifer.syrup import models diff --git a/conifer/integration/hooks.py b/conifer/integration/hooks.py index 5444f34..f228c3b 100644 --- a/conifer/integration/hooks.py +++ b/conifer/integration/hooks.py @@ -6,3 +6,23 @@ from conifer.integration._hooksystem import * # @hook # def can_create_sites(user): # ... + +#TODO: this is for testing purposes only! Remove. + +@hook +def department_course_catalogue(): + """ + Return a list of rows representing all known, active courses and + the departments to which they belong. Each row should be a tuple + in the form: ('Department name', 'course-code', 'Course name'). + """ + return [ + ('Arts','01-01-209','Ethics in the Professions'), + ('Social Work','02-47-204','Issues & Perspectives in Social Welfare'), + ('Social Work','02-47-211','Prof Comm in Gen. Social Work Practice'), + ('Social Work','02-47-336','Theory and Practice Social Work I'), + ('Social Work','02-47-361','Field Practice I - A'), + ('Social Work','02-47-362','Field Practice I - B'), + ('Social Work','02-47-370','Mothering and Motherhood'), + ('Social Work','02-47-456','Social Work and Health'), + ] diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 8e17a4e..f8737bf 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -49,6 +49,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^admin/depts/' + GENERIC_REGEX, 'admin_depts'), (r'^admin/config/' + GENERIC_REGEX, 'admin_configs'), (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'), + (r'^admin/update_depts_courses/$', 'admin_update_depts_courses'), (r'^phys/$', 'phys_index'), (r'^phys/checkout/$', 'phys_checkout'), diff --git a/conifer/syrup/views/admin.py b/conifer/syrup/views/admin.py index fedd597..2b27022 100644 --- a/conifer/syrup/views/admin.py +++ b/conifer/syrup/views/admin.py @@ -1,5 +1,6 @@ from _common import * from django.utils.translation import ugettext as _ +from conifer.integration._hooksystem import * #----------------------------------------------------------------------------- # Administrative options @@ -109,3 +110,24 @@ class ConfigForm(ModelForm): clean_host = strip_and_nonblank('value') admin_configs = generic_handler(ConfigForm, decorator=admin_only) + +def admin_update_depts_courses(request): + HOOKNAME = 'department_course_catalogue' + catalogue = callhook(HOOKNAME) + + # we can only assign them to the default service desk. + defaultdesk = models.Config.get('default.desk', 1, int) + 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) + 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( + department=dept, name=cname, code=ccode) + return HttpResponse('Updated.') # TODO: make a nice confirmation message. diff --git a/conifer/templates/admin/index.xhtml b/conifer/templates/admin/index.xhtml index 3799d5d..9f963c6 100644 --- a/conifer/templates/admin/index.xhtml +++ b/conifer/templates/admin/index.xhtml @@ -26,6 +26,11 @@ title = _('Administrative Options') +