1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Module: Subject Pulldown
22
# Pluggable subject pulldown module.
23
# Grabs a student's subject list from a source specified in conf.py.
25
# Each module should have a get_subjects(login) function, which takes login
26
# and returns a list of (subject, semester) pairs (both strings), or None
27
# if the user can't be found. May also raise a SubjectError which is fatal.
32
from subjecterror import SubjectError
35
def get_subjects(login):
37
Looks up the student in whatever modules are available, using login.
38
If successful, returns a list of (subject, semester) pairs (both strings).
39
Raises a SubjectError if unsuccessful.
41
for modname, m in subj_modules:
43
if result is not None:
47
# Allow imports to get files from this directory.
48
# Get the directory that this module (authenticate) is in
49
plugpath = os.path.split(sys.modules[__name__].__file__)[0]
51
sys.path.append(plugpath)
53
# Create a global variable "subj_modules", a list of (name, function object)s.
54
# This list consists of null_subj, plus the "get_subject" functions of all the
55
# plugin subject pulldown modules.
58
for modname in conf.subject_pulldown_modules.split(','):
60
mod = __import__(modname)
62
raise SubjectError("Internal error: "
63
"Can't import subject pulldown module %s"
66
# If auth_modules is "", we may get an empty string - ignore
69
subjfunc = mod.get_subjects
70
except AttributeError:
71
raise SubjectError("Internal error: Subject pulldown module %r has no "
72
"'get_subjects' function" % modname)
73
subj_modules.append((modname, subjfunc))