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

« back to all changes in this revision

Viewing changes to ivle/webapp/groups/__init__.py

ivle.webapp.groups: Remove most of the view code; the template now accesses
    the objects directly. Also fix a few double-encodings and typos.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
# App: groups
19
 
# Author: Matt Giuca
20
 
# Date: 21/7/2008
21
 
 
22
 
# Allows students and tutors to manage project groups.
23
 
 
24
 
# XXX Does not distinguish between current and past subjects.
25
 
 
26
 
import cgi
 
18
# Author: Matt Giuca, Will Grant
 
19
 
 
20
'''
 
21
Allows students and tutors to manage project groups.
 
22
'''
 
23
 
 
24
# TODO Does not distinguish between current and past subjects.
27
25
 
28
26
from ivle import caps
29
27
from ivle.database import Subject
30
 
from ivle import util
31
28
 
32
29
from ivle.webapp.base.plugins import BasePlugin
33
30
from ivle.webapp.base.xhtml import XHTMLView
48
45
            "media/common/json2.js",
49
46
        ]
50
47
 
51
 
        ctx['enrolments'] = []
52
48
        # Show a group panel per enrolment
53
 
        enrolments = req.user.active_enrolments
54
 
        if enrolments.count() == 0:
55
 
            ctx['no_enrolments'] = True
56
 
        else:
57
 
            ctx['no_enrolments'] = False
58
 
 
59
 
        for enrolment in enrolments:
60
 
            self.add_subject_panel(req, enrolment.offering, ctx)
61
 
 
62
 
        if req.user.hasCap(caps.CAP_MANAGEGROUPS):
63
 
            ctx['manage_groups'] = True
64
 
            ctx['manage_subjects'] = []
65
 
            subjects = req.store.find(Subject)
66
 
            for s in subjects:
67
 
                new_s = {}
68
 
                new_s['id'] = s.id
69
 
                new_s['name'] = s.name
70
 
                new_s['code'] = s.code
71
 
                ctx['manage_subjects'].append(new_s)
72
 
        else:
73
 
            ctx['manage_groups'] = False
74
 
 
75
 
 
76
 
    def add_subject_panel(self, req, offering, ctx):
77
 
        """
78
 
        Show the group management panel for a particular subject.
79
 
        Prints to req.
80
 
        """
81
 
        # Get the groups this user is in, for this offering
82
 
        groups = req.user.get_groups(offering)
83
 
        if groups.count() == 0:
84
 
            return
85
 
 
86
 
        offering_groups = {}
87
 
 
88
 
        offering_groups['offering_id'] = offering.id
89
 
        offering_groups['offering_name'] = offering.subject.name
90
 
        offering_groups['groups'] = []
91
 
 
92
 
        #TODO: Use a better way to manage group membership and invitations
93
 
        for group in groups:
94
 
            new_group = {}
95
 
            new_group['nick'] = cgi.escape(group.nick if group.nick else '')
96
 
            new_group['name'] = cgi.escape(group.name)
97
 
 
98
 
            # XXX - This should be set to reflect whether or not a user is invited
99
 
            #     - or if they have accepted the offer
100
 
            new_group['is_member'] = True
101
 
            new_group['members'] = []
102
 
 
103
 
            for user in group.members:
104
 
                member = {}
105
 
                member['fullname'] = cgi.escape(user.fullname)
106
 
                member['login'] = cgi.escape(user.login)
107
 
                new_group['members'].append(member)
108
 
            offering_groups['groups'].append(new_group)
109
 
 
110
 
        ctx['enrolments'].append(offering_groups)
 
49
        ctx['get_user_groups'] = req.user.get_groups
 
50
        ctx['enrolments'] = req.user.active_enrolments
 
51
        ctx['manage_subjects'] = req.store.find(Subject) if \
 
52
              req.user.hasCap(caps.CAP_MANAGEGROUPS) else []
111
53
 
112
54
 
113
55
class Plugin(BasePlugin):
114
56
    """
115
 
    The Plugin class for the user plugin.
 
57
    The Plugin class for the group admin plugin.
116
58
    """
117
 
    # Magic attribute: urls
118
 
    # Sequence of pairs/triples of
119
 
    # (regex str, handler class, kwargs dict)
120
 
    # The kwargs dict is passed to the __init__ of the view object
121
59
    urls = [
122
60
        ('groups/', GroupsView),
123
61
    ]