From 3ece3303db9c79d3748058ed98740a9f9a12717c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 25 Sep 2021 18:54:33 -0400 Subject: [PATCH] Refactor several "field grids" per Buefy theme e.g. the Users field when viewing a Role, and Vendor Sources panel when viewing a Product --- tailbone/forms/core.py | 25 ++++++-- tailbone/grids/core.py | 3 +- tailbone/templates/customers/view.mako | 25 ++++++++ tailbone/templates/grids/b-table.mako | 7 +++ tailbone/templates/products/view.mako | 11 ++++ tailbone/templates/roles/view.mako | 22 ++++++- tailbone/views/customers.py | 80 +++++++++++++++++++++++--- tailbone/views/products.py | 80 ++++++++++++++++++++++++++ tailbone/views/roles.py | 63 +++++++++++++++++++- 9 files changed, 299 insertions(+), 17 deletions(-) diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py index d35b8a35..2267b8dc 100644 --- a/tailbone/forms/core.py +++ b/tailbone/forms/core.py @@ -615,6 +615,9 @@ class Form(object): elif type_ == 'text': self.set_renderer(key, self.render_pre_sans_serif) self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8)) + elif type_ == 'text_wrapped': + self.set_renderer(key, self.render_pre_sans_serif_wrapped) + self.set_widget(key, dfwidget.TextAreaWidget(cols=80, rows=8)) elif type_ == 'file': tmpstore = SessionFileUploadTempStore(self.request) kw = {'widget': dfwidget.FileUploadWidget(tmpstore), @@ -914,14 +917,26 @@ class Form(object): return "" return HTML.tag('pre', value) - def render_pre_sans_serif(self, record, field_name): + def render_pre_sans_serif(self, record, field_name, wrapped=False): 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) + + kwargs = { + 'c': value, + # this uses a Bulma helper class, for which we also add + # custom styles to our "default" base.css (for jquery + # theme) + 'class_': 'is-family-sans-serif', + } + + if wrapped: + kwargs['style'] = 'white-space: pre-wrap;' + + return HTML.tag('pre', **kwargs) + + def render_pre_sans_serif_wrapped(self, record, field_name): + return self.render_pre_sans_serif(record, field_name, wrapped=True) def obtain_value(self, record, field_name): if record: diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 1e6787fa..f918fad4 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -1418,12 +1418,13 @@ class GridAction(object): """ def __init__(self, key, label=None, url='#', icon=None, target=None, - click_handler=None): + link_class=None, click_handler=None): self.key = key self.label = label or prettify(key) self.icon = icon self.url = url self.target = target + self.link_class = link_class self.click_handler = click_handler def get_url(self, row, i): diff --git a/tailbone/templates/customers/view.mako b/tailbone/templates/customers/view.mako index 6c9de1ce..81e05aaa 100644 --- a/tailbone/templates/customers/view.mako +++ b/tailbone/templates/customers/view.mako @@ -26,4 +26,29 @@ % endif +<%def name="render_buefy_form()"> +
+ + +
+ + +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + + + ${parent.body()} diff --git a/tailbone/templates/grids/b-table.mako b/tailbone/templates/grids/b-table.mako index ee257819..7ff33e73 100644 --- a/tailbone/templates/grids/b-table.mako +++ b/tailbone/templates/grids/b-table.mako @@ -15,6 +15,9 @@ % if loading is not Undefined and loading: :loading="${loading}" % endif + % if grid.default_sortkey: + :default-sort="['${grid.default_sortkey}', '${grid.default_sortdir}']" + % endif >