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