Fix how metadata/bind is used for importer batch table
per changes coming in SQLAlchemy 2.0
This commit is contained in:
parent
25c48a97c5
commit
0b7d2f5aed
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2023 Lance Edgar
|
# Copyright © 2010-2024 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -26,7 +26,7 @@ Views for importer batches
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db.model import ImporterBatch
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
"""
|
"""
|
||||||
Master view for importer batches.
|
Master view for importer batches.
|
||||||
"""
|
"""
|
||||||
model_class = model.ImporterBatch
|
model_class = ImporterBatch
|
||||||
default_handler_spec = 'rattail.batch.importer:ImporterBatchHandler'
|
default_handler_spec = 'rattail.batch.importer:ImporterBatchHandler'
|
||||||
route_prefix = 'batch.importer'
|
route_prefix = 'batch.importer'
|
||||||
url_prefix = '/batches/importer'
|
url_prefix = '/batches/importer'
|
||||||
|
@ -91,7 +91,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
]
|
]
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(ImporterBatchView, self).configure_form(f)
|
super().configure_form(f)
|
||||||
|
|
||||||
# readonly fields
|
# readonly fields
|
||||||
f.set_readonly('import_handler_spec')
|
f.set_readonly('import_handler_spec')
|
||||||
|
@ -110,21 +110,21 @@ class ImporterBatchView(BatchMasterView):
|
||||||
self.make_row_table(batch.row_table)
|
self.make_row_table(batch.row_table)
|
||||||
kwargs['rows'] = self.Session.query(self.current_row_table).all()
|
kwargs['rows'] = self.Session.query(self.current_row_table).all()
|
||||||
kwargs.setdefault('status_enum', self.enum.IMPORTER_BATCH_ROW_STATUS)
|
kwargs.setdefault('status_enum', self.enum.IMPORTER_BATCH_ROW_STATUS)
|
||||||
breakdown = super(ImporterBatchView, self).make_status_breakdown(
|
breakdown = super().make_status_breakdown(batch, **kwargs)
|
||||||
batch, **kwargs)
|
|
||||||
return breakdown
|
return breakdown
|
||||||
|
|
||||||
def delete_instance(self, batch):
|
def delete_instance(self, batch):
|
||||||
self.make_row_table(batch.row_table)
|
self.make_row_table(batch.row_table)
|
||||||
if self.current_row_table is not None:
|
if self.current_row_table is not None:
|
||||||
self.current_row_table.drop()
|
self.current_row_table.drop()
|
||||||
super(ImporterBatchView, self).delete_instance(batch)
|
super().delete_instance(batch)
|
||||||
|
|
||||||
def make_row_table(self, name):
|
def make_row_table(self, name):
|
||||||
if not hasattr(self, 'current_row_table'):
|
if not hasattr(self, 'current_row_table'):
|
||||||
metadata = sa.MetaData(schema='batch', bind=self.Session.bind)
|
metadata = sa.MetaData(schema='batch')
|
||||||
try:
|
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:
|
except sa.exc.NoSuchTableError:
|
||||||
self.current_row_table = None
|
self.current_row_table = None
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
return self.enum.IMPORTER_BATCH_ROW_STATUS
|
return self.enum.IMPORTER_BATCH_ROW_STATUS
|
||||||
|
|
||||||
def configure_row_grid(self, g):
|
def configure_row_grid(self, g):
|
||||||
super(ImporterBatchView, self).configure_row_grid(g)
|
super().configure_row_grid(g)
|
||||||
|
|
||||||
def make_filter(field, **kwargs):
|
def make_filter(field, **kwargs):
|
||||||
column = getattr(self.current_row_table.c, field)
|
column = getattr(self.current_row_table.c, field)
|
||||||
|
@ -190,7 +190,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
|
|
||||||
def get_parent(self, row):
|
def get_parent(self, row):
|
||||||
uuid = self.current_row_table.name
|
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):
|
def get_row_instance_title(self, row):
|
||||||
if row.object_str:
|
if row.object_str:
|
||||||
|
@ -242,7 +242,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
|
|
||||||
kwargs.setdefault('schema', colander.Schema())
|
kwargs.setdefault('schema', colander.Schema())
|
||||||
kwargs.setdefault('cancel_url', None)
|
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):
|
def configure_row_form(self, f):
|
||||||
"""
|
"""
|
||||||
|
@ -291,7 +291,7 @@ class ImporterBatchView(BatchMasterView):
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_row_xlsx_row(self, row, fields):
|
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]
|
xlrow['status'] = self.enum.IMPORTER_BATCH_ROW_STATUS[row.status_code]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue