~azzar1/unity/add-show-desktop-key

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
925 by mattgiuca
Added "groups" app. No code within the app just yet.
30
31
def handle(req):
32
    # Set request attributes
33
    req.content_type = "text/html"
34
    req.styles = ["media/groups/groups.css"]
1001 by dcoles
Groups: Added the view half of the group admin panel. This lets people with the
35
    req.scripts = [
36
        "media/groups/groups.js",
37
        "media/common/util.js",
38
        "media/common/json2.js",
39
    ]
925 by mattgiuca
Added "groups" app. No code within the app just yet.
40
    req.write_html_head_foot = True     # Have dispatch print head and foot
41
42
    req.write('<div id="ivle_padding">\n')
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
43
    # Show a group panel per enrolment
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
44
    db = ivle.db.DB()
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
45
    try:
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')
930 by dcoles
Userservice: Added get_enrolments handler to allow a JSON query of a students
49
        subjects.sort(key=lambda(subject):
50
                          (subject["year"],subject["semester"],subject["subj_code"]),
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
51
                      reverse=True)
52
        if len(subjects) == 0:
53
            req.write("<p>Error: You are not currently enrolled in any subjects."
54
                      "</p>\n")
930 by dcoles
Userservice: Added get_enrolments handler to allow a JSON query of a students
55
        for subject in subjects:
56
            show_subject_panel(req, db, subject['offeringid'],
57
                subject['subj_name'])
1001 by dcoles
Groups: Added the view half of the group admin panel. This lets people with the
58
        if req.user.hasCap(caps.CAP_MANAGEGROUPS):
59
            show_groupadmin_panel(req, db)
60
        
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
61
        req.write("</div>\n")
62
    finally:
63
        db.close()
64
1001 by dcoles
Groups: Added the view half of the group admin panel. This lets people with the
65
def show_groupadmin_panel(req, db):
66
    """
67
    Shows the group admin panel
68
    """
69
    req.write("<hr/>\n")
70
    req.write("<h1>Group Administration</h1>")
71
    # Choose subject
72
    subjects = db.get_subjects()
1009 by wagrant
groups: Pretty up the admin interface somewhat.
73
    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
74
    req.write("<select id=\"subject_select\">\n")
75
    for s in subjects:
1009 by wagrant
groups: Pretty up the admin interface somewhat.
76
        req.write("    <option value=\"%d\">%s (%s)</option>\n"%
77
            (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
78
    req.write("</select>\n")
1009 by wagrant
groups: Pretty up the admin interface somewhat.
79
    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
80
        onclick=\"manage_subject()\" />\n")
81
    req.write("<div id=\"subject_div\"></div>")
82
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
83
def show_subject_panel(req, db, offeringid, subj_name):
84
    """
85
    Show the group management panel for a particular subject.
86
    Prints to req.
87
    """
1008 by wagrant
groups: Pretty up a bit. Remove buttons that did nothing and won't for
88
    # Get the groups this user is in, for this offering
89
    groups = db.get_groups_by_user(req.user.login, offeringid=offeringid)
90
    if len(groups) == 0:
91
        return
92
1001 by dcoles
Groups: Added the view half of the group admin panel. This lets people with the
93
    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
94
    req.write("<h1>%s</h1>\n" % cgi.escape(subj_name))
95
    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)
96
        if group_nick is None:
97
            group_nick = "";
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
98
        req.write("<h2>%s (%s)</h2>\n" %
99
            (cgi.escape(group_nick), cgi.escape(groupnm)))
100
        if is_member:
1008 by wagrant
groups: Pretty up a bit. Remove buttons that did nothing and won't for
101
            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
102
        else:
103
            req.write('<p>You have been invited to this group.</p>\n')
104
            req.write('<p>'
105
                '<input type="button" '
106
                'onclick="accept(&quot;%(groupnm)s&quot;)" '
107
                'value="Accept" />\n'
108
                '<input type="button" '
109
                'onclick="decline(&quot;%(groupnm)s&quot;)" '
110
                'value="Decline" />\n'
111
                '</p>\n' % {"groupnm": cgi.escape(groupnm)})
112
        req.write("<h3>Members</h3>\n")
1008 by wagrant
groups: Pretty up a bit. Remove buttons that did nothing and won't for
113
        req.write("<ul>\n")
114
        for user in db.get_projectgroup_members(groupid):
115
            req.write("<li>%s (%s)</li>" %
116
                      (cgi.escape(user['fullname']),
117
                       cgi.escape(user['login'])))
118
        req.write("</ul>\n")
926 by mattgiuca
db: Added get_enrolment and get_groups_by_user methods to retrieve details
119
1001 by dcoles
Groups: Added the view half of the group admin panel. This lets people with the
120
    req.write("</div>")