fix: refactor config.get_model()
=> app.model
per rattail changes
This commit is contained in:
parent
4eb5866379
commit
ae8212069c
10 changed files with 54 additions and 40 deletions
|
@ -32,7 +32,7 @@ import sqlalchemy as sa
|
|||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db.types import GPCType
|
||||
from rattail.util import prettify, pretty_boolean, pretty_quantity
|
||||
from rattail.util import prettify, pretty_boolean
|
||||
|
||||
from pyramid.renderers import render
|
||||
from webhelpers2.html import HTML, tags
|
||||
|
@ -60,7 +60,7 @@ class FieldList(list):
|
|||
self.insert(i + 1, newfield)
|
||||
|
||||
|
||||
class Grid(object):
|
||||
class Grid:
|
||||
"""
|
||||
Core grid class. In sore need of documentation.
|
||||
|
||||
|
@ -532,7 +532,8 @@ class Grid(object):
|
|||
|
||||
def render_quantity(self, obj, column_name):
|
||||
value = self.obtain_value(obj, column_name)
|
||||
return pretty_quantity(value)
|
||||
app = self.request.rattail_config.get_app()
|
||||
return app.render_quantity(value)
|
||||
|
||||
def render_duration(self, obj, column_name):
|
||||
seconds = self.obtain_value(obj, column_name)
|
||||
|
@ -1152,10 +1153,12 @@ class Grid(object):
|
|||
"""
|
||||
Persist the given settings in some way, as defined by ``func``.
|
||||
"""
|
||||
app = self.request.rattail_config.get_app()
|
||||
model = app.model
|
||||
|
||||
def persist(key, value=lambda k: settings[k]):
|
||||
if to == 'defaults':
|
||||
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
||||
app = self.request.rattail_config.get_app()
|
||||
app.save_setting(Session(), skey, value(key))
|
||||
else: # to == session
|
||||
skey = 'grid.{}.{}'.format(self.key, key)
|
||||
|
@ -1172,7 +1175,6 @@ class Grid(object):
|
|||
# first clear existing settings for *sorting* only
|
||||
# nb. this is because number of sort settings will vary
|
||||
if to == 'defaults':
|
||||
model = self.request.rattail_config.get_model()
|
||||
prefix = f'tailbone.{self.request.user.uuid}.grid.{self.key}'
|
||||
query = Session.query(model.Setting)\
|
||||
.filter(sa.or_(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue