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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

Update some docs, and remove other obsolete ones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import urllib
27
27
import cgi
28
28
 
29
 
from storm.locals import Desc
30
 
 
31
29
from ivle.webapp.base.xhtml import XHTMLView
32
30
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
33
31
from ivle.webapp.errors import NotFound
34
 
from ivle.database import Subject, Semester
 
32
from ivle.database import Subject
35
33
from ivle import util
36
34
 
37
35
 
38
36
class SubjectsView(XHTMLView):
39
37
    '''The view of the list of subjects.'''
40
38
    template = 'subjects.html'
41
 
    tab = 'subjects'
 
39
    appname = 'subjects' # XXX
42
40
 
43
41
    def authorize(self, req):
44
42
        return req.user is not None
45
43
 
46
44
    def populate(self, req, ctx):
47
 
        ctx['semesters'] = []
48
 
        for semester in req.store.find(Semester).order_by(Desc(Semester.year),
49
 
                                                     Desc(Semester.semester)):
50
 
            enrolments = semester.enrolments.find(user=req.user)
51
 
            if enrolments.count():
52
 
                ctx['semesters'].append((semester, enrolments))
 
45
        enrolled_subjects = req.user.subjects
 
46
        unenrolled_subjects = [subject for subject in
 
47
                               req.store.find(Subject)
 
48
                               if subject not in enrolled_subjects]
 
49
 
 
50
        ctx['enrolled_subjects'] = []
 
51
        ctx['other_subjects'] = []
 
52
 
 
53
        for subject in enrolled_subjects:
 
54
            new_subj = {}
 
55
            new_subj['name'] = subject.name
 
56
            new_subj['url'] = subject.url
 
57
            ctx['enrolled_subjects'].append(new_subj)
 
58
 
 
59
        if len(unenrolled_subjects) > 0:
 
60
            for subject in unenrolled_subjects:
 
61
                new_subj = {}
 
62
                new_subj['name'] = subject.name
 
63
                new_subj['url'] = subject.url
 
64
                ctx['other_subjects'].append(new_subj)
 
65
 
53
66
 
54
67
class Plugin(ViewPlugin, MediaPlugin):
55
68
    urls = [
57
70
    ]
58
71
 
59
72
    tabs = [
60
 
        ('subjects', 'Subjects',
61
 
         'View subject content and complete worksheets',
62
 
         'subjects.png', 'subjects', 5)
 
73
        ('subjects', 'Subjects', 'Announcements and information about the '
 
74
         'subjects you are enrolled in.', 'subjects.png', 'subjects', 5)
63
75
    ]
64
76
 
65
77
    media = 'subject-media'