from conifer.integration._hooksystem import *
+from datetime import date
#----------------------------------------------------------------------
# Your hooks go here.
('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)),
+ ]
(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'),
from _common import *
from django.utils.translation import ugettext as _
from conifer.integration._hooksystem import *
+from datetime import date
#-----------------------------------------------------------------------------
# Administrative options
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.', '')
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
#--------------------
<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>