@register.inclusion_tag(u'wagtailusers/groups/includes/formatted_permissions.html')
def format_permissions(permission_bound_field):
 permissions = permission_bound_field.field._queryset
 content_type_ids = set(permissions.values_list(u'content_type_id', flat=True))
 checkboxes_by_id = {int(checkbox.choice_value): checkbox for checkbox in permission_bound_field}
 object_perms = []
 other_perms = []
 for content_type_id in content_type_ids:
  content_perms = permissions.filter(content_type_id=content_type_id)
  content_perms_dict = {}
  for perm in content_perms:
   checkbox = checkboxes_by_id[perm.id]
   permission_action = perm.codename.split(u'_')[0]
   if (permission_action in [u'add', u'change', u'delete']):
    content_perms_dict[u'object'] = perm.content_type.name
    content_perms_dict[permission_action] = checkbox
   else:
    other_perms.append((perm, checkbox))
  if content_perms_dict:
   object_perms.append(content_perms_dict)
 return {u'object_perms': object_perms, u'other_perms': other_perms}

@ register . inclusion_tag ( u'wagtailusers/groups/includes/formatted_permissions.html' ) def format_permissions ( permission_bound_field ) : permissions = permission_bound_field . field . _queryset content_type_ids = set ( permissions . values_list ( u'content_type_id' , flat = True ) ) checkboxes_by_id = { int ( checkbox . choice_value ) : checkbox for checkbox in permission_bound_field } object_perms = [ ] other_perms = [ ] for content_type_id in content_type_ids : content_perms = permissions . filter ( content_type_id = content_type_id ) content_perms_dict = { } for perm in content_perms : checkbox = checkboxes_by_id [ perm . id ] permission_action = perm . codename . split ( u'_' ) [ 0 ] if ( permission_action in [ u'add' , u'change' , u'delete' ] ) : content_perms_dict [ u'object' ] = perm . content_type . name content_perms_dict [ permission_action ] = checkbox else : other_perms . append ( ( perm , checkbox ) ) if content_perms_dict : object_perms . append ( content_perms_dict ) return { u'object_perms' : object_perms , u'other_perms' : other_perms }
given a bound field with a queryset of permission objects - which must be using the checkboxselectmultiple widget - construct a list of dictionaries for objects: objects: [ object: name_of_some_content_object .