Refactor Query.get()
=> Session.get()
per SQLAlchemy 1.4
This commit is contained in:
parent
81aa0ae109
commit
f611a5a521
38 changed files with 169 additions and 205 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,8 +24,6 @@
|
|||
Common Forms
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
import colander
|
||||
|
@ -35,7 +33,7 @@ import colander
|
|||
def validate_user(node, kw):
|
||||
session = kw['session']
|
||||
def validate(node, value):
|
||||
user = session.query(model.User).get(value)
|
||||
user = session.get(model.User, value)
|
||||
if not user:
|
||||
raise colander.Invalid(node, "User not found")
|
||||
return user.uuid
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,8 +24,6 @@
|
|||
Forms for Receiving
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
import colander
|
||||
|
@ -35,7 +33,7 @@ import colander
|
|||
def valid_purchase_batch_row(node, kw):
|
||||
session = kw['session']
|
||||
def validate(node, value):
|
||||
row = session.query(model.PurchaseBatchRow).get(value)
|
||||
row = session.get(model.PurchaseBatchRow, value)
|
||||
if not row:
|
||||
raise colander.Invalid(node, "Batch row not found")
|
||||
if row.batch.executed:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,13 +24,9 @@
|
|||
Form Schema Types
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import re
|
||||
import datetime
|
||||
|
||||
import six
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.gpc import GPC
|
||||
|
||||
|
@ -84,7 +80,7 @@ class GPCType(colander.SchemaType):
|
|||
def serialize(self, node, appstruct):
|
||||
if appstruct is colander.null:
|
||||
return colander.null
|
||||
return six.text_type(appstruct)
|
||||
return str(appstruct)
|
||||
|
||||
def deserialize(self, node, cstruct):
|
||||
if not cstruct:
|
||||
|
@ -95,7 +91,7 @@ class GPCType(colander.SchemaType):
|
|||
try:
|
||||
return GPC(digits)
|
||||
except Exception as err:
|
||||
raise colander.Invalid(node, six.text_type(err))
|
||||
raise colander.Invalid(node, str(err))
|
||||
|
||||
|
||||
class ProductQuantity(colander.MappingSchema):
|
||||
|
@ -133,12 +129,12 @@ class ModelType(colander.SchemaType):
|
|||
def serialize(self, node, appstruct):
|
||||
if appstruct is colander.null:
|
||||
return colander.null
|
||||
return six.text_type(appstruct)
|
||||
return str(appstruct)
|
||||
|
||||
def deserialize(self, node, cstruct):
|
||||
if not cstruct:
|
||||
return None
|
||||
obj = self.session.query(self.model_class).get(cstruct)
|
||||
obj = self.session.get(self.model_class, cstruct)
|
||||
if not obj:
|
||||
raise colander.Invalid(node, "{} not found".format(self.model_title))
|
||||
return obj
|
||||
|
|
|
@ -410,7 +410,7 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
|
|||
# fetch customer to provide button label, if we have a value
|
||||
if cstruct:
|
||||
model = self.request.rattail_config.get_model()
|
||||
customer = Session.query(model.Customer).get(cstruct)
|
||||
customer = Session.get(model.Customer, cstruct)
|
||||
if customer:
|
||||
self.field_display = str(customer)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue