Only show granted permissions when viewing role details

Hopefully a little easier on the eyes..still could use more improvements
though I'm sure.
This commit is contained in:
Lance Edgar 2016-08-11 22:29:55 -05:00
parent 2b1a493706
commit 41ca3859f6
2 changed files with 18 additions and 8 deletions

View file

@ -3,6 +3,10 @@
* Permission Lists
******************************/
div.field-wrapper.permissions {
overflow: visible;
}
div.field-wrapper.permissions div.field div.group {
margin-bottom: 10px;
}

View file

@ -74,18 +74,24 @@ def PermissionsFieldRenderer(permissions, *args, **kwargs):
for groupkey in sorted(permissions, key=lambda k: permissions[k]['label'].lower()):
inner = HTML.tag('p', c=permissions[groupkey]['label'])
perms = permissions[groupkey]['perms']
rendered = False
for key in sorted(perms, key=lambda p: perms[p]['label'].lower()):
checked = has_permission(Session(), role, key,
include_guest=False,
include_authenticated=False)
label = perms[key]['label']
if readonly:
span = HTML.tag('span', c="[X]" if checked else "[ ]")
inner += HTML.tag('p', class_='perm', c=span + ' ' + label)
else:
inner += tags.checkbox(self.name + '-' + key,
checked=checked, label=label)
html += HTML.tag('div', class_='group', c=inner)
if checked or not readonly:
label = perms[key]['label']
if readonly:
span = HTML.tag('span', c="[X]" if checked else "[ ]")
inner += HTML.tag('p', class_='perm', c=span + ' ' + label)
else:
inner += tags.checkbox(self.name + '-' + key,
checked=checked, label=label)
rendered = True
if rendered:
html += HTML.tag('div', class_='group', c=inner)
if not html:
return "(none granted)"
return html
def render(self, **kwargs):