149
149
req.write("""<p>Welcome to the IVLE tutorial system.
150
150
Please select a subject from the list below to select a worksheet
151
151
for that subject.</p>\n""")
152
153
# Get list of subjects
153
# TODO: Fetch from DB. For now, just get directory listing
154
subjects = os.listdir(conf.subjects_base)
156
enrolled_subjects = db.get_enrolment(req.user.login)
157
all_subjects = db.get_subjects()
161
enrolled_set = set(x['subj_code'] for x in enrolled_subjects)
162
unenrolled_subjects = [x for x in all_subjects
163
if x['subj_code'] not in enrolled_set]
164
enrolled_subjects.sort(key=lambda x: x['subj_code'])
165
unenrolled_subjects.sort(key=lambda x: x['subj_code'])
167
def print_subject(subject):
168
req.write(' <li><a href="%s">%s</a></li>\n'
169
% (urllib.quote(subject['subj_code']) + '/',
170
cgi.escape(subject['subj_name'])))
156
172
req.write("<h2>Subjects</h2>\n<ul>\n")
157
for subject in subjects:
158
req.write(' <li><a href="%s">%s</a></li>\n'
159
% (urllib.quote(subject) + '/', cgi.escape(subject)))
173
for subject in enrolled_subjects:
174
print_subject(subject)
160
175
req.write("</ul>\n")
176
if len(unenrolled_subjects) > 0:
177
req.write("<h3>Other Subjects</h3>\n")
178
req.write("<p>You are not currently enrolled in these subjects.\n"
179
" Your marks will not be counted.</p>\n")
181
for subject in unenrolled_subjects:
182
print_subject(subject)
161
184
req.write("</div>\n") # tutorialbody
163
186
def is_valid_subjname(subject):