'@todo: description?
@return: dictionary for the view
# All the possible roles
"roles": {
"staff_reader": {
"module": {
"uid": "staff",
"label": "Staff"
# The roles currently assigned to users for entit(y/ies)
"assigned_roles": {
"1": [
"staff_reader",
"project_editor",
"pagination_list": [
"User One",
"1"
# The object (user/entity) we are assigning roles for
"foreign_object": {
"id": "1",
"name": "User One"
or
"foreign_object": {
"id": "70",
"name": "Organisation Seventy"'

def get_context_data(self, r, **attr):

    T = current.T
    self.entity = self.get_entity()
    self.user = self.get_user()
    self.assigned_roles = self.get_assigned_roles()
    self.foreign_object = self.get_foreign_object()
    form = self.get_form()
    form.vars.update(self.get_form_vars())
    if form.accepts(r.post_vars, current.session):
        before = (self.assigned_roles[self.foreign_object['id']] if self.foreign_object else [])
        after = [('%s_%s' % (mod_uid, acl_uid)) for (mod_uid, acl_uid) in form.vars.items() if ((mod_uid in self.modules.keys()) and (acl_uid in self.acls.keys()))]
        user_id = (self.user['id'] if self.user else form.vars.foreign_object)
        entity_id = (self.entity['id'] if self.entity else form.vars.foreign_object)
        self.update_roles(user_id, entity_id, before, after)
        current.session.confirmation = T('Roles    updated')
        redirect(r.url(vars={}))
    context = {'roles': self.roles, 'foreign_object': self.foreign_object, 'form': form, 'title': T('Roles')}
    if (not self.foreign_object):
        pagination_size = int(r.get_vars.get('page_size', 4))
        pagination_offset = int(r.get_vars.get('page_offset', 0))
        import math
        pagination_pages = int(math.ceil((len(self.assigned_roles) / float(pagination_size))))
        pagination_list = [(self.objects[id], id) for id in self.assigned_roles]
        pagination_list = sorted(pagination_list)[(pagination_offset * pagination_size):((pagination_offset * pagination_size) + pagination_size)]
        context.update({'assigned_roles': self.assigned_roles, 'pagination_size': pagination_size, 'pagination_offset': pagination_offset, 'pagination_list': pagination_list, 'pagination_pages': pagination_pages})
    return context
