15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# Allows students and tutors to manage project groups.
24
# XXX Does not distinguish between current and past subjects.
18
# Author: Matt Giuca, Will Grant
21
Allows students and tutors to manage project groups.
24
# TODO Does not distinguish between current and past subjects.
28
26
from ivle import caps
29
27
from ivle.database import Subject
32
29
from ivle.webapp.base.plugins import BasePlugin
33
30
from ivle.webapp.base.xhtml import XHTMLView
48
45
"media/common/json2.js",
51
ctx['enrolments'] = []
52
48
# Show a group panel per enrolment
53
enrolments = req.user.active_enrolments
54
if enrolments.count() == 0:
55
ctx['no_enrolments'] = True
57
ctx['no_enrolments'] = False
59
for enrolment in enrolments:
60
self.add_subject_panel(req, enrolment.offering, ctx)
62
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
63
ctx['manage_groups'] = True
64
ctx['manage_subjects'] = []
65
subjects = req.store.find(Subject)
69
new_s['name'] = s.name
70
new_s['code'] = s.code
71
ctx['manage_subjects'].append(new_s)
73
ctx['manage_groups'] = False
76
def add_subject_panel(self, req, offering, ctx):
78
Show the group management panel for a particular subject.
81
# Get the groups this user is in, for this offering
82
groups = req.user.get_groups(offering)
83
if groups.count() == 0:
88
offering_groups['offering_id'] = offering.id
89
offering_groups['offering_name'] = offering.subject.name
90
offering_groups['groups'] = []
92
#TODO: Use a better way to manage group membership and invitations
95
new_group['nick'] = cgi.escape(group.nick if group.nick else '')
96
new_group['name'] = cgi.escape(group.name)
98
# XXX - This should be set to reflect whether or not a user is invited
99
# - or if they have accepted the offer
100
new_group['is_member'] = True
101
new_group['members'] = []
103
for user in group.members:
105
member['fullname'] = cgi.escape(user.fullname)
106
member['login'] = cgi.escape(user.login)
107
new_group['members'].append(member)
108
offering_groups['groups'].append(new_group)
110
ctx['enrolments'].append(offering_groups)
49
ctx['get_user_groups'] = req.user.get_groups
50
ctx['enrolments'] = req.user.active_enrolments
51
ctx['manage_subjects'] = req.store.find(Subject) if \
52
req.user.hasCap(caps.CAP_MANAGEGROUPS) else []
113
55
class Plugin(BasePlugin):
115
The Plugin class for the user plugin.
57
The Plugin class for the group admin plugin.
117
# Magic attribute: urls
118
# Sequence of pairs/triples of
119
# (regex str, handler class, kwargs dict)
120
# The kwargs dict is passed to the __init__ of the view object
122
60
('groups/', GroupsView),