40
40
req.write_html_head_foot = True # Have dispatch print head and foot
42
42
req.write('<div id="ivle_padding">\n')
43
44
# Show a group panel per enrolment
46
subjects = db.get_enrolment(req.user.login)
47
# Sort by year,semester,subj_code (newer subjects first)
48
# Leave all fields as strings, just in case (eg. semester='y')
49
subjects.sort(key=lambda(subject):
50
(subject["year"],subject["semester"],subject["subj_code"]),
52
if len(subjects) == 0:
53
req.write("<p>Error: You are not currently enrolled in any subjects."
55
for subject in subjects:
56
show_subject_panel(req, db, subject['offeringid'],
58
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
59
show_groupadmin_panel(req, db)
65
def show_groupadmin_panel(req, db):
45
enrolments = req.user.active_enrolments
46
if enrolments.count() == 0:
47
req.write("<p>Error: You are not currently enrolled in any subjects."
49
for enrolment in enrolments:
50
show_subject_panel(req, enrolment.offering)
51
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
52
show_groupadmin_panel(req)
56
def show_groupadmin_panel(req):
67
58
Shows the group admin panel
69
60
req.write("<hr/>\n")
70
61
req.write("<h1>Group Administration</h1>")
72
subjects = db.get_subjects()
63
subjects = req.store.find(Subject)
73
64
req.write("<label for=\"subject_select\">Subject:</label>\n")
74
65
req.write("<select id=\"subject_select\">\n")
76
67
req.write(" <option value=\"%d\">%s (%s)</option>\n"%
77
(s['subjectid'], s['subj_name'], s['subj_code']))
68
(s.id, s.name, s.code))
78
69
req.write("</select>\n")
79
70
req.write("<input type=\"button\" value=\"Manage\" \
80
71
onclick=\"manage_subject()\" />\n")
81
72
req.write("<div id=\"subject_div\"></div>")
83
def show_subject_panel(req, db, offeringid, subj_name):
74
def show_subject_panel(req, offering):
85
76
Show the group management panel for a particular subject.
88
79
# Get the groups this user is in, for this offering
89
groups = db.get_groups_by_user(req.user.login, offeringid=offeringid)
80
groups = req.user.get_groups(offering)
81
if groups.count() == 0:
93
req.write("<div id=\"subject%d\"class=\"subject\">"%offeringid)
94
req.write("<h1>%s</h1>\n" % cgi.escape(subj_name))
95
for groupid, groupnm, group_nick, is_member in groups:
96
if group_nick is None:
84
req.write("<div id=\"subject%d\"class=\"subject\">"%offering.id)
85
req.write("<h1>%s</h1>\n" % cgi.escape(offering.subject.name))
98
87
req.write("<h2>%s (%s)</h2>\n" %
99
(cgi.escape(group_nick), cgi.escape(groupnm)))
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)
101
91
req.write('<p>You are a member of this group.</p>\n')
103
93
req.write('<p>You have been invited to this group.</p>\n')
108
98
'<input type="button" '
109
99
'onclick="decline("%(groupnm)s")" '
110
100
'value="Decline" />\n'
111
'</p>\n' % {"groupnm": cgi.escape(groupnm)})
101
'</p>\n' % {"groupnm": cgi.escape(group.name)})
112
102
req.write("<h3>Members</h3>\n")
113
103
req.write("<ul>\n")
114
for user in db.get_projectgroup_members(groupid):
104
for user in group.members:
115
105
req.write("<li>%s (%s)</li>" %
116
(cgi.escape(user['fullname']),
117
cgi.escape(user['login'])))
106
(cgi.escape(user.fullname),
107
cgi.escape(user.login)))
118
108
req.write("</ul>\n")
120
110
req.write("</div>")