[open-ils-commits] r915 - in servres/trunk/conifer: . integration syrup syrup/views templates/admin (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jul 14 20:55:00 EDT 2010


Author: gfawcett
Date: 2010-07-14 20:54:58 -0400 (Wed, 14 Jul 2010)
New Revision: 915

Modified:
   servres/trunk/conifer/genshi_namespace.py
   servres/trunk/conifer/integration/hooks.py
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views/admin.py
   servres/trunk/conifer/templates/admin/index.xhtml
Log:
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.

Modified: servres/trunk/conifer/genshi_namespace.py
===================================================================
--- servres/trunk/conifer/genshi_namespace.py	2010-07-15 00:54:53 UTC (rev 914)
+++ servres/trunk/conifer/genshi_namespace.py	2010-07-15 00:54:58 UTC (rev 915)
@@ -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

Modified: servres/trunk/conifer/integration/hooks.py
===================================================================
--- servres/trunk/conifer/integration/hooks.py	2010-07-15 00:54:53 UTC (rev 914)
+++ servres/trunk/conifer/integration/hooks.py	2010-07-15 00:54:58 UTC (rev 915)
@@ -6,3 +6,23 @@
 # @hook
 # def can_create_sites(user):
 #     ...
+
+#TODO: this is for testing purposes only! Remove.
+
+ at 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'),
+        ]

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2010-07-15 00:54:53 UTC (rev 914)
+++ servres/trunk/conifer/syrup/urls.py	2010-07-15 00:54:58 UTC (rev 915)
@@ -49,6 +49,7 @@
     (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'),

Modified: servres/trunk/conifer/syrup/views/admin.py
===================================================================
--- servres/trunk/conifer/syrup/views/admin.py	2010-07-15 00:54:53 UTC (rev 914)
+++ servres/trunk/conifer/syrup/views/admin.py	2010-07-15 00:54:58 UTC (rev 915)
@@ -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 @@
     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.

Modified: servres/trunk/conifer/templates/admin/index.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/index.xhtml	2010-07-15 00:54:53 UTC (rev 914)
+++ servres/trunk/conifer/templates/admin/index.xhtml	2010-07-15 00:54:58 UTC (rev 915)
@@ -26,6 +26,11 @@
   <ul>
     <li><a href="../djadmin/">Django Administrative UI</a></li>
   </ul>
+  <ul>
+    <li py:if="gethook('department_course_catalogue')">
+      <a href="update_depts_courses">Automatically update departments and courses</a>
+    </li>
+  </ul>
   </div>
 </body>
 </html>



More information about the open-ils-commits mailing list