Expose the Role.notes
field for view/edit
also add a simple "<pre> with sans-serif font" renderer
This commit is contained in:
parent
cd019fb05b
commit
917d5ab3fa
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2019 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -609,6 +609,7 @@ class Form(object):
|
||||||
self.set_renderer(key, self.render_codeblock)
|
self.set_renderer(key, self.render_codeblock)
|
||||||
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
|
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
|
||||||
elif type_ == 'text':
|
elif type_ == 'text':
|
||||||
|
self.set_renderer(key, self.render_pre_sans_serif)
|
||||||
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
|
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
|
||||||
elif type_ == 'file':
|
elif type_ == 'file':
|
||||||
tmpstore = SessionFileUploadTempStore(self.request)
|
tmpstore = SessionFileUploadTempStore(self.request)
|
||||||
|
@ -903,6 +904,15 @@ class Form(object):
|
||||||
return ""
|
return ""
|
||||||
return HTML.tag('pre', value)
|
return HTML.tag('pre', value)
|
||||||
|
|
||||||
|
def render_pre_sans_serif(self, record, field_name):
|
||||||
|
value = self.obtain_value(record, field_name)
|
||||||
|
if value is None:
|
||||||
|
return ""
|
||||||
|
# this uses a Bulma helper class, for which we also add custom styles
|
||||||
|
# to our "default" base.css (for jquery theme)
|
||||||
|
return HTML.tag('pre', class_='is-family-sans-serif',
|
||||||
|
c=value)
|
||||||
|
|
||||||
def obtain_value(self, record, field_name):
|
def obtain_value(self, record, field_name):
|
||||||
if record:
|
if record:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -91,6 +91,13 @@ ul.error li {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre.is-family-sans-serif {
|
||||||
|
background-color: white;
|
||||||
|
font-family: Verdana, Arial, sans-serif;
|
||||||
|
font-size: 11pt;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* jQuery UI tweaks
|
* jQuery UI tweaks
|
||||||
******************************/
|
******************************/
|
||||||
|
|
|
@ -35,6 +35,7 @@ from rattail.db.auth import (has_permission, grant_permission, revoke_permission
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
from deform import widget as dfwidget
|
from deform import widget as dfwidget
|
||||||
|
from webhelpers2.html import HTML
|
||||||
|
|
||||||
from tailbone import grids
|
from tailbone import grids
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
|
@ -51,21 +52,37 @@ class RolesView(PrincipalMasterView):
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'name',
|
'name',
|
||||||
'session_timeout',
|
'session_timeout',
|
||||||
|
'notes',
|
||||||
]
|
]
|
||||||
|
|
||||||
form_fields = [
|
form_fields = [
|
||||||
'name',
|
'name',
|
||||||
'session_timeout',
|
'session_timeout',
|
||||||
|
'notes',
|
||||||
'permissions',
|
'permissions',
|
||||||
]
|
]
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(RolesView, self).configure_grid(g)
|
super(RolesView, self).configure_grid(g)
|
||||||
|
|
||||||
|
# name
|
||||||
g.filters['name'].default_active = True
|
g.filters['name'].default_active = True
|
||||||
g.filters['name'].default_verb = 'contains'
|
g.filters['name'].default_verb = 'contains'
|
||||||
g.set_sort_defaults('name')
|
g.set_sort_defaults('name')
|
||||||
g.set_link('name')
|
g.set_link('name')
|
||||||
|
|
||||||
|
# notes
|
||||||
|
g.set_renderer('notes', self.render_short_notes)
|
||||||
|
|
||||||
|
def render_short_notes(self, role, field):
|
||||||
|
value = getattr(role, field)
|
||||||
|
if value is None:
|
||||||
|
return ""
|
||||||
|
if len(value) < 100:
|
||||||
|
return value
|
||||||
|
return HTML.tag('span', title=value,
|
||||||
|
c="{}...".format(value[:100]))
|
||||||
|
|
||||||
def editable_instance(self, role):
|
def editable_instance(self, role):
|
||||||
"""
|
"""
|
||||||
We must prevent edit for certain built-in roles etc., depending on
|
We must prevent edit for certain built-in roles etc., depending on
|
||||||
|
@ -124,6 +141,9 @@ class RolesView(PrincipalMasterView):
|
||||||
# name
|
# name
|
||||||
f.set_validator('name', self.unique_name)
|
f.set_validator('name', self.unique_name)
|
||||||
|
|
||||||
|
# notes
|
||||||
|
f.set_type('notes', 'text')
|
||||||
|
|
||||||
# permissions
|
# permissions
|
||||||
self.tailbone_permissions = self.get_available_permissions()
|
self.tailbone_permissions = self.get_available_permissions()
|
||||||
f.set_renderer('permissions', PermissionsRenderer(permissions=self.tailbone_permissions))
|
f.set_renderer('permissions', PermissionsRenderer(permissions=self.tailbone_permissions))
|
||||||
|
|
Loading…
Reference in a new issue