~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/tutorial/__init__.py

  • Committer: mattgiuca
  • Date: 2008-07-27 13:54:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:959
tutorial: Top-level menu now displays list of subjects from the database,
    rather than guessing by looking in the directory listing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
152
153
    # Get list of subjects
153
 
    # TODO: Fetch from DB. For now, just get directory listing
154
 
    subjects = os.listdir(conf.subjects_base)
155
 
    subjects.sort()
 
154
    db = common.db.DB()
 
155
    try:
 
156
        enrolled_subjects = db.get_enrolment(req.user.login)
 
157
        all_subjects = db.get_subjects()
 
158
    finally:
 
159
        db.close()
 
160
 
 
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'])
 
166
 
 
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'])))
 
171
 
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")
 
180
        req.write("<ul>\n")
 
181
        for subject in unenrolled_subjects:
 
182
            print_subject(subject)
 
183
        req.write("</ul>\n")
161
184
    req.write("</div>\n")   # tutorialbody
162
185
 
163
186
def is_valid_subjname(subject):