Refactor Query.get()
=> Session.get()
per SQLAlchemy 1.4
This commit is contained in:
parent
81aa0ae109
commit
f611a5a521
|
@ -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}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,8 +24,6 @@
|
|||
Authentication & Authorization
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from rattail import enum
|
||||
|
@ -107,7 +105,7 @@ class TailboneAuthorizationPolicy(object):
|
|||
# re-creating the database, which means new user uuids.
|
||||
# TODO: the odds of this query returning a user in that
|
||||
# case, are probably nil, and we should just skip this bit?
|
||||
user = Session.query(model.User).get(userid)
|
||||
user = Session.get(model.User, userid)
|
||||
if user:
|
||||
if auth.has_permission(Session(), user, permission):
|
||||
return True
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ def new_request(event):
|
|||
uuid = request.authenticated_userid
|
||||
if uuid:
|
||||
model = request.rattail_config.get_model()
|
||||
user = Session.query(model.User).get(uuid)
|
||||
user = Session.get(model.User, uuid)
|
||||
if user:
|
||||
Session().set_continuum_user(user)
|
||||
return user
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -89,7 +89,7 @@ class WebsocketView(object):
|
|||
session=session) as s:
|
||||
|
||||
# load user proper
|
||||
return s.query(model.User).get(user_uuid)
|
||||
return s.get(model.User, user_uuid)
|
||||
|
||||
def get_user_session(self, scope):
|
||||
settings = self.registry.settings
|
||||
|
|
|
@ -32,7 +32,6 @@ import logging
|
|||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
from six import StringIO
|
||||
|
||||
import json
|
||||
import markdown
|
||||
|
@ -236,7 +235,7 @@ class BatchMasterView(MasterView):
|
|||
Thread target for updating a batch from worksheet.
|
||||
"""
|
||||
session = self.make_isolated_session()
|
||||
batch = session.query(self.model_class).get(batch_uuid)
|
||||
batch = session.get(self.model_class, batch_uuid)
|
||||
try:
|
||||
self.handler.update_from_worksheet(batch, path, progress=progress)
|
||||
|
||||
|
@ -1020,7 +1019,7 @@ class BatchMasterView(MasterView):
|
|||
|
||||
def catchup_versions(self, port, batch_uuid, username, *models):
|
||||
with short_session() as s:
|
||||
batch = s.query(self.model_class).get(batch_uuid)
|
||||
batch = s.get(self.model_class, batch_uuid)
|
||||
batch_id = batch.id_str
|
||||
description = str(batch)
|
||||
|
||||
|
@ -1047,8 +1046,8 @@ class BatchMasterView(MasterView):
|
|||
"""
|
||||
# mustn't use tailbone web session here
|
||||
session = RattailSession()
|
||||
batch = session.query(self.model_class).get(batch_uuid)
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
batch = session.get(self.model_class, batch_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
self.handler.do_populate(batch, user, progress=progress)
|
||||
session.flush()
|
||||
|
@ -1104,8 +1103,8 @@ class BatchMasterView(MasterView):
|
|||
# rattail session here; can't use tailbone because it has web request
|
||||
# transaction binding etc.
|
||||
session = RattailSession()
|
||||
batch = session.query(self.model_class).get(batch_uuid)
|
||||
cognizer = session.query(model.User).get(user_uuid) if user_uuid else None
|
||||
batch = session.get(self.model_class, batch_uuid)
|
||||
cognizer = session.get(model.User, user_uuid) if user_uuid else None
|
||||
try:
|
||||
self.refresh_data(session, batch, cognizer, progress=progress)
|
||||
session.flush()
|
||||
|
@ -1158,7 +1157,7 @@ class BatchMasterView(MasterView):
|
|||
"""
|
||||
session = RattailSession()
|
||||
batches = batches.with_session(session).all()
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
self.handler.refresh_many(batches, user=user, progress=progress)
|
||||
|
||||
|
@ -1298,7 +1297,7 @@ class BatchMasterView(MasterView):
|
|||
# transaction binding etc.
|
||||
session = RattailSession()
|
||||
batch = self.get_instance_for_key(key, session)
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
result = self.handler.do_execute(batch, user=user, progress=progress, **kwargs)
|
||||
|
||||
|
@ -1373,7 +1372,7 @@ class BatchMasterView(MasterView):
|
|||
"""
|
||||
session = RattailSession()
|
||||
batches = batches.with_session(session).all()
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
result = self.handler.execute_many(batches, user=user, progress=progress, **kwargs)
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class ImporterBatchView(BatchMasterView):
|
|||
|
||||
def get_parent(self, row):
|
||||
uuid = self.current_row_table.name
|
||||
return self.Session.query(model.ImporterBatch).get(uuid)
|
||||
return self.Session.get(model.ImporterBatch, uuid)
|
||||
|
||||
def get_row_instance_title(self, row):
|
||||
if row.object_str:
|
||||
|
|
|
@ -214,7 +214,7 @@ class InventoryBatchView(BatchMasterView):
|
|||
return super(InventoryBatchView, self).save_edit_row_form(form)
|
||||
|
||||
def delete_row(self):
|
||||
row = self.Session.query(model.InventoryBatchRow).get(self.request.matchdict['row_uuid'])
|
||||
row = self.Session.get(model.InventoryBatchRow, self.request.matchdict['row_uuid'])
|
||||
if not row:
|
||||
raise self.notfound()
|
||||
batch = row.batch
|
||||
|
@ -235,7 +235,7 @@ class InventoryBatchView(BatchMasterView):
|
|||
if self.request.method == 'POST':
|
||||
if form.validate(newstyle=True):
|
||||
|
||||
product = self.Session.query(model.Product).get(form.validated['product'])
|
||||
product = self.Session.get(model.Product, form.validated['product'])
|
||||
|
||||
row = None
|
||||
if self.should_aggregate_products(batch):
|
||||
|
@ -515,7 +515,7 @@ class InventoryBatchView(BatchMasterView):
|
|||
def valid_product(node, kw):
|
||||
session = kw['session']
|
||||
def validate(node, value):
|
||||
product = session.query(model.Product).get(value)
|
||||
product = session.get(model.Product, value)
|
||||
if not product:
|
||||
raise colander.Invalid(node, "Product not found")
|
||||
return product.uuid
|
||||
|
|
|
@ -225,8 +225,8 @@ class VendorCatalogView(FileBatchMasterView):
|
|||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor_uuid'):
|
||||
vendor = self.Session.query(model.Vendor).get(
|
||||
self.request.POST['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor,
|
||||
self.request.POST['vendor_uuid'])
|
||||
if vendor:
|
||||
vendor_display = str(vendor)
|
||||
f.set_widget('vendor_uuid',
|
||||
|
|
|
@ -163,7 +163,7 @@ class CommonView(View):
|
|||
if form.validate(newstyle=True):
|
||||
data = dict(form.validated)
|
||||
if data['user']:
|
||||
data['user'] = Session.query(model.User).get(data['user'])
|
||||
data['user'] = Session.get(model.User, data['user'])
|
||||
data['user_url'] = self.request.route_url('users.view', uuid=data['user'].uuid)
|
||||
data['client_ip'] = self.request.client_addr
|
||||
app.send_email('user_feedback', data=data)
|
||||
|
|
|
@ -97,7 +97,7 @@ class View(object):
|
|||
if self.request.method == 'POST':
|
||||
uuid = self.request.POST.get('late-login-user')
|
||||
if uuid:
|
||||
return Session.query(model.User).get(uuid)
|
||||
return Session.get(model.User, uuid)
|
||||
|
||||
def user_is_protected(self, user):
|
||||
"""
|
||||
|
|
|
@ -187,12 +187,12 @@ class CustomerView(MasterView):
|
|||
return instance
|
||||
|
||||
# search by CustomerPerson.uuid
|
||||
instance = self.Session.query(model.CustomerPerson).get(key)
|
||||
instance = self.Session.get(model.CustomerPerson, key)
|
||||
if instance:
|
||||
return instance.customer
|
||||
|
||||
# search by CustomerGroupAssignment.uuid
|
||||
instance = self.Session.query(model.CustomerGroupAssignment).get(key)
|
||||
instance = self.Session.get(model.CustomerGroupAssignment, key)
|
||||
if instance:
|
||||
return instance.customer
|
||||
|
||||
|
@ -438,7 +438,7 @@ class CustomerView(MasterView):
|
|||
|
||||
def detach_person(self):
|
||||
customer = self.get_instance()
|
||||
person = self.Session.query(model.Person).get(self.request.matchdict['person_uuid'])
|
||||
person = self.Session.get(model.Person, self.request.matchdict['person_uuid'])
|
||||
if not person:
|
||||
return self.notfound()
|
||||
|
||||
|
@ -612,7 +612,7 @@ class PendingCustomerView(MasterView):
|
|||
redirect = self.redirect(self.get_action_url('view', pending))
|
||||
|
||||
uuid = self.request.POST['person_uuid']
|
||||
person = self.Session.query(model.Person).get(uuid)
|
||||
person = self.Session.get(model.Person, uuid)
|
||||
if not person:
|
||||
self.request.session.flash("Person not found!", 'error')
|
||||
return redirect
|
||||
|
@ -670,7 +670,7 @@ def customer_info(request):
|
|||
View which returns simple dictionary of info for a particular customer.
|
||||
"""
|
||||
uuid = request.params.get('uuid')
|
||||
customer = Session.query(model.Customer).get(uuid) if uuid else None
|
||||
customer = Session.get(model.Customer, uuid) if uuid else None
|
||||
if not customer:
|
||||
return {}
|
||||
return {
|
||||
|
|
|
@ -408,7 +408,7 @@ class CustomerOrderItemView(MasterView):
|
|||
uuids = self.request.POST['uuids']
|
||||
if uuids:
|
||||
for uuid in uuids.split(','):
|
||||
item = self.Session.query(model.CustomerOrderItem).get(uuid)
|
||||
item = self.Session.get(model.CustomerOrderItem, uuid)
|
||||
if item:
|
||||
order_items.append(item)
|
||||
|
||||
|
|
|
@ -24,12 +24,9 @@
|
|||
Customer Order Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import decimal
|
||||
import logging
|
||||
|
||||
import six
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db import model
|
||||
|
@ -195,7 +192,7 @@ class CustomerOrderView(MasterView):
|
|||
person = order.person
|
||||
if not person:
|
||||
return ""
|
||||
text = six.text_type(person)
|
||||
text = str(person)
|
||||
url = self.request.route_url('people.view', uuid=person.uuid)
|
||||
return tags.link_to(text, url)
|
||||
|
||||
|
@ -203,7 +200,7 @@ class CustomerOrderView(MasterView):
|
|||
pending = batch.pending_customer
|
||||
if not pending:
|
||||
return
|
||||
text = six.text_type(pending)
|
||||
text = str(pending)
|
||||
url = self.request.route_url('pending_customers.view', uuid=pending.uuid)
|
||||
return tags.link_to(text, url,
|
||||
class_='has-background-warning')
|
||||
|
@ -275,7 +272,7 @@ class CustomerOrderView(MasterView):
|
|||
|
||||
def render_row_status_code(self, item, field):
|
||||
text = self.enum.CUSTORDER_ITEM_STATUS.get(item.status_code,
|
||||
six.text_type(item.status_code))
|
||||
str(item.status_code))
|
||||
if item.status_text:
|
||||
return HTML.tag('span', title=item.status_text, c=[text])
|
||||
return text
|
||||
|
@ -445,7 +442,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a customer UUID"}
|
||||
|
||||
customer = self.Session.query(model.Customer).get(uuid)
|
||||
customer = self.Session.get(model.Customer, uuid)
|
||||
if not customer:
|
||||
return {'error': "Customer not found"}
|
||||
|
||||
|
@ -472,14 +469,14 @@ class CustomerOrderView(MasterView):
|
|||
|
||||
if self.batch_handler.new_order_requires_customer():
|
||||
|
||||
customer = self.Session.query(model.Customer).get(uuid)
|
||||
customer = self.Session.get(model.Customer, uuid)
|
||||
if not customer:
|
||||
return {'error': "Customer not found"}
|
||||
kwargs['customer'] = customer
|
||||
|
||||
else:
|
||||
|
||||
person = self.Session.query(model.Person).get(uuid)
|
||||
person = self.Session.get(model.Person, uuid)
|
||||
if not person:
|
||||
return {'error': "Person not found"}
|
||||
kwargs['person'] = person
|
||||
|
@ -488,7 +485,7 @@ class CustomerOrderView(MasterView):
|
|||
try:
|
||||
self.batch_handler.assign_contact(batch, **kwargs)
|
||||
except ValueError as error:
|
||||
return {'error': six.text_type(error)}
|
||||
return {'error': str(error)}
|
||||
|
||||
self.Session.flush()
|
||||
context = self.get_context_contact(batch)
|
||||
|
@ -590,7 +587,7 @@ class CustomerOrderView(MasterView):
|
|||
self.batch_handler.update_pending_customer(batch, self.request.user,
|
||||
data)
|
||||
except Exception as error:
|
||||
return {'error': six.text_type(error)}
|
||||
return {'error': str(error)}
|
||||
|
||||
self.Session.flush()
|
||||
context = self.get_context_contact(batch)
|
||||
|
@ -619,7 +616,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a product UUID"}
|
||||
|
||||
product = self.Session.query(model.Product).get(uuid)
|
||||
product = self.Session.get(model.Product, uuid)
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -635,7 +632,7 @@ class CustomerOrderView(MasterView):
|
|||
try:
|
||||
info = self.batch_handler.get_product_info(batch, product)
|
||||
except Exception as error:
|
||||
return {'error': six.text_type(error)}
|
||||
return {'error': str(error)}
|
||||
else:
|
||||
info['url'] = self.request.route_url('products.view', uuid=info['uuid'])
|
||||
app = self.get_rattail_app()
|
||||
|
@ -661,7 +658,7 @@ class CustomerOrderView(MasterView):
|
|||
def normalize_batch(self, batch):
|
||||
return {
|
||||
'uuid': batch.uuid,
|
||||
'total_price': six.text_type(batch.total_price or 0),
|
||||
'total_price': str(batch.total_price or 0),
|
||||
'total_price_display': "${:0.2f}".format(batch.total_price or 0),
|
||||
'status_code': batch.status_code,
|
||||
'status_text': batch.status_text,
|
||||
|
@ -690,7 +687,7 @@ class CustomerOrderView(MasterView):
|
|||
'sequence': row.sequence,
|
||||
'item_entry': row.item_entry,
|
||||
'product_uuid': row.product_uuid,
|
||||
'product_upc': six.text_type(row.product_upc or ''),
|
||||
'product_upc': str(row.product_upc or ''),
|
||||
'product_item_id': row.product_item_id,
|
||||
'product_scancode': row.product_scancode,
|
||||
'product_upc_pretty': row.product_upc.pretty() if row.product_upc else None,
|
||||
|
@ -727,7 +724,7 @@ class CustomerOrderView(MasterView):
|
|||
data['unit_sale_price_display'] = app.render_currency(row.unit_sale_price)
|
||||
if row.sale_ends:
|
||||
sale_ends = app.localtime(row.sale_ends, from_utc=True).date()
|
||||
data['sale_ends'] = six.text_type(sale_ends)
|
||||
data['sale_ends'] = str(sale_ends)
|
||||
data['sale_ends_display'] = app.render_date(sale_ends)
|
||||
|
||||
if row.unit_sale_price and row.unit_price == row.unit_sale_price:
|
||||
|
@ -748,7 +745,7 @@ class CustomerOrderView(MasterView):
|
|||
pending = row.pending_product
|
||||
data['pending_product'] = {
|
||||
'uuid': pending.uuid,
|
||||
'upc': six.text_type(pending.upc) if pending.upc is not None else None,
|
||||
'upc': str(pending.upc) if pending.upc is not None else None,
|
||||
'item_id': pending.item_id,
|
||||
'scancode': pending.scancode,
|
||||
'brand_name': pending.brand_name,
|
||||
|
@ -826,7 +823,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a product UUID"}
|
||||
|
||||
product = self.Session.query(model.Product).get(uuid)
|
||||
product = self.Session.get(model.Product, uuid)
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -871,7 +868,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a row UUID"}
|
||||
|
||||
row = self.Session.query(model.CustomerOrderBatchRow).get(uuid)
|
||||
row = self.Session.get(model.CustomerOrderBatchRow, uuid)
|
||||
if not row:
|
||||
return {'error': "Row not found"}
|
||||
|
||||
|
@ -888,7 +885,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a product UUID"}
|
||||
|
||||
product = self.Session.query(model.Product).get(uuid)
|
||||
product = self.Session.get(model.Product, uuid)
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -929,7 +926,7 @@ class CustomerOrderView(MasterView):
|
|||
if not uuid:
|
||||
return {'error': "Must specify a row UUID"}
|
||||
|
||||
row = self.Session.query(model.CustomerOrderBatchRow).get(uuid)
|
||||
row = self.Session.get(model.CustomerOrderBatchRow, uuid)
|
||||
if not row:
|
||||
return {'error': "Row not found"}
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ class EmployeeView(MasterView):
|
|||
employee._stores.append(model.EmployeeStore(store_uuid=uuid))
|
||||
for uuid in old_stores:
|
||||
if uuid not in new_stores:
|
||||
store = self.Session.query(model.Store).get(uuid)
|
||||
store = self.Session.get(model.Store, uuid)
|
||||
employee.stores.remove(store)
|
||||
|
||||
def update_departments(self, employee, data):
|
||||
|
@ -262,7 +262,7 @@ class EmployeeView(MasterView):
|
|||
employee._departments.append(model.EmployeeDepartment(department_uuid=uuid))
|
||||
for uuid in old_depts:
|
||||
if uuid not in new_depts:
|
||||
dept = self.Session.query(model.Department).get(uuid)
|
||||
dept = self.Session.get(model.Department, uuid)
|
||||
employee.departments.remove(dept)
|
||||
|
||||
def get_possible_stores(self):
|
||||
|
|
|
@ -1024,7 +1024,7 @@ class MasterView(View):
|
|||
"""
|
||||
# mustn't use tailbone web session here
|
||||
session = RattailSession()
|
||||
obj = session.query(self.model_class).get(uuid)
|
||||
obj = session.get(self.model_class, uuid)
|
||||
try:
|
||||
self.populate_object(session, obj, progress=progress)
|
||||
except Exception as error:
|
||||
|
@ -1727,7 +1727,7 @@ class MasterView(View):
|
|||
if uuids:
|
||||
uuids = uuids.split(',')
|
||||
# TODO: probably need to allow override of fetcher callable
|
||||
fetcher = lambda uuid: self.Session.query(self.model_class).get(uuid)
|
||||
fetcher = lambda uuid: self.Session.get(self.model_class, uuid)
|
||||
objects = []
|
||||
for uuid in uuids:
|
||||
obj = fetcher(uuid)
|
||||
|
@ -1856,7 +1856,7 @@ class MasterView(View):
|
|||
model_key = self.get_model_key(as_tuple=True)
|
||||
if len(model_key) == 1 and model_key[0] == 'uuid':
|
||||
uuid = key[0]
|
||||
return session.query(self.model_class).get(uuid)
|
||||
return session.get(self.model_class, uuid)
|
||||
raise NotImplementedError
|
||||
|
||||
def execute_thread(self, key, user_uuid, progress=None, **kwargs):
|
||||
|
@ -1865,7 +1865,7 @@ class MasterView(View):
|
|||
"""
|
||||
session = RattailSession()
|
||||
obj = self.get_instance_for_key(key, session)
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
success_msg = self.execute_instance(obj, user,
|
||||
progress=progress,
|
||||
|
@ -2021,8 +2021,8 @@ class MasterView(View):
|
|||
if self.request.method == 'POST':
|
||||
uuids = self.request.POST.get('uuids', '').split(',')
|
||||
if len(uuids) == 2:
|
||||
object_to_remove = self.Session.query(self.get_model_class()).get(uuids[0])
|
||||
object_to_keep = self.Session.query(self.get_model_class()).get(uuids[1])
|
||||
object_to_remove = self.Session.get(self.get_model_class(), uuids[0])
|
||||
object_to_keep = self.Session.get(self.get_model_class(), uuids[1])
|
||||
|
||||
if object_to_remove and object_to_keep and self.request.POST.get('commit-merge') == 'yes':
|
||||
msg = str(object_to_remove)
|
||||
|
@ -4447,7 +4447,7 @@ class MasterView(View):
|
|||
# TODO: is this right..?
|
||||
# key = self.request.matchdict[self.get_model_key()]
|
||||
key = self.request.matchdict['row_uuid']
|
||||
instance = self.Session.query(self.model_row_class).get(key)
|
||||
instance = self.Session.get(self.model_row_class, key)
|
||||
if not instance:
|
||||
raise self.notfound()
|
||||
return instance
|
||||
|
|
|
@ -279,7 +279,7 @@ class MessageView(MasterView):
|
|||
message.sender = self.request.user
|
||||
|
||||
for uuid in data['set_recipients']:
|
||||
user = self.Session.query(model.User).get(uuid)
|
||||
user = self.Session.get(model.User, uuid)
|
||||
if user:
|
||||
message.add_recipient(user, status=self.enum.MESSAGE_STATUS_INBOX)
|
||||
|
||||
|
|
|
@ -171,10 +171,10 @@ class PersonView(MasterView):
|
|||
# TODO: I don't recall why this fallback check for a vendor contact
|
||||
# exists here, but leaving it intact for now.
|
||||
key = self.request.matchdict['uuid']
|
||||
instance = self.Session.query(model.Person).get(key)
|
||||
instance = self.Session.get(model.Person, key)
|
||||
if instance:
|
||||
return instance
|
||||
instance = self.Session.query(model.VendorContact).get(key)
|
||||
instance = self.Session.get(model.VendorContact, key)
|
||||
if instance:
|
||||
return instance.person
|
||||
raise HTTPNotFound
|
||||
|
@ -677,7 +677,7 @@ class PersonView(MasterView):
|
|||
person = self.get_instance()
|
||||
data = dict(self.request.json_body)
|
||||
|
||||
phone = self.Session.query(model.PersonPhoneNumber).get(data['phone_uuid'])
|
||||
phone = self.Session.get(model.PersonPhoneNumber, data['phone_uuid'])
|
||||
if not phone:
|
||||
return {'error': "Phone not found."}
|
||||
|
||||
|
@ -708,7 +708,7 @@ class PersonView(MasterView):
|
|||
data = dict(self.request.json_body)
|
||||
|
||||
# validate phone
|
||||
phone = self.Session.query(model.PersonPhoneNumber).get(data['phone_uuid'])
|
||||
phone = self.Session.get(model.PersonPhoneNumber, data['phone_uuid'])
|
||||
if not phone:
|
||||
return {'error': "Phone not found."}
|
||||
if phone not in person.phones:
|
||||
|
@ -731,7 +731,7 @@ class PersonView(MasterView):
|
|||
data = dict(self.request.json_body)
|
||||
|
||||
# validate phone
|
||||
phone = self.Session.query(model.PersonPhoneNumber).get(data['phone_uuid'])
|
||||
phone = self.Session.get(model.PersonPhoneNumber, data['phone_uuid'])
|
||||
if not phone:
|
||||
return {'error': "Phone not found."}
|
||||
if phone not in person.phones:
|
||||
|
@ -792,7 +792,7 @@ class PersonView(MasterView):
|
|||
person = self.get_instance()
|
||||
data = dict(self.request.json_body)
|
||||
|
||||
email = self.Session.query(model.PersonEmailAddress).get(data['email_uuid'])
|
||||
email = self.Session.get(model.PersonEmailAddress, data['email_uuid'])
|
||||
if not email:
|
||||
return {'error': "Email not found."}
|
||||
|
||||
|
@ -819,7 +819,7 @@ class PersonView(MasterView):
|
|||
data = dict(self.request.json_body)
|
||||
|
||||
# validate email
|
||||
email = self.Session.query(model.PersonEmailAddress).get(data['email_uuid'])
|
||||
email = self.Session.get(model.PersonEmailAddress, data['email_uuid'])
|
||||
if not email:
|
||||
return {'error': "Email not found."}
|
||||
if email not in person.emails:
|
||||
|
@ -843,7 +843,7 @@ class PersonView(MasterView):
|
|||
data = dict(self.request.json_body)
|
||||
|
||||
# validate email
|
||||
email = self.Session.query(model.PersonEmailAddress).get(data['email_uuid'])
|
||||
email = self.Session.get(model.PersonEmailAddress, data['email_uuid'])
|
||||
if not email:
|
||||
return {'error': "Email not found."}
|
||||
if email not in person.emails:
|
||||
|
@ -944,7 +944,7 @@ class PersonView(MasterView):
|
|||
employee = person.employee
|
||||
|
||||
uuid = self.request.json_body['uuid']
|
||||
history = self.Session.query(model.EmployeeHistory).get(uuid)
|
||||
history = self.Session.get(model.EmployeeHistory, uuid)
|
||||
if not history or history not in employee.history:
|
||||
return {'error': "Must specify a valid Employee History record for this Person."}
|
||||
|
||||
|
@ -1032,7 +1032,7 @@ class PersonView(MasterView):
|
|||
return self.profile_edit_note_failure(person, form)
|
||||
|
||||
def update_note(self, person, form):
|
||||
note = self.Session.query(model.PersonNote).get(form.validated['uuid'])
|
||||
note = self.Session.get(model.PersonNote, form.validated['uuid'])
|
||||
note.subject = form.validated['note_subject']
|
||||
note.text = form.validated['note_text']
|
||||
return note
|
||||
|
@ -1054,7 +1054,7 @@ class PersonView(MasterView):
|
|||
return self.profile_delete_note_failure(person, form)
|
||||
|
||||
def delete_note(self, person, form):
|
||||
note = self.Session.query(model.PersonNote).get(form.validated['uuid'])
|
||||
note = self.Session.get(model.PersonNote, form.validated['uuid'])
|
||||
self.Session.delete(note)
|
||||
|
||||
def profile_delete_note_success(self, person):
|
||||
|
@ -1065,7 +1065,7 @@ class PersonView(MasterView):
|
|||
|
||||
def make_user(self):
|
||||
uuid = self.request.POST['person_uuid']
|
||||
person = self.Session.query(model.Person).get(uuid)
|
||||
person = self.Session.get(model.Person, uuid)
|
||||
if not person:
|
||||
return self.notfound()
|
||||
if person.users:
|
||||
|
@ -1355,7 +1355,7 @@ def valid_note_uuid(node, kw):
|
|||
session = kw['session']
|
||||
person_uuid = kw['person_uuid']
|
||||
def validate(node, value):
|
||||
note = session.query(model.PersonNote).get(value)
|
||||
note = session.get(model.PersonNote, value)
|
||||
if not note:
|
||||
raise colander.Invalid(node, "Note not found")
|
||||
if note.person.uuid != person_uuid:
|
||||
|
@ -1425,15 +1425,15 @@ class MergePeopleRequestView(MasterView):
|
|||
|
||||
def render_referenced_person_name(self, merge_request, field):
|
||||
uuid = getattr(merge_request, field)
|
||||
person = self.Session.query(self.model.Person).get(uuid)
|
||||
person = self.Session.get(self.model.Person, uuid)
|
||||
if person:
|
||||
return str(person)
|
||||
return "(person not found)"
|
||||
|
||||
def get_instance_title(self, merge_request):
|
||||
model = self.model
|
||||
removing = self.Session.query(model.Person).get(merge_request.removing_uuid)
|
||||
keeping = self.Session.query(model.Person).get(merge_request.keeping_uuid)
|
||||
removing = self.Session.get(model.Person, merge_request.removing_uuid)
|
||||
keeping = self.Session.get(model.Person, merge_request.keeping_uuid)
|
||||
return "{} -> {}".format(
|
||||
removing or "(not found)",
|
||||
keeping or "(not found)")
|
||||
|
@ -1446,7 +1446,7 @@ class MergePeopleRequestView(MasterView):
|
|||
|
||||
def render_referenced_person(self, merge_request, field):
|
||||
uuid = getattr(merge_request, field)
|
||||
person = self.Session.query(self.model.Person).get(uuid)
|
||||
person = self.Session.get(self.model.Person, uuid)
|
||||
if person:
|
||||
text = str(person)
|
||||
url = self.request.route_url('people.view', uuid=person.uuid)
|
||||
|
|
|
@ -808,10 +808,10 @@ class ProductView(MasterView):
|
|||
|
||||
def get_instance(self):
|
||||
key = self.request.matchdict['uuid']
|
||||
product = self.Session.query(model.Product).get(key)
|
||||
product = self.Session.get(model.Product, key)
|
||||
if product:
|
||||
return product
|
||||
price = self.Session.query(model.ProductPrice).get(key)
|
||||
price = self.Session.get(model.ProductPrice, key)
|
||||
if price:
|
||||
return price.product
|
||||
raise self.notfound()
|
||||
|
@ -956,7 +956,7 @@ class ProductView(MasterView):
|
|||
brand_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('brand_uuid'):
|
||||
brand = self.Session.query(model.Brand).get(self.request.POST['brand_uuid'])
|
||||
brand = self.Session.get(model.Brand, self.request.POST['brand_uuid'])
|
||||
if brand:
|
||||
brand_display = str(brand)
|
||||
elif self.editing:
|
||||
|
@ -1751,12 +1751,12 @@ class ProductView(MasterView):
|
|||
model = self.model
|
||||
|
||||
profile = self.request.params.get('profile')
|
||||
profile = self.Session.query(model.LabelProfile).get(profile) if profile else None
|
||||
profile = self.Session.get(model.LabelProfile, profile) if profile else None
|
||||
if not profile:
|
||||
return {'error': "Label profile not found"}
|
||||
|
||||
product = self.request.params.get('product')
|
||||
product = self.Session.query(model.Product).get(product) if product else None
|
||||
product = self.Session.get(model.Product, product) if product else None
|
||||
if not product:
|
||||
return {'error': "Product not found"}
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ class ProductView(MasterView):
|
|||
}
|
||||
uuid = self.request.GET.get('with_vendor_cost')
|
||||
if uuid:
|
||||
vendor = self.Session.query(model.Vendor).get(uuid)
|
||||
vendor = self.Session.get(model.Vendor, uuid)
|
||||
if not vendor:
|
||||
return {'error': "Vendor not found"}
|
||||
cost = product.cost_for_vendor(vendor)
|
||||
|
@ -2068,7 +2068,7 @@ class ProductView(MasterView):
|
|||
Threat target for making a batch from current products query.
|
||||
"""
|
||||
session = RattailSession()
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
assert user
|
||||
params['created_by'] = user
|
||||
try:
|
||||
|
@ -2288,7 +2288,7 @@ class PendingProductView(MasterView):
|
|||
brand_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('brand_uuid'):
|
||||
brand = self.Session.query(model.Brand).get(self.request.POST['brand_uuid'])
|
||||
brand = self.Session.get(model.Brand, self.request.POST['brand_uuid'])
|
||||
if brand:
|
||||
brand_display = str(brand)
|
||||
elif self.editing:
|
||||
|
@ -2315,7 +2315,7 @@ class PendingProductView(MasterView):
|
|||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor_uuid'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor, self.request.POST['vendor_uuid'])
|
||||
if vendor:
|
||||
vendor_display = str(vendor)
|
||||
f.set_widget('vendor_uuid', forms.widgets.JQueryAutocompleteWidget(
|
||||
|
@ -2414,7 +2414,7 @@ class PendingProductView(MasterView):
|
|||
redirect = self.redirect(self.get_action_url('view', pending))
|
||||
|
||||
uuid = self.request.POST['product_uuid']
|
||||
product = self.Session.query(model.Product).get(uuid)
|
||||
product = self.Session.get(model.Product, uuid)
|
||||
if not product:
|
||||
self.request.session.flash("Product not found!", 'error')
|
||||
return redirect
|
||||
|
|
|
@ -150,7 +150,7 @@ class PurchaseCreditView(MasterView):
|
|||
for uuid in self.request.POST.get('uuids', '').split(','):
|
||||
uuid = uuid.strip()
|
||||
if uuid:
|
||||
credit = self.Session.query(model.PurchaseCredit).get(uuid)
|
||||
credit = self.Session.get(model.PurchaseCredit, uuid)
|
||||
if credit:
|
||||
credits_.append(credit)
|
||||
if not credits_:
|
||||
|
|
|
@ -271,7 +271,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor_uuid'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor, self.request.POST['vendor_uuid'])
|
||||
if vendor:
|
||||
vendor_display = str(vendor)
|
||||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
|
@ -304,7 +304,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
buyer_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('buyer_uuid'):
|
||||
buyer = self.Session.query(model.Employee).get(self.request.POST['buyer_uuid'])
|
||||
buyer = self.Session.get(model.Employee, self.request.POST['buyer_uuid'])
|
||||
if buyer:
|
||||
buyer_display = str(buyer)
|
||||
elif self.creating:
|
||||
|
@ -331,8 +331,8 @@ class PurchasingBatchView(BatchMasterView):
|
|||
kwargs = {}
|
||||
|
||||
if 'vendor_uuid' in self.request.matchdict:
|
||||
vendor = self.Session.query(model.Vendor).get(
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor,
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
if vendor:
|
||||
kwargs['vendor'] = vendor
|
||||
|
||||
|
@ -397,7 +397,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
|
||||
def valid_vendor_uuid(self, node, value):
|
||||
model = self.model
|
||||
vendor = self.Session.query(model.Vendor).get(value)
|
||||
vendor = self.Session.get(model.Vendor, value)
|
||||
if not vendor:
|
||||
raise colander.Invalid(node, "Invalid vendor selection")
|
||||
|
||||
|
@ -495,7 +495,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
def eligible_purchases(self, vendor_uuid=None, mode=None):
|
||||
if not vendor_uuid:
|
||||
vendor_uuid = self.request.GET.get('vendor_uuid')
|
||||
vendor = self.Session.query(model.Vendor).get(vendor_uuid) if vendor_uuid else None
|
||||
vendor = self.Session.get(model.Vendor, vendor_uuid) if vendor_uuid else None
|
||||
if not vendor:
|
||||
return {'error': "Must specify a vendor."}
|
||||
|
||||
|
@ -572,7 +572,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
self.enum.PURCHASE_BATCH_MODE_COSTING):
|
||||
purchase = batch.purchase
|
||||
if not purchase and batch.purchase_uuid:
|
||||
purchase = self.Session.query(model.Purchase).get(batch.purchase_uuid)
|
||||
purchase = self.Session.get(model.Purchase, batch.purchase_uuid)
|
||||
assert purchase
|
||||
if purchase:
|
||||
kwargs['purchase'] = purchase
|
||||
|
|
|
@ -207,7 +207,7 @@ class CostingBatchView(PurchasingBatchView):
|
|||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor'])
|
||||
vendor = self.Session.get(model.Vendor, self.request.POST['vendor'])
|
||||
if vendor:
|
||||
vendor_display = str(vendor)
|
||||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
|
@ -258,8 +258,8 @@ class CostingBatchView(PurchasingBatchView):
|
|||
if self.creating and workflow:
|
||||
|
||||
# display vendor but do not allow changing
|
||||
vendor = self.Session.query(model.Vendor).get(
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor,
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
assert vendor
|
||||
|
||||
f.set_hidden('vendor_uuid')
|
||||
|
|
|
@ -241,7 +241,7 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
assert not (batch.executed or batch.complete)
|
||||
|
||||
uuid = data.get('row_uuid')
|
||||
row = self.Session.query(self.model_row_class).get(uuid) if uuid else None
|
||||
row = self.Session.get(self.model_row_class, uuid) if uuid else None
|
||||
if not row:
|
||||
return {'error': "Row not found"}
|
||||
if row.batch is not batch or row.removed:
|
||||
|
@ -401,7 +401,7 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
return {'error': "Invalid value for units ordered: {}".format(units_ordered)}
|
||||
|
||||
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"}
|
||||
|
||||
|
|
|
@ -280,7 +280,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
# someone e.g. navigates to a URL by accident etc. we want
|
||||
# to gracefully handle and redirect
|
||||
uuid = self.request.matchdict['vendor_uuid']
|
||||
vendor = self.Session.query(model.Vendor).get(uuid)
|
||||
vendor = self.Session.get(model.Vendor, uuid)
|
||||
if not vendor:
|
||||
self.request.session.flash("Invalid vendor selection. "
|
||||
"Please choose an existing vendor.",
|
||||
|
@ -337,7 +337,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor'])
|
||||
vendor = self.Session.get(model.Vendor, self.request.POST['vendor'])
|
||||
if vendor:
|
||||
vendor_display = str(vendor)
|
||||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
|
@ -417,8 +417,8 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if self.creating and workflow:
|
||||
|
||||
# display vendor but do not allow changing
|
||||
vendor = self.Session.query(model.Vendor).get(
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
vendor = self.Session.get(model.Vendor,
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
assert vendor
|
||||
f.set_readonly('vendor_uuid')
|
||||
f.set_default('vendor_uuid', str(vendor))
|
||||
|
@ -944,7 +944,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
def validate_purchase(node, kw):
|
||||
session = kw['session']
|
||||
def validate(node, value):
|
||||
purchase = session.query(model.Purchase).get(value)
|
||||
purchase = session.get(model.Purchase, value)
|
||||
if not purchase:
|
||||
raise colander.Invalid(node, "Purchase not found")
|
||||
return purchase.uuid
|
||||
|
@ -1439,7 +1439,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
credit = None
|
||||
uuid = data.get('uuid')
|
||||
if uuid:
|
||||
credit = self.Session.query(model.PurchaseBatchCredit).get(uuid)
|
||||
credit = self.Session.get(model.PurchaseBatchCredit, uuid)
|
||||
if not credit:
|
||||
return {'error': "Credit not found"}
|
||||
|
||||
|
@ -1479,7 +1479,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
batch = self.get_instance()
|
||||
|
||||
row_uuid = self.request.params.get('row_uuid')
|
||||
row = self.Session.query(model.PurchaseBatchRow).get(row_uuid) if row_uuid else None
|
||||
row = self.Session.get(model.PurchaseBatchRow, row_uuid) if row_uuid else None
|
||||
if row and row.batch is batch and not row.removed:
|
||||
pass # we're good
|
||||
else:
|
||||
|
@ -1841,7 +1841,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# validate row
|
||||
uuid = data.get('row_uuid')
|
||||
row = self.Session.query(model.PurchaseBatchRow).get(uuid) if uuid else None
|
||||
row = self.Session.get(model.PurchaseBatchRow, uuid) if uuid else None
|
||||
if not row or row.batch is not batch:
|
||||
return {'error': "Row not found"}
|
||||
|
||||
|
@ -1910,7 +1910,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
Thread target for receiving all items on the given batch.
|
||||
"""
|
||||
session = RattailSession()
|
||||
batch = session.query(model.PurchaseBatch).get(uuid)
|
||||
batch = session.get(model.PurchaseBatch, uuid)
|
||||
# user = session.query(model.User).get(user_uuid)
|
||||
try:
|
||||
self.handler.auto_receive_all_items(batch, progress=progress)
|
||||
|
|
|
@ -81,13 +81,13 @@ class OrderingWorksheet(View):
|
|||
|
||||
def __call__(self):
|
||||
if self.request.params.get('vendor'):
|
||||
vendor = Session.query(model.Vendor).get(self.request.params['vendor'])
|
||||
vendor = Session.get(model.Vendor, self.request.params['vendor'])
|
||||
if vendor:
|
||||
departments = []
|
||||
uuids = self.request.params.get('departments')
|
||||
if uuids:
|
||||
for uuid in uuids.split(','):
|
||||
dept = Session.query(model.Department).get(uuid)
|
||||
dept = Session.get(model.Department, uuid)
|
||||
if dept:
|
||||
departments.append(dept)
|
||||
preferred_only = self.request.params.get('preferred_only') == '1'
|
||||
|
@ -495,7 +495,7 @@ class ReportOutputView(ExportMasterView):
|
|||
object.
|
||||
"""
|
||||
session = RattailSession()
|
||||
user = session.query(model.User).get(user_uuid)
|
||||
user = session.get(model.User, user_uuid)
|
||||
try:
|
||||
output = self.report_handler.generate_output(session, report, params, user, progress=progress)
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ class SettingView(MasterView):
|
|||
f.set_validator('name', self.unique_name)
|
||||
|
||||
def unique_name(self, node, value):
|
||||
setting = self.Session.query(model.Setting).get(value)
|
||||
setting = self.Session.get(model.Setting, value)
|
||||
if setting:
|
||||
raise colander.Invalid(node, "Setting name must be unique")
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,11 +24,8 @@
|
|||
Base views for time sheets
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail import enum
|
||||
|
@ -105,10 +102,10 @@ class TimeSheetView(View):
|
|||
if store_key in self.request.session or department_key in self.request.session:
|
||||
store_uuid = self.request.session.get(store_key)
|
||||
if store_uuid:
|
||||
store = Session.query(model.Store).get(store_uuid) if store_uuid else None
|
||||
store = Session.get(model.Store, store_uuid) if store_uuid else None
|
||||
department_uuid = self.request.session.get(department_key)
|
||||
if department_uuid:
|
||||
department = Session.query(model.Department).get(department_uuid)
|
||||
department = Session.get(model.Department, department_uuid)
|
||||
else: # no store/department in session
|
||||
if self.default_filter_store:
|
||||
store = self.rattail_config.get('rattail', 'store')
|
||||
|
@ -151,7 +148,7 @@ class TimeSheetView(View):
|
|||
employee_key = 'timesheet.{}.employee'.format(self.key)
|
||||
if employee_key in self.request.session:
|
||||
employee_uuid = self.request.session[employee_key]
|
||||
employee = Session.query(model.Employee).get(employee_uuid) if employee_uuid else None
|
||||
employee = Session.get(model.Employee, employee_uuid) if employee_uuid else None
|
||||
if not employee:
|
||||
employee = self.request.user.employee
|
||||
|
||||
|
@ -238,7 +235,7 @@ class TimeSheetView(View):
|
|||
form = forms.Form(schema=EmployeeShiftFilter(), request=self.request)
|
||||
|
||||
if self.request.has_perm('{}.viewall'.format(permission_prefix)):
|
||||
employee_display = six.text_type(context['employee'] or '')
|
||||
employee_display = str(context['employee'] or '')
|
||||
employees_url = self.request.route_url('employees.autocomplete')
|
||||
form.set_widget('employee', forms.widgets.JQueryAutocompleteWidget(
|
||||
field_display=employee_display, service_url=employees_url))
|
||||
|
@ -470,7 +467,7 @@ class TimeSheetView(View):
|
|||
if hours_style == 'pretty':
|
||||
display = pretty_hours(hours)
|
||||
else: # decimal
|
||||
display = six.text_type(hours_as_decimal(hours))
|
||||
display = str(hours_as_decimal(hours))
|
||||
if empday['hours_incomplete']:
|
||||
display = '{} ?'.format(display)
|
||||
empday['{}_hours_display'.format(shift_type)] = display
|
||||
|
@ -481,7 +478,7 @@ class TimeSheetView(View):
|
|||
if hours_style == 'pretty':
|
||||
display = pretty_hours(hours)
|
||||
else: # decimal
|
||||
display = six.text_type(hours_as_decimal(hours))
|
||||
display = str(hours_as_decimal(hours))
|
||||
if hours_incomplete:
|
||||
display = '{} ?'.format(display)
|
||||
setattr(employee, '{}_hours_display'.format(shift_type), display)
|
||||
|
|
|
@ -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 @@
|
|||
Views for employee schedules
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
from rattail.db import model
|
||||
|
@ -81,7 +79,7 @@ class ScheduleView(TimeSheetView):
|
|||
deleted = []
|
||||
for uuid, value in data['delete'].items():
|
||||
if value == 'delete':
|
||||
shift = Session.query(model.ScheduledShift).get(uuid)
|
||||
shift = Session.get(model.ScheduledShift, uuid)
|
||||
if shift:
|
||||
Session.delete(shift)
|
||||
deleted.append(uuid)
|
||||
|
@ -103,7 +101,7 @@ class ScheduleView(TimeSheetView):
|
|||
Session.add(shift)
|
||||
created[uuid] = shift
|
||||
else:
|
||||
shift = Session.query(model.ScheduledShift).get(uuid)
|
||||
shift = Session.get(model.ScheduledShift, uuid)
|
||||
assert shift
|
||||
updated[uuid] = shift
|
||||
start_time = datetime.datetime.strptime(data['start_time'][uuid], time_format)
|
||||
|
|
|
@ -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 @@
|
|||
Views for employee time sheets
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
from rattail.db import model
|
||||
|
@ -74,7 +72,7 @@ class TimeSheetView(BaseTimeSheetView):
|
|||
deleted = []
|
||||
for uuid, value in list(data['delete'].items()):
|
||||
assert value == 'delete'
|
||||
shift = Session.query(model.WorkedShift).get(uuid)
|
||||
shift = Session.get(model.WorkedShift, uuid)
|
||||
assert shift
|
||||
Session.delete(shift)
|
||||
deleted.append(uuid)
|
||||
|
@ -93,7 +91,7 @@ class TimeSheetView(BaseTimeSheetView):
|
|||
Session.add(shift)
|
||||
created[uuid] = shift
|
||||
else:
|
||||
shift = Session.query(model.WorkedShift).get(uuid)
|
||||
shift = Session.get(model.WorkedShift, uuid)
|
||||
assert shift
|
||||
updated[uuid] = shift
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class TempmonDashboardView(View):
|
|||
appliance = None
|
||||
uuid = self.request.POST.get('appliance_uuid')
|
||||
if uuid:
|
||||
appliance = TempmonSession.query(tempmon.Appliance).get(uuid)
|
||||
appliance = TempmonSession.get(tempmon.Appliance, uuid)
|
||||
if appliance:
|
||||
self.request.session[self.session_key] = appliance.uuid
|
||||
if not appliance:
|
||||
|
@ -91,7 +91,7 @@ class TempmonDashboardView(View):
|
|||
uuid = self.request.params.get('appliance_uuid')
|
||||
if not uuid:
|
||||
return {'error': "Must specify valid appliance_uuid"}
|
||||
appliance = TempmonSession.query(tempmon.Appliance).get(uuid)
|
||||
appliance = TempmonSession.get(tempmon.Appliance, uuid)
|
||||
if not appliance:
|
||||
return {'error': "Must specify valid appliance_uuid"}
|
||||
|
||||
|
|
|
@ -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,9 +24,6 @@
|
|||
User Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
|
@ -168,7 +165,7 @@ class UserView(PrincipalMasterView):
|
|||
"""
|
||||
if value:
|
||||
model = self.model
|
||||
person = self.Session.query(model.Person).get(value)
|
||||
person = self.Session.get(model.Person, value)
|
||||
if not person:
|
||||
raise colander.Invalid(node, "Person not found (you must *select* a record)")
|
||||
|
||||
|
@ -189,11 +186,11 @@ class UserView(PrincipalMasterView):
|
|||
person_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('person_uuid'):
|
||||
person = self.Session.query(model.Person).get(self.request.POST['person_uuid'])
|
||||
person = self.Session.get(model.Person, self.request.POST['person_uuid'])
|
||||
if person:
|
||||
person_display = six.text_type(person)
|
||||
person_display = str(person)
|
||||
elif self.editing:
|
||||
person_display = six.text_type(user.person or '')
|
||||
person_display = str(user.person or '')
|
||||
people_url = self.request.route_url('people.autocomplete')
|
||||
f.set_widget('person_uuid', forms.widgets.JQueryAutocompleteWidget(
|
||||
field_display=person_display, service_url=people_url))
|
||||
|
@ -224,7 +221,7 @@ class UserView(PrincipalMasterView):
|
|||
f.remove_field('roles')
|
||||
else:
|
||||
roles = self.get_possible_roles().all()
|
||||
role_values = [(s.uuid, six.text_type(s)) for s in roles]
|
||||
role_values = [(s.uuid, str(s)) for s in roles]
|
||||
f.set_node('roles', colander.Set())
|
||||
size = len(roles)
|
||||
if size < 3:
|
||||
|
@ -358,7 +355,7 @@ class UserView(PrincipalMasterView):
|
|||
for uuid in old_roles:
|
||||
if uuid not in new_roles:
|
||||
if self.request.is_root or uuid != admin.uuid:
|
||||
role = self.Session.query(model.Role).get(uuid)
|
||||
role = self.Session.get(model.Role, uuid)
|
||||
user.roles.remove(role)
|
||||
|
||||
# also record a change to the role, for datasync.
|
||||
|
@ -373,7 +370,7 @@ class UserView(PrincipalMasterView):
|
|||
person = user.person
|
||||
if not person:
|
||||
return ""
|
||||
text = six.text_type(person)
|
||||
text = str(person)
|
||||
url = self.request.route_url('people.view', uuid=person.uuid)
|
||||
return tags.link_to(person, url)
|
||||
|
||||
|
@ -383,7 +380,7 @@ class UserView(PrincipalMasterView):
|
|||
name = getattr(user, field[:-1], None)
|
||||
if not name:
|
||||
return ""
|
||||
return six.text_type(name)
|
||||
return str(name)
|
||||
|
||||
def render_roles(self, user, field):
|
||||
roles = sorted(user.roles, key=lambda r: r.name)
|
||||
|
|
Loading…
Reference in a new issue