1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# IVLE
# Copyright (C) 2007-2008 The University of Melbourne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# App: groups
# Author: Matt Giuca
# Date: 21/7/2008
# Allows students and tutors to manage project groups.
# XXX Does not distinguish between current and past subjects.
import cgi
from ivle import (util, caps)
import ivle.db
from ivle.database import Enrolment, Subject, Semester, Offering
def handle(req):
# Set request attributes
req.content_type = "text/html"
req.styles = ["media/groups/groups.css"]
req.scripts = [
"media/groups/groups.js",
"media/common/util.js",
"media/common/json2.js",
]
req.write_html_head_foot = True # Have dispatch print head and foot
req.write('<div id="ivle_padding">\n')
# Show a group panel per enrolment
db = ivle.db.DB()
try:
enrolments = req.user.active_enrolments
if enrolments.count() == 0:
req.write("<p>Error: You are not currently enrolled in any subjects."
"</p>\n")
for enrolment in enrolments:
show_subject_panel(req, db, enrolment.offering.id,
enrolment.offering.subject.name)
if req.user.hasCap(caps.CAP_MANAGEGROUPS):
show_groupadmin_panel(req, db)
req.write("</div>\n")
finally:
db.close()
def show_groupadmin_panel(req, db):
"""
Shows the group admin panel
"""
req.write("<hr/>\n")
req.write("<h1>Group Administration</h1>")
# Choose subject
subjects = db.get_subjects()
req.write("<label for=\"subject_select\">Subject:</label>\n")
req.write("<select id=\"subject_select\">\n")
for s in subjects:
req.write(" <option value=\"%d\">%s (%s)</option>\n"%
(s['subjectid'], s['subj_name'], s['subj_code']))
req.write("</select>\n")
req.write("<input type=\"button\" value=\"Manage\" \
onclick=\"manage_subject()\" />\n")
req.write("<div id=\"subject_div\"></div>")
def show_subject_panel(req, db, offeringid, subj_name):
"""
Show the group management panel for a particular subject.
Prints to req.
"""
# Get the groups this user is in, for this offering
groups = db.get_groups_by_user(req.user.login, offeringid=offeringid)
if len(groups) == 0:
return
req.write("<div id=\"subject%d\"class=\"subject\">"%offeringid)
req.write("<h1>%s</h1>\n" % cgi.escape(subj_name))
for groupid, groupnm, group_nick, is_member in groups:
if group_nick is None:
group_nick = "";
req.write("<h2>%s (%s)</h2>\n" %
(cgi.escape(group_nick), cgi.escape(groupnm)))
if is_member:
req.write('<p>You are a member of this group.</p>\n')
else:
req.write('<p>You have been invited to this group.</p>\n')
req.write('<p>'
'<input type="button" '
'onclick="accept("%(groupnm)s")" '
'value="Accept" />\n'
'<input type="button" '
'onclick="decline("%(groupnm)s")" '
'value="Decline" />\n'
'</p>\n' % {"groupnm": cgi.escape(groupnm)})
req.write("<h3>Members</h3>\n")
req.write("<ul>\n")
for user in db.get_projectgroup_members(groupid):
req.write("<li>%s (%s)</li>" %
(cgi.escape(user['fullname']),
cgi.escape(user['login'])))
req.write("</ul>\n")
req.write("</div>")
|