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

« back to all changes in this revision

Viewing changes to www/apps/groups/__init__.py

  • Committer: mattgiuca
  • Date: 2008-07-21 17:38:18 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:926
db: Added get_enrolment and get_groups_by_user methods to retrieve details
    from the DB.
groups app: Added top-level handler which queries the DB for information about
    the current user's subjects and groups and displays some of the HTML
    required on this page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
# Allows students and tutors to manage project groups.
23
23
 
 
24
# XXX Does not distinguish between current and past subjects.
 
25
 
 
26
import cgi
 
27
 
24
28
from common import util
 
29
import common.db
25
30
 
26
31
def handle(req):
27
32
    # Set request attributes
30
35
    req.scripts = ["media/groups/groups.js"]
31
36
    req.write_html_head_foot = True     # Have dispatch print head and foot
32
37
 
33
 
    # Start writing data
34
38
    req.write('<div id="ivle_padding">\n')
35
 
    req.write("<p>Group Management Panel (Under Construction)</p>\n")
36
 
    req.write("</div>\n")
 
39
    # Show a group panel per enrolment
 
40
    db = common.db.DB()
 
41
    try:
 
42
        subjects = db.get_enrolment(req.user.login)
 
43
        # Sort by year,semester,subj_code (newer subjects first)
 
44
        # Leave all fields as strings, just in case (eg. semester='y')
 
45
        subjects.sort(key=lambda (_oid,subj_code,_sn,_ssn,year,semester):
 
46
                            (year,semester,subj_code),
 
47
                      reverse=True)
 
48
        if len(subjects) == 0:
 
49
            req.write("<p>Error: You are not currently enrolled in any subjects."
 
50
                      "</p>\n")
 
51
        for offeringid,_,subj_name,_,_,_ in subjects:
 
52
            show_subject_panel(req, db, offeringid, subj_name)
 
53
        req.write("</div>\n")
 
54
    finally:
 
55
        db.close()
 
56
 
 
57
def show_subject_panel(req, db, offeringid, subj_name):
 
58
    """
 
59
    Show the group management panel for a particular subject.
 
60
    Prints to req.
 
61
    """
 
62
    req.write("<h1>%s</h1>\n" % cgi.escape(subj_name))
 
63
    # Get the groups this user is in, for this offering
 
64
    groups = db.get_groups_by_user(req.user.login, offeringid=offeringid)
 
65
    for groupid, groupnm, group_nick, is_member in groups:
 
66
        req.write("<h2>%s (%s)</h2>\n" %
 
67
            (cgi.escape(group_nick), cgi.escape(groupnm)))
 
68
        if is_member:
 
69
            req.write('<p>You are in this group.\n'
 
70
                '  <input type="button" onclick="manage(&quot;%s&quot;)" '
 
71
                'value="Manage" /></p>\n' % (cgi.escape(groupnm)))
 
72
        else:
 
73
            req.write('<p>You have been invited to this group.</p>\n')
 
74
            req.write('<p>'
 
75
                '<input type="button" '
 
76
                'onclick="accept(&quot;%(groupnm)s&quot;)" '
 
77
                'value="Accept" />\n'
 
78
                '<input type="button" '
 
79
                'onclick="decline(&quot;%(groupnm)s&quot;)" '
 
80
                'value="Decline" />\n'
 
81
                '</p>\n' % {"groupnm": cgi.escape(groupnm)})
 
82
        req.write("<h3>Members</h3>\n")
 
83
        req.write("<table>\n")
 
84
        # TODO: Fill in members table
 
85
        req.write("</table>\n")
 
86
 
 
87
    if True:        # XXX Only if offering allows students to create groups
 
88
        req.write('<input type="button" onclick="create(%d)" '
 
89
            'value="Create Group" />\n' % offeringid)