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

« back to all changes in this revision

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

ivle.webapp.base.views#XHTMLView: Set the content type to text/html.
ivle.webapp.browser#BrowserView: Don't set the content type.
ivle.webapp.groups#GroupsView: Clean up, and don't set the content type. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        self.app_template = 'template.html'
42
42
        #XXX: Will hates me for this.
43
43
        self.appname = "groups"
44
 
    
 
44
 
45
45
    def populate(self, req, ctx):
46
46
        # Set request attributes
47
 
        req.content_type = "text/html"
48
47
        req.styles = ["media/groups/groups.css"]
49
48
        req.scripts = [
50
49
            "media/groups/groups.js",
51
50
            "media/common/util.js",
52
51
            "media/common/json2.js",
53
52
        ]
54
 
        req.write_html_head_foot = True     # Have dispatch print head and foot
55
 
        
 
53
 
56
54
        ctx['enrolments'] = []
57
55
        # Show a group panel per enrolment
58
56
        enrolments = req.user.active_enrolments
60
58
            ctx['no_enrolments'] = True
61
59
        else:
62
60
            ctx['no_enrolments'] = False
63
 
        
 
61
 
64
62
        for enrolment in enrolments:
65
63
            self.add_subject_panel(req, enrolment.offering, ctx)
66
 
            
 
64
 
67
65
        if req.user.hasCap(caps.CAP_MANAGEGROUPS):
68
66
            ctx['manage_groups'] = True
69
67
            ctx['manage_subjects'] = []
76
74
                ctx['manage_subjects'].append(new_s)
77
75
        else:
78
76
            ctx['manage_groups'] = False
79
 
      
 
77
 
80
78
 
81
79
    def add_subject_panel(self, req, offering, ctx):
82
80
        """
87
85
        groups = req.user.get_groups(offering)
88
86
        if groups.count() == 0:
89
87
            return
90
 
        
 
88
 
91
89
        offering_groups = {}
92
 
        
 
90
 
93
91
        offering_groups['offering_id'] = offering.id
94
92
        offering_groups['offering_name'] = offering.subject.name
95
93
        offering_groups['groups'] = []
96
 
        
 
94
 
97
95
        #TODO: Use a better way to manage group membership and invitations
98
96
        for group in groups:
99
97
            new_group = {}
100
98
            new_group['nick'] = cgi.escape(group.nick if group.nick else '')
101
99
            new_group['name'] = cgi.escape(group.name)
102
 
            
 
100
 
103
101
            # XXX - This should be set to reflect whether or not a user is invited
104
102
            #     - or if they have accepted the offer
105
103
            new_group['is_member'] = True
106
104
            new_group['members'] = []
107
 
            
 
105
 
108
106
            for user in group.members:
109
107
                member = {}
110
108
                member['fullname'] = cgi.escape(user.fullname)
113
111
            offering_groups['groups'].append(new_group)
114
112
 
115
113
        ctx['enrolments'].append(offering_groups)
116
 
    
 
114
 
 
115
 
117
116
class Plugin(BasePlugin):
118
117
    """
119
118
    The Plugin class for the user plugin.
123
122
    # (regex str, handler class, kwargs dict)
124
123
    # The kwargs dict is passed to the __init__ of the view object
125
124
    urls = [
126
 
        ('groups/*(path)', GroupsView),
127
125
        ('groups/', GroupsView),
128
126
    ]