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
34
import genshi.template
37
# Set request attributes
38
req.content_type = "text/html"
39
req.styles = ["media/groups/groups.css"]
41
"media/groups/groups.js",
42
"media/common/util.js",
43
"media/common/json2.js",
29
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
30
from ivle.webapp.base.xhtml import XHTMLView
32
class GroupsView(XHTMLView):
36
template = 'template.html'
37
appname = 'groups' # XXX
39
def populate(self, req, ctx):
40
self.plugin_styles[Plugin] = ['groups.css']
41
self.plugin_scripts[Plugin] = ['groups.js']
43
# Show a group panel per enrolment
44
ctx['get_user_groups'] = req.user.get_groups
45
ctx['enrolments'] = req.user.active_enrolments
46
ctx['manage_subjects'] = req.store.find(Subject) if \
47
req.user.hasCap(caps.CAP_MANAGEGROUPS) else []
50
class Plugin(ViewPlugin, MediaPlugin):
52
The Plugin class for the group admin plugin.
55
('groups/', GroupsView),
45
req.write_html_head_foot = True # Have dispatch print head and foot
47
ctx = genshi.template.Context()
49
ctx['enrolments'] = []
50
# Show a group panel per enrolment
51
enrolments = req.user.active_enrolments
52
if enrolments.count() == 0:
53
ctx['no_enrolments'] = True
55
ctx['no_enrolments'] = False
57
for enrolment in enrolments:
58
add_subject_panel(req, enrolment.offering, ctx)
60
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
61
ctx['manage_groups'] = True
62
ctx['manage_subjects'] = []
63
subjects = req.store.find(Subject)
67
new_s['name'] = s.name
68
new_s['code'] = s.code
69
ctx['manage_subjects'].append(new_s)
71
ctx['manage_groups'] = False
73
loader = genshi.template.TemplateLoader(".", auto_reload=True)
74
tmpl = loader.load(util.make_local_path("apps/groups/template.html"))
76
req.write(tmpl.generate(ctx).render('html'))
78
def add_subject_panel(req, offering, ctx):
80
Show the group management panel for a particular subject.
83
# Get the groups this user is in, for this offering
84
groups = req.user.get_groups(offering)
85
if groups.count() == 0:
90
offering_groups['offering_id'] = offering.id
91
offering_groups['offering_name'] = offering.subject.name
92
offering_groups['groups'] = []
94
#TODO: Use a better way to manage group membership and invitations
97
new_group['nick'] = cgi.escape(group.nick if group.nick else '')
98
new_group['name'] = cgi.escape(group.name)
100
# XXX - This should be set to reflect whether or not a user is invited
101
# - or if they have accepted the offer
102
new_group['is_member'] = True
103
new_group['members'] = []
105
for user in group.members:
107
member['fullname'] = cgi.escape(user.fullname)
108
member['login'] = cgi.escape(user.login)
109
new_group['members'].append(member)
110
offering_groups['groups'].append(new_group)
112
ctx['enrolments'].append(offering_groups)