40
45
req.write_html_head_foot = True # Have dispatch print head and foot
42
req.write('<div id="ivle_padding">\n')
47
ctx = genshi.template.Context()
49
ctx['enrolments'] = []
44
50
# Show a group panel per enrolment
45
51
enrolments = req.user.active_enrolments
46
52
if enrolments.count() == 0:
47
req.write("<p>Error: You are not currently enrolled in any subjects."
53
ctx['no_enrolments'] = True
55
ctx['no_enrolments'] = False
49
57
for enrolment in enrolments:
50
show_subject_panel(req, enrolment.offering)
58
add_subject_panel(req, enrolment.offering, ctx)
51
60
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
52
show_groupadmin_panel(req)
56
def show_groupadmin_panel(req):
58
Shows the group admin panel
61
req.write("<h1>Group Administration</h1>")
63
subjects = req.store.find(Subject)
64
req.write("<label for=\"subject_select\">Subject:</label>\n")
65
req.write("<select id=\"subject_select\">\n")
67
req.write(" <option value=\"%d\">%s (%s)</option>\n"%
68
(s.id, s.name, s.code))
69
req.write("</select>\n")
70
req.write("<input type=\"button\" value=\"Manage\" \
71
onclick=\"manage_subject()\" />\n")
72
req.write("<div id=\"subject_div\"></div>")
74
def show_subject_panel(req, offering):
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):
76
80
Show the group management panel for a particular subject.
80
84
groups = req.user.get_groups(offering)
81
85
if groups.count() == 0:
84
req.write("<div id=\"subject%d\"class=\"subject\">"%offering.id)
85
req.write("<h1>%s</h1>\n" % cgi.escape(offering.subject.name))
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
86
95
for group in groups:
87
req.write("<h2>%s (%s)</h2>\n" %
88
(cgi.escape(group.nick if group.nick else ''),
89
cgi.escape(group.name)))
90
if True: # XXX - was is_member (whether real member or just invited)
91
req.write('<p>You are a member of this group.</p>\n')
93
req.write('<p>You have been invited to this group.</p>\n')
95
'<input type="button" '
96
'onclick="accept("%(groupnm)s")" '
98
'<input type="button" '
99
'onclick="decline("%(groupnm)s")" '
100
'value="Decline" />\n'
101
'</p>\n' % {"groupnm": cgi.escape(group.name)})
102
req.write("<h3>Members</h3>\n")
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'] = []
104
105
for user in group.members:
105
req.write("<li>%s (%s)</li>" %
106
(cgi.escape(user.fullname),
107
cgi.escape(user.login)))
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)