33
33
from subjecterror import SubjectError
36
35
from ivle.database import Subject, Offering, Semester
38
def get_subjects(login):
37
def get_subjects(config, login):
40
39
Looks up the student in whatever modules are available, using login.
41
40
If successful, returns a list of (subject, semester) pairs (both strings).
42
41
Raises a SubjectError if unsuccessful.
44
for modname, m in subj_modules:
43
for modname, m in get_pulldown_modules(config):
46
45
if result is not None:
50
def enrol_user(store, user, year=None):
49
def enrol_user(config, store, user, year=None):
52
51
Looks up the student in whatever modules are available.
53
52
The pulldown does not tell us what year to enrol the student for, so the
67
66
year = unicode(datetime.datetime.now().year)
70
for subject, semester in get_subjects(user.login):
69
for subject, semester in get_subjects(config, user.login):
71
70
offering = store.find(Offering,
72
71
Subject.code == subject,
73
72
Offering.subject_id == Subject.id,
86
# Allow imports to get files from this directory.
87
# Get the directory that this module (authenticate) is in
88
plugpath = os.path.split(sys.modules[__name__].__file__)[0]
90
sys.path.append(plugpath)
92
# Create a global variable "subj_modules", a list of (name, function object)s.
93
# This list consists of null_subj, plus the "get_subject" functions of all the
94
# plugin subject pulldown modules.
97
for modname in ivle.conf.subject_pulldown_modules.split(','):
99
mod = __import__(modname)
101
raise SubjectError("Internal error: "
102
"Can't import subject pulldown module %s"
105
# If auth_modules is "", we may get an empty string - ignore
108
subjfunc = mod.get_subjects
109
except AttributeError:
110
raise SubjectError("Internal error: Subject pulldown module %r has no "
111
"'get_subjects' function" % modname)
112
subj_modules.append((modname, subjfunc))
85
def get_pulldown_modules(config):
86
"""Get the subject pulldown modules defined in the configuration.
88
Returns a list of (name, function object)s. The list consists of
89
the "get_subject" functions of all the plugin subject pulldown modules.
93
# Allow imports to get files from this directory.
94
# Get the directory that this module (authenticate) is in
95
plugpath = os.path.split(sys.modules[__name__].__file__)[0]
97
sys.path.append(plugpath)
100
for modname in config['auth']['subject_pulldown_modules']:
102
mod = __import__(modname)
104
raise SubjectError("Internal error: "
105
"Can't import subject pulldown module %s"
108
# If auth_modules is "", we may get an empty string - ignore
111
subjfunc = mod.get_subjects
112
except AttributeError:
113
raise SubjectError("Internal error: Subject pulldown module %r has no "
114
"'get_subjects' function" % modname)
115
subj_modules.append((modname, subjfunc))
117
# Restore the old path, without this directory in it.