Fix how row grid values are fetched, for row proxy objects

per changes coming in SQLAlchemy 2.0
This commit is contained in:
Lance Edgar 2024-03-26 11:48:52 -05:00
parent 0b7d2f5aed
commit 27fce173ce

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -33,7 +33,6 @@ from sqlalchemy import orm
from rattail.db.types import GPCType
from rattail.util import prettify, pretty_boolean, pretty_quantity
from rattail.time import localtime
import webhelpers2_grid
from pyramid.renderers import render
@ -478,6 +477,11 @@ class Grid(object):
:returns: The value, or ``None`` if no value was found.
"""
# TODO: this seems a little hacky, is there a better way?
# nb. this may only be relevant for import/export batch view?
if isinstance(obj, sa.engine.Row):
return obj._mapping[column_name]
try:
return obj[column_name]
except KeyError:
@ -503,7 +507,8 @@ class Grid(object):
value = self.obtain_value(obj, column_name)
if value is None:
return ""
value = localtime(self.request.rattail_config, value)
app = self.request.rattail_config.get_app()
value = app.localtime(value)
return raw_datetime(self.request.rattail_config, value)
def render_enum(self, obj, column_name):
@ -1724,7 +1729,7 @@ class CustomWebhelpersGrid(webhelpers2_grid.Grid):
self.renderers = kwargs.pop('renderers', {})
self.linked_columns = kwargs.pop('linked_columns', [])
self.extra_record_class = kwargs.pop('extra_record_class', None)
super(CustomWebhelpersGrid, self).__init__(itemlist, columns, **kwargs)
super().__init__(itemlist, columns, **kwargs)
def generate_header_link(self, column_number, column, label_text):