[open-ils-commits] r916 - 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:07 EDT 2010
Author: gfawcett
Date: 2010-07-14 20:55:06 -0400 (Wed, 14 Jul 2010)
New Revision: 916
Modified:
servres/trunk/conifer/integration/hooks.py
servres/trunk/conifer/syrup/urls.py
servres/trunk/conifer/syrup/views/admin.py
servres/trunk/conifer/syrup/views/sites.py
servres/trunk/conifer/templates/admin/index.xhtml
Log:
admin: refresh terms from external system.
Modified: servres/trunk/conifer/integration/hooks.py
===================================================================
--- servres/trunk/conifer/integration/hooks.py 2010-07-15 00:54:58 UTC (rev 915)
+++ servres/trunk/conifer/integration/hooks.py 2010-07-15 00:55:06 UTC (rev 916)
@@ -1,4 +1,5 @@
from conifer.integration._hooksystem import *
+from datetime import date
#----------------------------------------------------------------------
# Your hooks go here.
@@ -26,3 +27,16 @@
('Social Work','02-47-370','Mothering and Motherhood'),
('Social Work','02-47-456','Social Work and Health'),
]
+
+ at 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)),
+ ]
Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py 2010-07-15 00:54:58 UTC (rev 915)
+++ servres/trunk/conifer/syrup/urls.py 2010-07-15 00:55:06 UTC (rev 916)
@@ -50,6 +50,7 @@
(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'),
Modified: servres/trunk/conifer/syrup/views/admin.py
===================================================================
--- servres/trunk/conifer/syrup/views/admin.py 2010-07-15 00:54:58 UTC (rev 915)
+++ servres/trunk/conifer/syrup/views/admin.py 2010-07-15 00:55:06 UTC (rev 916)
@@ -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 @@
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.', '')
Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:54:58 UTC (rev 915)
+++ servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:55:06 UTC (rev 916)
@@ -23,16 +23,16 @@
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
#--------------------
Modified: servres/trunk/conifer/templates/admin/index.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/index.xhtml 2010-07-15 00:54:58 UTC (rev 915)
+++ servres/trunk/conifer/templates/admin/index.xhtml 2010-07-15 00:55:06 UTC (rev 916)
@@ -30,6 +30,9 @@
<li py:if="gethook('department_course_catalogue')">
<a href="update_depts_courses">Automatically update departments and courses</a>
</li>
+ <li py:if="gethook('term_catalogue')">
+ <a href="update_terms">Automatically update terms</a>
+ </li>
</ul>
</div>
</body>
More information about the open-ils-commits
mailing list