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
36
def get_subjects(login):
38
Looks up the student in whatever modules are available, using login.
39
If successful, returns a list of (subject, semester) pairs (both strings).
40
Raises a SubjectError if unsuccessful.
42
for modname, m in subj_modules:
44
if result is not None:
48
def enrol_user(login, year=None):
50
Looks up the student in whatever modules are available.
51
The pulldown does not tell us what year to enrol the student for, so the
52
year may be specified (as a string). If unspecified, will enrol in the
53
current year according to the system clock.
54
If successful, enrols the student (in the database) in all subjects in the
55
system. Subjects which the pulldown tells us the student is in, but which
56
are not in the system are ignored.
57
Does not unenrol the student from any subjects.
58
Does not complain if the student is already enrolled in any subjects.
59
Raises a SubjectError if the pulldown module says so.
61
Returns the number of subjects the user was enrolled in (not including
62
subjects outside the system, or subjects already enrolled).
66
for subject, semester in get_subjects(login):
67
count += db.add_enrolment(login, subject, semester, year)
70
# Allow imports to get files from this directory.
71
# Get the directory that this module (authenticate) is in
72
plugpath = os.path.split(sys.modules[__name__].__file__)[0]
74
sys.path.append(plugpath)
76
# Create a global variable "subj_modules", a list of (name, function object)s.
77
# This list consists of null_subj, plus the "get_subject" functions of all the
78
# plugin subject pulldown modules.
81
for modname in conf.subject_pulldown_modules.split(','):
83
mod = __import__(modname)
85
raise SubjectError("Internal error: "
86
"Can't import subject pulldown module %s"
89
# If auth_modules is "", we may get an empty string - ignore
92
subjfunc = mod.get_subjects
93
except AttributeError:
94
raise SubjectError("Internal error: Subject pulldown module %r has no "
95
"'get_subjects' function" % modname)
96
subj_modules.append((modname, subjfunc))