Expose the Role.notes field for view/edit

also add a simple "<pre> with sans-serif font" renderer
This commit is contained in:
Lance Edgar 2020-03-23 19:59:28 -05:00
parent cd019fb05b
commit 917d5ab3fa
3 changed files with 38 additions and 1 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -609,6 +609,7 @@ class Form(object):
self.set_renderer(key, self.render_codeblock)
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
elif type_ == 'text':
self.set_renderer(key, self.render_pre_sans_serif)
self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8))
elif type_ == 'file':
tmpstore = SessionFileUploadTempStore(self.request)
@ -903,6 +904,15 @@ class Form(object):
return ""
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):
if record:
try:

View file

@ -91,6 +91,13 @@ ul.error li {
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
******************************/

View file

@ -35,6 +35,7 @@ from rattail.db.auth import (has_permission, grant_permission, revoke_permission
import colander
from deform import widget as dfwidget
from webhelpers2.html import HTML
from tailbone import grids
from tailbone.db import Session
@ -51,21 +52,37 @@ class RolesView(PrincipalMasterView):
grid_columns = [
'name',
'session_timeout',
'notes',
]
form_fields = [
'name',
'session_timeout',
'notes',
'permissions',
]
def configure_grid(self, g):
super(RolesView, self).configure_grid(g)
# name
g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains'
g.set_sort_defaults('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):
"""
We must prevent edit for certain built-in roles etc., depending on
@ -124,6 +141,9 @@ class RolesView(PrincipalMasterView):
# name
f.set_validator('name', self.unique_name)
# notes
f.set_type('notes', 'text')
# permissions
self.tailbone_permissions = self.get_available_permissions()
f.set_renderer('permissions', PermissionsRenderer(permissions=self.tailbone_permissions))