Fix how metadata/bind is used for importer batch table

per changes coming in SQLAlchemy 2.0
This commit is contained in:
Lance Edgar 2024-03-26 11:47:37 -05:00
parent 25c48a97c5
commit 0b7d2f5aed

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.
#
@ -26,7 +26,7 @@ Views for importer batches
import sqlalchemy as sa
from rattail.db import model
from rattail.db.model import ImporterBatch
import colander
@ -37,7 +37,7 @@ class ImporterBatchView(BatchMasterView):
"""
Master view for importer batches.
"""
model_class = model.ImporterBatch
model_class = ImporterBatch
default_handler_spec = 'rattail.batch.importer:ImporterBatchHandler'
route_prefix = 'batch.importer'
url_prefix = '/batches/importer'
@ -91,7 +91,7 @@ class ImporterBatchView(BatchMasterView):
]
def configure_form(self, f):
super(ImporterBatchView, self).configure_form(f)
super().configure_form(f)
# readonly fields
f.set_readonly('import_handler_spec')
@ -110,21 +110,21 @@ class ImporterBatchView(BatchMasterView):
self.make_row_table(batch.row_table)
kwargs['rows'] = self.Session.query(self.current_row_table).all()
kwargs.setdefault('status_enum', self.enum.IMPORTER_BATCH_ROW_STATUS)
breakdown = super(ImporterBatchView, self).make_status_breakdown(
batch, **kwargs)
breakdown = super().make_status_breakdown(batch, **kwargs)
return breakdown
def delete_instance(self, batch):
self.make_row_table(batch.row_table)
if self.current_row_table is not None:
self.current_row_table.drop()
super(ImporterBatchView, self).delete_instance(batch)
super().delete_instance(batch)
def make_row_table(self, name):
if not hasattr(self, 'current_row_table'):
metadata = sa.MetaData(schema='batch', bind=self.Session.bind)
metadata = sa.MetaData(schema='batch')
try:
self.current_row_table = sa.Table(name, metadata, autoload=True)
self.current_row_table = sa.Table(name, metadata,
autoload_with=self.Session.bind)
except sa.exc.NoSuchTableError:
self.current_row_table = None
@ -136,7 +136,7 @@ class ImporterBatchView(BatchMasterView):
return self.enum.IMPORTER_BATCH_ROW_STATUS
def configure_row_grid(self, g):
super(ImporterBatchView, self).configure_row_grid(g)
super().configure_row_grid(g)
def make_filter(field, **kwargs):
column = getattr(self.current_row_table.c, field)
@ -190,7 +190,7 @@ class ImporterBatchView(BatchMasterView):
def get_parent(self, row):
uuid = self.current_row_table.name
return self.Session.get(model.ImporterBatch, uuid)
return self.Session.get(ImporterBatch, uuid)
def get_row_instance_title(self, row):
if row.object_str:
@ -242,7 +242,7 @@ class ImporterBatchView(BatchMasterView):
kwargs.setdefault('schema', colander.Schema())
kwargs.setdefault('cancel_url', None)
return super(ImporterBatchView, self).make_row_form(instance=row, **kwargs)
return super().make_row_form(instance=row, **kwargs)
def configure_row_form(self, f):
"""
@ -291,7 +291,7 @@ class ImporterBatchView(BatchMasterView):
]
def get_row_xlsx_row(self, row, fields):
xlrow = super(ImporterBatchView, self).get_row_xlsx_row(row, fields)
xlrow = super().get_row_xlsx_row(row, fields)
xlrow['status'] = self.enum.IMPORTER_BATCH_ROW_STATUS[row.status_code]