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
tailbone/api
|
@ -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,13 +24,9 @@
|
|||
Tailbone Web API - Batch Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
import six
|
||||
|
||||
from cornice import Service
|
||||
|
||||
from tailbone.api import APIMasterView
|
||||
|
@ -104,25 +100,25 @@ class APIBatchView(APIBatchMixin, APIMasterView):
|
|||
|
||||
return {
|
||||
'uuid': batch.uuid,
|
||||
'_str': six.text_type(batch),
|
||||
'_str': str(batch),
|
||||
'id': batch.id,
|
||||
'id_str': batch.id_str,
|
||||
'description': batch.description,
|
||||
'notes': batch.notes,
|
||||
'params': batch.params or {},
|
||||
'rowcount': batch.rowcount,
|
||||
'created': six.text_type(created),
|
||||
'created': str(created),
|
||||
'created_display': self.pretty_datetime(created),
|
||||
'created_by_uuid': batch.created_by.uuid,
|
||||
'created_by_display': six.text_type(batch.created_by),
|
||||
'created_by_display': str(batch.created_by),
|
||||
'complete': batch.complete,
|
||||
'status_code': batch.status_code,
|
||||
'status_display': batch.STATUS.get(batch.status_code,
|
||||
six.text_type(batch.status_code)),
|
||||
'executed': six.text_type(executed) if executed else None,
|
||||
str(batch.status_code)),
|
||||
'executed': str(executed) if executed else None,
|
||||
'executed_display': self.pretty_datetime(executed) if executed else None,
|
||||
'executed_by_uuid': batch.executed_by_uuid,
|
||||
'executed_by_display': six.text_type(batch.executed_by or ''),
|
||||
'executed_by_display': str(batch.executed_by or ''),
|
||||
'mutable': self.batch_handler.is_mutable(batch),
|
||||
}
|
||||
|
||||
|
@ -273,8 +269,8 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
|
|||
batch = row.batch
|
||||
return {
|
||||
'uuid': row.uuid,
|
||||
'_str': six.text_type(row),
|
||||
'_parent_str': six.text_type(batch),
|
||||
'_str': str(row),
|
||||
'_parent_str': str(batch),
|
||||
'_parent_uuid': batch.uuid,
|
||||
'batch_uuid': batch.uuid,
|
||||
'batch_id': batch.id,
|
||||
|
@ -285,7 +281,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
|
|||
'batch_mutable': self.batch_handler.is_mutable(batch),
|
||||
'sequence': row.sequence,
|
||||
'status_code': row.status_code,
|
||||
'status_display': row.STATUS.get(row.status_code, six.text_type(row.status_code)),
|
||||
'status_display': row.STATUS.get(row.status_code, str(row.status_code)),
|
||||
}
|
||||
|
||||
def update_object(self, row, data):
|
||||
|
@ -320,7 +316,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
|
|||
data = self.request.json_body
|
||||
|
||||
uuid = data['batch_uuid']
|
||||
batch = self.Session.query(self.get_batch_class()).get(uuid)
|
||||
batch = self.Session.get(self.get_batch_class(), uuid)
|
||||
if not batch:
|
||||
raise self.notfound()
|
||||
|
||||
|
@ -332,7 +328,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
|
|||
log.warning("quick entry failed for '%s' batch %s: %s",
|
||||
self.batch_handler.batch_key, batch.id_str, entry,
|
||||
exc_info=True)
|
||||
msg = six.text_type(error)
|
||||
msg = str(error)
|
||||
if not msg and isinstance(error, NotImplementedError):
|
||||
msg = "Feature is not implemented"
|
||||
return {'error': msg}
|
||||
|
|
|
@ -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,11 +24,8 @@
|
|||
Tailbone Web API - Receiving Batches
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
import humanize
|
||||
|
||||
from rattail.db import model
|
||||
|
@ -64,10 +61,10 @@ class ReceivingBatchViews(APIBatchView):
|
|||
data = super(ReceivingBatchViews, self).normalize(batch)
|
||||
|
||||
data['vendor_uuid'] = batch.vendor.uuid
|
||||
data['vendor_display'] = six.text_type(batch.vendor)
|
||||
data['vendor_display'] = str(batch.vendor)
|
||||
|
||||
data['department_uuid'] = batch.department_uuid
|
||||
data['department_display'] = six.text_type(batch.department) if batch.department else None
|
||||
data['department_display'] = str(batch.department) if batch.department else None
|
||||
|
||||
data['po_total'] = batch.po_total
|
||||
data['invoice_total'] = batch.invoice_total
|
||||
|
@ -115,7 +112,7 @@ class ReceivingBatchViews(APIBatchView):
|
|||
|
||||
def eligible_purchases(self):
|
||||
uuid = self.request.params.get('vendor_uuid')
|
||||
vendor = self.Session.query(model.Vendor).get(uuid) if uuid else None
|
||||
vendor = self.Session.get(model.Vendor, uuid) if uuid else None
|
||||
if not vendor:
|
||||
return {'error': "Vendor not found"}
|
||||
|
||||
|
@ -289,7 +286,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
|
|||
|
||||
data['product_uuid'] = row.product_uuid
|
||||
data['item_id'] = row.item_id
|
||||
data['upc'] = six.text_type(row.upc)
|
||||
data['upc'] = str(row.upc)
|
||||
data['upc_pretty'] = row.upc.pretty() if row.upc else None
|
||||
data['brand_name'] = row.brand_name
|
||||
data['description'] = row.description
|
||||
|
@ -415,7 +412,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
|
|||
return {'error': "Form did not validate"}
|
||||
|
||||
# fetch / validate row object
|
||||
row = self.Session.query(model.PurchaseBatchRow).get(form.validated['row'])
|
||||
row = self.Session.get(model.PurchaseBatchRow, form.validated['row'])
|
||||
if row is not self.get_object():
|
||||
return {'error': "Specified row does not match the route!"}
|
||||
|
||||
|
|
|
@ -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 @@
|
|||
Tailbone Web API - "Common" Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import rattail
|
||||
from rattail.db import model
|
||||
from rattail.mail import send_email
|
||||
|
@ -97,7 +95,7 @@ class CommonView(APIView):
|
|||
if self.request.user:
|
||||
data['user'] = self.request.user
|
||||
elif data['user']:
|
||||
data['user'] = Session.query(model.User).get(data['user'])
|
||||
data['user'] = Session.get(model.User, data['user'])
|
||||
|
||||
# TODO: should provide URL to view user
|
||||
if data['user']:
|
||||
|
|
|
@ -339,7 +339,7 @@ class APIMasterView(APIView):
|
|||
if not uuid:
|
||||
uuid = self.request.matchdict['uuid']
|
||||
|
||||
obj = self.Session.query(self.get_model_class()).get(uuid)
|
||||
obj = self.Session.get(self.get_model_class(), uuid)
|
||||
if obj:
|
||||
return obj
|
||||
|
||||
|
@ -390,7 +390,7 @@ class APIMasterView(APIView):
|
|||
"""
|
||||
if not uuid:
|
||||
uuid = self.request.matchdict['uuid']
|
||||
obj = self.Session.query(self.get_model_class()).get(uuid)
|
||||
obj = self.Session.get(self.get_model_class(), uuid)
|
||||
if not obj:
|
||||
raise self.notfound()
|
||||
|
||||
|
|
|
@ -24,11 +24,8 @@
|
|||
Tailbone Web API - Product Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
|
@ -84,7 +81,7 @@ class ProductView(APIMasterView):
|
|||
# but must supplement
|
||||
cost = product.cost
|
||||
data.update({
|
||||
'upc': six.text_type(product.upc),
|
||||
'upc': str(product.upc),
|
||||
'scancode': product.scancode,
|
||||
'item_id': product.item_id,
|
||||
'item_type': product.item_type,
|
||||
|
@ -135,12 +132,12 @@ class ProductView(APIMasterView):
|
|||
data = self.request.json_body
|
||||
|
||||
uuid = data.get('label_profile_uuid')
|
||||
profile = self.Session.query(model.LabelProfile).get(uuid) if uuid else None
|
||||
profile = self.Session.get(model.LabelProfile, uuid) if uuid else None
|
||||
if not profile:
|
||||
return {'error': "Label profile not found"}
|
||||
|
||||
uuid = data.get('product_uuid')
|
||||
product = self.Session.query(model.Product).get(uuid) if uuid else None
|
||||
product = self.Session.get(model.Product, uuid) if uuid else None
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -157,7 +154,7 @@ class ProductView(APIMasterView):
|
|||
printer.print_labels([({'product': product}, quantity)])
|
||||
except Exception as error:
|
||||
log.warning("error occurred while printing labels", exc_info=True)
|
||||
return {'error': six.text_type(error)}
|
||||
return {'error': str(error)}
|
||||
|
||||
return {'ok': True}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue