From f9a100b24c9838adc56503998209478b76b6f7b0 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Fri, 26 Feb 2010 02:58:37 +0000 Subject: [PATCH] Campus integration module now specified in local_settings; default is in 'conifer.integration'. I haven't changed any of the campus integration functions: I've just moved them from 'custom' into 'integration', joined them into a single module, and given an example of how to extend the default (null) integration. It's a start. Library integration will be similar, but bitchier. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/branches/2010-02-campus-integration-reorg@801 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- .gitignore | 1 + conifer/custom/README | 4 ++ .../COURSE_CODES.txt} | 0 .../COURSE_SECTIONS.txt} | 0 conifer/integration/__init__.py | 0 conifer/integration/default.py | 18 ++++++ conifer/integration/example.py | 72 ++++++++++++++++++++++ conifer/local_settings.py.example | 5 ++ conifer/settings.py | 27 +++++--- conifer/syrup/models.py | 17 ++--- conifer/syrup/views/courses.py | 16 ++--- conifer/templates/edit_course_permissions.xhtml | 4 +- 12 files changed, 139 insertions(+), 25 deletions(-) create mode 100644 conifer/custom/README rename conifer/{custom/course_codes.py => integration/COURSE_CODES.txt} (100%) rename conifer/{custom/course_sections.py => integration/COURSE_SECTIONS.txt} (100%) create mode 100644 conifer/integration/__init__.py create mode 100644 conifer/integration/default.py create mode 100644 conifer/integration/example.py diff --git a/.gitignore b/.gitignore index 7b80a14..b634ce8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ PyZ3950_parsetab.py xsip TAGS private_local_settings.py +/conifer/.dired diff --git a/conifer/custom/README b/conifer/custom/README new file mode 100644 index 0000000..a80b2b0 --- /dev/null +++ b/conifer/custom/README @@ -0,0 +1,4 @@ +This directory is going away. + +Default integrations are being moved to 'conifer.integration'. The +active integration modules are to be specified in local_settings. diff --git a/conifer/custom/course_codes.py b/conifer/integration/COURSE_CODES.txt similarity index 100% rename from conifer/custom/course_codes.py rename to conifer/integration/COURSE_CODES.txt diff --git a/conifer/custom/course_sections.py b/conifer/integration/COURSE_SECTIONS.txt similarity index 100% rename from conifer/custom/course_sections.py rename to conifer/integration/COURSE_SECTIONS.txt diff --git a/conifer/integration/__init__.py b/conifer/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/conifer/integration/default.py b/conifer/integration/default.py new file mode 100644 index 0000000..b553b28 --- /dev/null +++ b/conifer/integration/default.py @@ -0,0 +1,18 @@ +# Do not edit this file: make your own, instead. + +# See COURSE_CODES.txt for information. + +course_code_is_valid = None +course_code_example = None +course_code_list = None +course_code_lookup_title = None +course_code_cross_listings = None + +# See COURSE_SECTIONS.txt for information. + +sections_tuple_delimiter = None +sections_taught_by = None +students_in = None +instructors_in = None +sections_for_code_and_term = None + diff --git a/conifer/integration/example.py b/conifer/integration/example.py new file mode 100644 index 0000000..2426949 --- /dev/null +++ b/conifer/integration/example.py @@ -0,0 +1,72 @@ +from default import * + +#---------------------------------------------------------------------- +# Course Codes + +_codes = [('ART99-100', 'Art History'), + ('BIOL55-350', 'Molecular Cell Biology'), + ('CRIM48-567', 'Current Issues in Criminology'), + ('ENGL26-280', 'Contemporary Literary Theory'), + ('ENGL26-420', 'Word and Image: The Contemporary Graphic Novel'), + ('SOCWK47-457', 'Advanced Social Work Research'),] + +_crosslists = set(['ENGL26-280', 'ENGL26-420']) + + +course_code_is_valid = None + +course_code_example = 'BIOL55-350; SOCWK47-457' + +def course_code_list(): + return [a for (a,b) in _codes] + +def course_code_lookup_title(course_code): + return dict(_codes).get(course_code) + +def course_code_cross_listings(course_code): + if course_code in _crosslists: + return list(_crosslists - set([course_code])) + + +#---------------------------------------------------------------------- +# Course Sections + +sections_tuple_delimiter = '|' + +# For any of the students to actually appear in a course site, they +# must also exist as Django users (or be in an authentication backend +# that supports 'maybe_initialize_user'; see auth_evergreen.py). + +_db = [ + #(instructor, (term, code, sec-code), 'student1 student2 ... studentN'), + ('fred', ('2009W', 'ENG203', '1'), 'jim joe jack ellen ed'), + ('fred', ('2009W', 'ENG327', '1'), 'ed paul bill'), + ('art', ('2009W', 'LIB201', '1'), 'graham bill ed'), + ('graham', ('2009S', 'ART108', '1'), 'alan june jack'), + ('graham', ('2009S', 'ART108', '2'), 'emmet'), + ('graham', ('2009S', 'ART108', '3'), 'freda hugo bill'), +] + +def sections_taught_by(username): + return set([s[1] for s in _db if s[0] == username]) + +def students_in(*sections): + def inner(): + for instr, sec, studs in _db: + if sec in sections: + for s in studs.split(' '): + yield s + return set(inner()) + +def instructors_in(*sections): + def inner(): + for instr, sec, studs in _db: + if sec in sections: + yield instr + return set(inner()) + +def sections_for_code_and_term(code, term): + return [(t, c, s) for (instr, (t, c, s), ss) in _db \ + if c == code and t == term] + + diff --git a/conifer/local_settings.py.example b/conifer/local_settings.py.example index dafbae6..659612b 100644 --- a/conifer/local_settings.py.example +++ b/conifer/local_settings.py.example @@ -34,6 +34,11 @@ SECRET_KEY = 'replace-with-your-own-super-random-key-@vv(tuvt2+yu2r-$dxs$s7=iqjz EVERGREEN_AUTHENTICATION = False #---------------------------------------------------------------------- +#Campus integration + +CAMPUS_INTEGRATION_MODULE = 'conifer.integration.default' + +#---------------------------------------------------------------------- # Stuff that probably belongs in a config table in the database, with # a nice UI to maintain it all. diff --git a/conifer/settings.py b/conifer/settings.py index 51cf117..39f68ea 100644 --- a/conifer/settings.py +++ b/conifer/settings.py @@ -8,11 +8,7 @@ sys.path.append(HERE('..')) DEBUG = False -ADMINS = ( - # ('Your Name', 'your_email@domain.com'), -) - -MANAGERS = ADMINS +ADMINS = [] DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = '' # Or path to database file if using sqlite3. @@ -97,6 +93,8 @@ AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend' ] +CAMPUS_INTEGRATION_MODULE = 'conifer.integration.default' + #--------------------------------------------------------------------------- # local_settings.py @@ -115,9 +113,22 @@ except: # Further settings that depend upon local_settings. TEMPLATE_DEBUG = DEBUG +MANAGERS = ADMINS + +#---------- if EVERGREEN_AUTHENTICATION: - AUTHENTICATION_BACKENDS.extend( - ['conifer.custom.auth_evergreen.EvergreenAuthBackend', - ]) + AUTHENTICATION_BACKENDS.append( + 'conifer.custom.auth_evergreen.EvergreenAuthBackend') + +#---------- + +try: + exec 'import %s as CAMPUS_INTEGRATION' % CAMPUS_INTEGRATION_MODULE +except: + raise Exception('There is an error in your campus integration module (%s)! ' + 'Please investigate and repair.' % CAMPUS_INTEGRATION_MODULE, + sys.exc_value) + +#---------- diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 03a3ea1..5bfd74c 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -5,14 +5,17 @@ from django.contrib.auth import get_backends from datetime import datetime from genshi import Markup from django.utils.translation import ugettext as _ -from conifer.custom import course_codes # fixme, not sure if conifer.custom is a good parent. -from conifer.custom import course_sections # fixme, not sure if conifer.custom is a good parent. -from conifer.custom import lib_integration import re import random from django.utils import simplejson from conifer.middleware import genshi_locals +# campus and library integration +from django.conf import settings +campus = settings.CAMPUS_INTEGRATION +from conifer.custom import lib_integration # fixme, not sure if conifer.custom is a good parent. + + def highlight(text, phrase, highlighter='\\1'): ''' This may be a lame way to do this, but will want to highlight matches somehow @@ -262,7 +265,7 @@ class Course(m.Model): break def sections(self): - delim = course_sections.sections_tuple_delimiter + delim = campus.sections_tuple_delimiter if not delim: return [] else: @@ -302,16 +305,16 @@ class Course(m.Model): def _merge_sections(secs): - delim = course_sections.sections_tuple_delimiter + delim = campus.sections_tuple_delimiter return delim.join(delim.join(sec) for sec in secs) def section_decode_safe(secstring): if not secstring: return None - return tuple(secstring.decode('base64').split(course_sections.sections_tuple_delimiter)) + return tuple(secstring.decode('base64').split(campus.sections_tuple_delimiter)) def section_encode_safe(section): - return course_sections.sections_tuple_delimiter.join(section).encode('base64').strip() + return campus.sections_tuple_delimiter.join(section).encode('base64').strip() class Member(m.Model): class Meta: diff --git a/conifer/syrup/views/courses.py b/conifer/syrup/views/courses.py index 8a778ce..e0bc9a7 100644 --- a/conifer/syrup/views/courses.py +++ b/conifer/syrup/views/courses.py @@ -12,7 +12,7 @@ class NewCourseForm(ModelForm): def clean_code(self): v = (self.cleaned_data.get('code') or '').strip() - is_valid_func = models.course_codes.course_code_is_valid + is_valid_func = models.campus.course_code_is_valid if (not is_valid_func) or is_valid_func(v): return v else: @@ -20,12 +20,12 @@ class NewCourseForm(ModelForm): # if we have course-code lookup, hack lookup support into the new-course form. -COURSE_CODE_LIST = bool(models.course_codes.course_code_list) -COURSE_CODE_LOOKUP_TITLE = bool(models.course_codes.course_code_lookup_title) +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.course_codes.course_code_list() + course_list = models.campus.course_code_list() choices = [(a,a) for a in course_list] choices.sort() empty_label = u'---------' @@ -52,7 +52,7 @@ def _add_or_edit_course(request, instance=None): if is_add: instance = models.Course() current_access_level = not is_add and instance.access or None - example = models.course_codes.course_code_example + example = models.campus.course_code_example if request.method != 'POST': form = NewCourseForm(instance=instance) return g.render('edit_course.xhtml', **locals()) @@ -81,7 +81,7 @@ def _add_or_edit_course(request, instance=None): # no access-control needed to protect title lookup. def add_new_course_ajax_title(request): course_code = request.GET['course_code'] - title = models.course_codes.course_code_lookup_title(course_code) + title = models.campus.course_code_lookup_title(course_code) return HttpResponse(simplejson.dumps({'title':title})) @instructors_only @@ -96,7 +96,7 @@ def edit_course_permissions(request, course_id): (u'STUDT', _(u'Students in my course -- I will provide section numbers')), (u'INVIT', _(u'Students in my course -- I will share an Invitation Code with them')), (u'LOGIN', _(u'All Reserves patrons'))] - if models.course_sections.sections_tuple_delimiter is None: + if models.campus.sections_tuple_delimiter is None: # no course-sections support? Then STUDT cannot be an option. del choices[1] choose_access = django.forms.Select(choices=choices) @@ -172,7 +172,7 @@ def edit_course_permissions(request, course_id): for name in POST \ if name.startswith('remove_section_')] course.drop_sections(*to_remove) - student_names = models.course_sections.students_in(*course.sections()) + student_names = models.campus.students_in(*course.sections()) for name in student_names: user = models.maybe_initialize_user(name) if user: diff --git a/conifer/templates/edit_course_permissions.xhtml b/conifer/templates/edit_course_permissions.xhtml index e8adbe2..98510a8 100644 --- a/conifer/templates/edit_course_permissions.xhtml +++ b/conifer/templates/edit_course_permissions.xhtml @@ -66,8 +66,8 @@ instructors = [m for m in models.Member.objects.filter(course=course) if m.role

Course section numbers

-- 2.11.0