21
21
Allows students and tutors to manage project groups.
24
# TODO Does not distinguish between current and past subjects.
26
from ivle.database import Subject
24
from ivle.database import Subject, Offering, Semester
28
26
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
29
27
from ivle.webapp.base.xhtml import XHTMLView
35
33
template = 'template.html'
36
def __init__(self, req, subject, year, semester):
37
"""Find the given offering by subject, year and semester."""
38
self.context = req.store.find(Offering,
39
Offering.subject_id == Subject.id,
40
Subject.code == subject,
41
Offering.semester_id == Semester.id,
42
Semester.year == year,
43
Semester.semester == semester).one()
38
48
def authorize(self, req):
39
return req.user is not None
49
enrolment = self.context.get_enrolment(req.user)
52
return req.user.admin or enrolment.role in (u'tutor', u'lecturer')
41
54
def populate(self, req, ctx):
42
55
self.plugin_styles[Plugin] = ['groups.css']
43
56
self.plugin_scripts[Plugin] = ['groups.js']
45
roles = set((e.role for e in req.user.active_enrolments))
46
ctx['manage_subjects'] = req.store.find(Subject) if \
47
req.user.admin or 'tutor' in roles or 'lecturer' in roles else []
58
ctx['offering'] = self.context
50
60
class Plugin(ViewPlugin, MediaPlugin):
52
62
The Plugin class for the group admin plugin.
55
('groups/', GroupsView),
65
('/subjects/:subject/:year/:semester/+groups/', GroupsView),