Refactor Query.get() => Session.get() per SQLAlchemy 1.4
This commit is contained in:
parent
f46fb3aa20
commit
af807063a8
16 changed files with 75 additions and 117 deletions
|
|
@ -24,8 +24,6 @@
|
|||
App Handler
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
# import re
|
||||
import datetime
|
||||
|
|
@ -37,7 +35,6 @@ import tempfile
|
|||
import warnings
|
||||
import logging
|
||||
|
||||
import six
|
||||
import humanize
|
||||
from mako.template import Template
|
||||
|
||||
|
|
@ -160,7 +157,7 @@ class AppHandler(object):
|
|||
and all values it contains will be coerced.
|
||||
"""
|
||||
if isinstance(value, dict):
|
||||
for key, val in six.iteritems(value):
|
||||
for key, val in value.items():
|
||||
value[key] = self.json_friendly(val)
|
||||
|
||||
elif isinstance(value, list):
|
||||
|
|
@ -171,7 +168,7 @@ class AppHandler(object):
|
|||
value = float(value)
|
||||
|
||||
elif isinstance(value, datetime.datetime):
|
||||
value = six.text_type(value)
|
||||
value = str(value)
|
||||
|
||||
return value
|
||||
|
||||
|
|
@ -293,7 +290,7 @@ class AppHandler(object):
|
|||
depending on the ``typ`` param.
|
||||
"""
|
||||
model = self.model
|
||||
setting = session.query(model.Setting).get(name)
|
||||
setting = session.get(model.Setting, name)
|
||||
value = None if setting is None else setting.value
|
||||
|
||||
if typ == 'utctime':
|
||||
|
|
@ -357,7 +354,7 @@ class AppHandler(object):
|
|||
# create or update the setting
|
||||
setting = None
|
||||
if not force_create:
|
||||
setting = session.query(model.Setting).get(name)
|
||||
setting = session.get(model.Setting, name)
|
||||
if not setting:
|
||||
setting = model.Setting(name=name)
|
||||
session.add(setting)
|
||||
|
|
@ -375,7 +372,7 @@ class AppHandler(object):
|
|||
:param name: Name of the setting to delete.
|
||||
"""
|
||||
model = self.model
|
||||
setting = session.query(model.Setting).get(name)
|
||||
setting = session.get(model.Setting, name)
|
||||
if setting:
|
||||
session.delete(setting)
|
||||
|
||||
|
|
@ -741,13 +738,13 @@ class AppHandler(object):
|
|||
|
||||
# organize registered classes by spec
|
||||
specs = {}
|
||||
for Handler in six.itervalues(Handlers):
|
||||
for Handler in Handlers.values():
|
||||
spec = '{}:{}'.format(Handler.__module__, Handler.__name__)
|
||||
specs[spec] = Handler
|
||||
|
||||
# many handlers may not be registered per se, but may be
|
||||
# designated via config. so try to include those too
|
||||
for Handler in six.itervalues(Handlers):
|
||||
for Handler in Handlers.values():
|
||||
spec = self.get_designated_import_handler_spec(Handler.get_key())
|
||||
if spec and spec not in specs:
|
||||
specs[spec] = load_object(spec)
|
||||
|
|
@ -807,7 +804,7 @@ class AppHandler(object):
|
|||
return group[0]
|
||||
|
||||
designated = []
|
||||
for key, group in six.iteritems(grouped):
|
||||
for key, group in grouped.items():
|
||||
Handler = find_designated(key, group)
|
||||
if Handler:
|
||||
# nb. we must instantiate here b/c otherwise if we
|
||||
|
|
@ -1514,7 +1511,7 @@ class AppHandler(object):
|
|||
|
||||
# this seems like a sane fallback..?
|
||||
if fallback is NOTSET:
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
# but if fallback specified, use that
|
||||
return fallback
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ class PurchaseBatchHandler(BatchHandler):
|
|||
logic assumes the key is a UUID, and will try to locate the
|
||||
corresponding :class:`~rattail.db.model.purchase.Purchase` instance.
|
||||
"""
|
||||
return session.query(model.Purchase).get(purchase_key)
|
||||
return session.get(model.Purchase, purchase_key)
|
||||
|
||||
def get_purchase_key(self, purchase, **kwargs):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
Batch-related commands
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import logging
|
||||
|
|
@ -181,7 +179,7 @@ class BatchAction(BatchHandlerCommand):
|
|||
"""
|
||||
This will invoke some action on the batch.
|
||||
"""
|
||||
batch = session.query(handler.batch_model_class).get(args.batch_uuid)
|
||||
batch = session.get(handler.batch_model_class, args.batch_uuid)
|
||||
if not batch:
|
||||
raise RuntimeError("Batch of type '{}' not found: {}".format(args.batch_type, args.batch_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,11 +24,8 @@
|
|||
DataSync for Rattail
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db.util import make_topo_sortkey
|
||||
|
|
@ -151,7 +148,7 @@ class RattailWatcher(DataSyncWatcher):
|
|||
try:
|
||||
for key in keys:
|
||||
if key: # note that key can sometimes be None
|
||||
change = session.query(model.Change).get(key)
|
||||
change = session.get(model.Change, key)
|
||||
if change:
|
||||
session.delete(change)
|
||||
session.flush()
|
||||
|
|
@ -230,7 +227,7 @@ class RattailConsumer(DataSyncConsumer):
|
|||
change.payload_type, change.payload_key))
|
||||
|
||||
if change.deletion:
|
||||
instance = session.query(cls).get(change.payload_key)
|
||||
instance = session.get(cls, change.payload_key)
|
||||
if instance:
|
||||
self.delete_instance(session, instance)
|
||||
session.flush()
|
||||
|
|
@ -238,7 +235,7 @@ class RattailConsumer(DataSyncConsumer):
|
|||
log.warning("could not find instance to delete")
|
||||
|
||||
else: # add/update
|
||||
host_instance = host_session.query(cls).get(change.payload_key)
|
||||
host_instance = host_session.get(cls, change.payload_key)
|
||||
if host_instance:
|
||||
|
||||
# if processing a pack item, must process its unit item
|
||||
|
|
@ -424,7 +421,7 @@ class FromRattailToRattailBase(DataSyncImportConsumer):
|
|||
cls = self.model.Product
|
||||
else:
|
||||
cls = getattr(self.model, change.payload_type)
|
||||
return session.query(cls).get(change.payload_key)
|
||||
return session.get(cls, change.payload_key)
|
||||
|
||||
|
||||
class FromRattailToRattailExportConsumer(FromRattailToRattailBase):
|
||||
|
|
@ -464,7 +461,7 @@ class FromRattailToRattailExportConsumer(FromRattailToRattailBase):
|
|||
self.target_session.set_continuum_user(self.runas_username)
|
||||
|
||||
# update all importers with current sessions
|
||||
for importer in six.itervalues(self.importers):
|
||||
for importer in self.importers.values():
|
||||
importer.host_session = self.local_session
|
||||
importer.session = self.target_session
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
Database Stuff
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
|
@ -93,7 +91,7 @@ if sqlalchemy:
|
|||
if isinstance(user_info, model.User):
|
||||
user = self.merge(user_info)
|
||||
else:
|
||||
user = self.query(model.User).get(user_info)
|
||||
user = self.get(model.User, user_info)
|
||||
if not user:
|
||||
try:
|
||||
user = self.query(model.User).filter_by(username=user_info).one()
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
API for Organizational Models
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from rattail.db import model
|
||||
|
|
@ -49,7 +46,7 @@ def get_department(session, key):
|
|||
otherwise ``None``.
|
||||
"""
|
||||
# Department.uuid match?
|
||||
department = session.query(model.Department).get(six.text_type(key))
|
||||
department = session.get(model.Department, str(key))
|
||||
if department:
|
||||
return department
|
||||
|
||||
|
|
@ -85,7 +82,7 @@ def get_subdepartment(session, key):
|
|||
otherwise ``None``.
|
||||
"""
|
||||
# Subdepartment.uuid match?
|
||||
subdepartment = session.query(model.Subdepartment).get(key)
|
||||
subdepartment = session.get(model.Subdepartment, key)
|
||||
if subdepartment:
|
||||
return subdepartment
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
Settings API
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
from rattail.db import Session, model
|
||||
|
|
@ -43,7 +41,7 @@ def get_setting(session, name):
|
|||
if session is None:
|
||||
session = Session()
|
||||
local_session = True
|
||||
setting = session.query(model.Setting).get(name)
|
||||
setting = session.get(model.Setting, name)
|
||||
value = None if setting is None else setting.value
|
||||
if local_session:
|
||||
session.close()
|
||||
|
|
@ -62,7 +60,7 @@ def save_setting(session, name, value):
|
|||
if session is None:
|
||||
session = Session()
|
||||
local_session = True
|
||||
setting = session.query(model.Setting).get(name)
|
||||
setting = session.get(model.Setting, name)
|
||||
if not setting:
|
||||
setting = model.Setting(name=name)
|
||||
session.add(setting)
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
API for Store Models
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from rattail.db import model
|
||||
|
|
@ -48,7 +46,7 @@ def get_store(session, key):
|
|||
``None``.
|
||||
"""
|
||||
# Store.uuid match?
|
||||
store = session.query(model.Store).get(key)
|
||||
store = session.get(model.Store, key)
|
||||
if store:
|
||||
return store
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
Vendors API
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
|
@ -60,7 +58,7 @@ def get_vendor(session, key):
|
|||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
# Vendor.uuid match?
|
||||
vendor = session.query(model.Vendor).get(key)
|
||||
vendor = session.get(model.Vendor, key)
|
||||
if vendor:
|
||||
return vendor
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 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
|
||||
|
||||
from passlib.context import CryptContext
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
|
|
@ -71,7 +69,7 @@ def special_role(session, uuid, name):
|
|||
Fetches, or creates, a "special" role.
|
||||
"""
|
||||
|
||||
role = session.query(model.Role).get(uuid)
|
||||
role = session.get(model.Role, uuid)
|
||||
if not role:
|
||||
role = model.Role(uuid=uuid, name=name)
|
||||
session.add(role)
|
||||
|
|
|
|||
|
|
@ -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,16 +24,12 @@
|
|||
Data Models for Contact Info
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from .core import Base, uuid_column
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class PhoneNumber(Base):
|
||||
"""
|
||||
Represents a phone (or fax) number associated with a contactable entity.
|
||||
|
|
@ -61,7 +57,6 @@ class PhoneNumber(Base):
|
|||
return self.preference == 1
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class EmailAddress(Base):
|
||||
"""
|
||||
Represents an email address associated with a contactable entity.
|
||||
|
|
@ -94,7 +89,6 @@ class EmailAddress(Base):
|
|||
return self.preference == 1
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class MailingAddress(Base):
|
||||
"""
|
||||
Represents a physical / mailing address associated with a contactable entity.
|
||||
|
|
@ -214,7 +208,7 @@ class ContactMixin(object):
|
|||
session = orm.object_session(self)
|
||||
contact = email.parent
|
||||
if not contact:
|
||||
contact = session.query(email.Parent).get(email.parent_uuid)
|
||||
contact = session.get(email.Parent, email.parent_uuid)
|
||||
if not contact:
|
||||
raise ValueError("cannot locate parent {} contact for email: {}".format(
|
||||
email.Parent.__name__, email))
|
||||
|
|
@ -294,7 +288,7 @@ class ContactMixin(object):
|
|||
session = orm.object_session(self)
|
||||
contact = phone.parent
|
||||
if not contact:
|
||||
contact = session.query(phone.Parent).get(phone.parent_uuid)
|
||||
contact = session.get(phone.Parent, phone.parent_uuid)
|
||||
if not contact:
|
||||
raise ValueError("cannot locate parent {} contact for phone: {}".format(
|
||||
phone.Parent.__name__, phone))
|
||||
|
|
@ -341,7 +335,7 @@ class ContactMixin(object):
|
|||
session = orm.object_session(self)
|
||||
contact = address.parent
|
||||
if not contact:
|
||||
contact = session.query(address.Parent).get(address.parent_uuid)
|
||||
contact = session.get(address.Parent, address.parent_uuid)
|
||||
if not contact:
|
||||
raise ValueError("cannot locate parent {} contact for address: {}".format(
|
||||
address.Parent.__name__, address))
|
||||
|
|
|
|||
|
|
@ -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,12 +24,9 @@
|
|||
Rattail Model Importers
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
|
@ -96,7 +93,7 @@ class ToRattail(ToSQLAlchemy):
|
|||
fields = list(super(ToRattail, self).simple_fields)
|
||||
|
||||
# extension fields, newer flexible style
|
||||
for name, ext_fields in six.iteritems(self.get_all_extensions()):
|
||||
for name, ext_fields in self.get_all_extensions().items():
|
||||
fields.extend(ext_fields)
|
||||
|
||||
return fields
|
||||
|
|
@ -105,7 +102,7 @@ class ToRattail(ToSQLAlchemy):
|
|||
options = super(ToRattail, self).cache_query_options() or []
|
||||
|
||||
# extension fields, newer flexible style
|
||||
for name, ext_fields in six.iteritems(self.get_all_extensions()):
|
||||
for name, ext_fields in self.get_all_extensions().items():
|
||||
if self.fields_active(ext_fields):
|
||||
options.append(orm.joinedload(
|
||||
getattr(self.model_class, name)))
|
||||
|
|
@ -124,7 +121,7 @@ class ToRattail(ToSQLAlchemy):
|
|||
return
|
||||
|
||||
# extension fields, newer flexible style
|
||||
for name, ext_fields in six.iteritems(self.get_all_extensions()):
|
||||
for name, ext_fields in self.get_all_extensions().items():
|
||||
for field in ext_fields:
|
||||
if field in self.fields:
|
||||
data[field] = getattr(obj, field)
|
||||
|
|
@ -136,7 +133,7 @@ class ToRattail(ToSQLAlchemy):
|
|||
if obj:
|
||||
|
||||
# extension fields, newer flexible style
|
||||
for name, ext_fields in six.iteritems(self.get_all_extensions()):
|
||||
for name, ext_fields in self.get_all_extensions().items():
|
||||
for field in ext_fields:
|
||||
if field in self.fields:
|
||||
if (not local_data
|
||||
|
|
@ -411,7 +408,7 @@ class PersonEmailAddressImporter(ToRattail):
|
|||
if email.preference != 1:
|
||||
person = email.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(email.parent_uuid)
|
||||
person = self.session.get(model.Person, email.parent_uuid)
|
||||
if email in person.emails:
|
||||
person.emails.remove(email)
|
||||
person.emails.insert(0, email)
|
||||
|
|
@ -420,7 +417,7 @@ class PersonEmailAddressImporter(ToRattail):
|
|||
if email.preference == 1:
|
||||
person = email.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(email.parent_uuid)
|
||||
person = self.session.get(model.Person, email.parent_uuid)
|
||||
if len(person.emails) > 1:
|
||||
person.emails.remove(email)
|
||||
person.emails.append(email)
|
||||
|
|
@ -430,7 +427,7 @@ class PersonEmailAddressImporter(ToRattail):
|
|||
if email.preference is None:
|
||||
person = email.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(email.parent_uuid)
|
||||
person = self.session.get(model.Person, email.parent_uuid)
|
||||
if email not in person.emails:
|
||||
person.emails.append(email)
|
||||
person.emails.reorder()
|
||||
|
|
@ -472,7 +469,7 @@ class PersonPhoneNumberImporter(ToRattail):
|
|||
if phone.preference != 1:
|
||||
person = phone.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(phone.parent_uuid)
|
||||
person = self.session.get(model.Person, phone.parent_uuid)
|
||||
if phone in person.phones:
|
||||
person.phones.remove(phone)
|
||||
person.phones.insert(0, phone)
|
||||
|
|
@ -481,7 +478,7 @@ class PersonPhoneNumberImporter(ToRattail):
|
|||
if phone.preference == 1:
|
||||
person = phone.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(phone.parent_uuid)
|
||||
person = self.session.get(model.Person, phone.parent_uuid)
|
||||
if len(person.phones) > 1:
|
||||
person.phones.remove(phone)
|
||||
person.phones.append(phone)
|
||||
|
|
@ -491,7 +488,7 @@ class PersonPhoneNumberImporter(ToRattail):
|
|||
if phone.preference is None:
|
||||
person = phone.person
|
||||
if not person:
|
||||
person = self.session.query(model.Person).get(phone.parent_uuid)
|
||||
person = self.session.get(model.Person, phone.parent_uuid)
|
||||
if phone not in person.phones:
|
||||
person.phones.append(phone)
|
||||
person.phones.reorder()
|
||||
|
|
@ -2084,7 +2081,7 @@ class ProductImporter(ToRattail):
|
|||
elif self.auto_create_unknown_category:
|
||||
category = model.Category()
|
||||
category.number = number
|
||||
category.code = six.text_type(number)
|
||||
category.code = str(number)
|
||||
category.name = "(auto-created)"
|
||||
self.session.add(category)
|
||||
if hasattr(self, 'categories'):
|
||||
|
|
@ -2640,7 +2637,7 @@ class ProductCostImporter(ToRattail):
|
|||
log.warning("duplicate products detected for item_id: %s", item_id)
|
||||
|
||||
if 'preferred' in self.fields:
|
||||
product = cost.product or self.session.query(model.Product).get(cost.product_uuid)
|
||||
product = cost.product or self.session.get(model.Product, cost.product_uuid)
|
||||
if data['preferred']:
|
||||
if cost in product.costs:
|
||||
if cost.preference != 1:
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
Rattail -> Rattail data import
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
|
@ -354,7 +352,7 @@ class GlobalRoleImporter(RoleImporter):
|
|||
# add some users
|
||||
for new_user in new_users:
|
||||
if new_user not in old_users:
|
||||
user = self.session.query(model.User).get(new_user)
|
||||
user = self.session.get(model.User, new_user)
|
||||
if user:
|
||||
user.roles.append(role)
|
||||
changed = True
|
||||
|
|
@ -362,7 +360,7 @@ class GlobalRoleImporter(RoleImporter):
|
|||
# remove some users
|
||||
for old_user in old_users:
|
||||
if old_user not in new_users:
|
||||
user = self.session.query(model.User).get(old_user)
|
||||
user = self.session.get(model.User, old_user)
|
||||
if user:
|
||||
user.roles.remove(role)
|
||||
changed = True
|
||||
|
|
|
|||
|
|
@ -26,11 +26,8 @@ People Handler
|
|||
See also :doc:`rattail-manual:base/handlers/other/people`.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail.app import GenericHandler, MergeMixin
|
||||
|
|
@ -74,7 +71,7 @@ class PeopleHandler(GenericHandler, MergeMixin):
|
|||
person.display_name = self.normalize_full_name(
|
||||
person.first_name, person.last_name)
|
||||
|
||||
for key, value in six.iteritems(kwargs):
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(person, key):
|
||||
setattr(person, key, value)
|
||||
|
||||
|
|
@ -363,13 +360,13 @@ class PeopleHandler(GenericHandler, MergeMixin):
|
|||
session = self.get_session(merge)
|
||||
model = self.model
|
||||
|
||||
removing = session.query(model.Person).get(merge.removing_uuid)
|
||||
keeping = session.query(model.Person).get(merge.keeping_uuid)
|
||||
removing = session.get(model.Person, merge.removing_uuid)
|
||||
keeping = session.get(model.Person, merge.keeping_uuid)
|
||||
|
||||
context = {
|
||||
'user_display': merge.requested_by.display_name,
|
||||
'removing_display': six.text_type(removing) if removing else "(not found)",
|
||||
'keeping_display': six.text_type(keeping) if keeping else "(not found)",
|
||||
'removing_display': str(removing) if removing else "(not found)",
|
||||
'keeping_display': str(keeping) if keeping else "(not found)",
|
||||
}
|
||||
|
||||
url = self.config.base_url()
|
||||
|
|
|
|||
|
|
@ -24,13 +24,10 @@
|
|||
Products Handler
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import decimal
|
||||
import warnings
|
||||
import logging
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
|
|
@ -70,8 +67,8 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
then returns ``None``.
|
||||
"""
|
||||
# normalize to string; remove unwanted chars
|
||||
if not isinstance(value, six.string_types):
|
||||
value = six.text_type(value)
|
||||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
value = value.replace(' ', '')
|
||||
value = value.replace('-', '')
|
||||
|
||||
|
|
@ -210,7 +207,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
|
||||
model = self.model
|
||||
only = kwargs.get('only')
|
||||
if isinstance(only, six.string_types):
|
||||
if isinstance(only, str):
|
||||
only = [only]
|
||||
vendor = kwargs.get('vendor')
|
||||
include_keys = kwargs.get('include_keys', False)
|
||||
|
|
@ -228,7 +225,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
|
||||
# maybe look for 'uuid' match
|
||||
if not only or 'uuid' in only:
|
||||
product = session.query(model.Product).get(value)
|
||||
product = session.get(model.Product, value)
|
||||
if product:
|
||||
products.append(('uuid', product))
|
||||
|
||||
|
|
@ -362,8 +359,8 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
# try to locate product by uuid before other, more specific key
|
||||
# if kwargs.get('try_uuid', True):
|
||||
if 'uuid' in lookup_fields:
|
||||
if isinstance(entry, six.string_types):
|
||||
product = session.query(model.Product).get(entry)
|
||||
if isinstance(entry, str):
|
||||
product = session.get(model.Product, entry)
|
||||
if product:
|
||||
return product
|
||||
|
||||
|
|
@ -414,7 +411,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
return
|
||||
|
||||
# assume entry is string; valid only if all digits
|
||||
entry = six.text_type(entry)
|
||||
entry = str(entry)
|
||||
if not entry.isdigit():
|
||||
return
|
||||
|
||||
|
|
@ -461,7 +458,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
return
|
||||
|
||||
# assume entry is string
|
||||
entry = six.text_type(entry)
|
||||
entry = str(entry)
|
||||
|
||||
# do basic lookup
|
||||
return get_product_by_item_id(session, entry)
|
||||
|
|
@ -489,7 +486,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
return
|
||||
|
||||
# assume entry is string
|
||||
entry = six.text_type(entry)
|
||||
entry = str(entry)
|
||||
|
||||
# do basic lookup
|
||||
return get_product_by_scancode(session, entry)
|
||||
|
|
@ -652,7 +649,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
'product_key': self.render_product_key(product),
|
||||
'description': product.description,
|
||||
'size': product.size,
|
||||
'_str': six.text_type(product),
|
||||
'_str': str(product),
|
||||
}
|
||||
|
||||
if not fields:
|
||||
|
|
@ -726,7 +723,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
current_ends = current_price.ends
|
||||
if current_ends:
|
||||
current_ends = self.app.localtime(current_ends, from_utc=True).date()
|
||||
data['current_ends'] = six.text_type(current_ends)
|
||||
data['current_ends'] = str(current_ends)
|
||||
data['current_ends_display'] = self.app.render_date(current_ends)
|
||||
|
||||
sale_fields = [
|
||||
|
|
@ -744,7 +741,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
sale_ends = sale_price.ends
|
||||
if sale_ends:
|
||||
sale_ends = self.app.localtime(sale_ends, from_utc=True).date()
|
||||
data['sale_ends'] = six.text_type(sale_ends)
|
||||
data['sale_ends'] = str(sale_ends)
|
||||
data['sale_ends_display'] = self.app.render_date(sale_ends)
|
||||
|
||||
tpr_fields = [
|
||||
|
|
@ -762,7 +759,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
tpr_ends = tpr_price.ends
|
||||
if tpr_ends:
|
||||
tpr_ends = self.app.localtime(tpr_ends, from_utc=True).date()
|
||||
data['tpr_ends'] = six.text_type(tpr_ends)
|
||||
data['tpr_ends'] = str(tpr_ends)
|
||||
data['tpr_ends_display'] = self.app.render_date(tpr_ends)
|
||||
|
||||
if 'case_quantity' in fields:
|
||||
|
|
@ -779,7 +776,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
unit_price = sale_price.price
|
||||
case_price = (case_size or 1) * unit_price
|
||||
case_price = case_price.quantize(decimal.Decimal('0.01'))
|
||||
data['case_price'] = six.text_type(case_price) if case_price is not None else None
|
||||
data['case_price'] = str(case_price) if case_price is not None else None
|
||||
data['case_price_display'] = self.app.render_currency(case_price)
|
||||
|
||||
if 'uom_choices' in fields:
|
||||
|
|
@ -896,7 +893,7 @@ class ProductsHandler(GenericHandler, MergeMixin):
|
|||
product_key = self.config.product_key()
|
||||
if product_key == 'upc':
|
||||
return self.app.render_gpc(product.upc)
|
||||
return six.text_type(getattr(product, product_key))
|
||||
return str(getattr(product, product_key))
|
||||
|
||||
def render_price(self, price, html=False, **kwargs):
|
||||
"""
|
||||
|
|
|
|||
10
rattail/vendors/handler.py
vendored
10
rattail/vendors/handler.py
vendored
|
|
@ -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,10 +24,6 @@
|
|||
Vendors Handler
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.app import GenericHandler
|
||||
|
|
@ -89,7 +85,7 @@ class VendorHandler(GenericHandler):
|
|||
model = self.model
|
||||
|
||||
# Vendor.uuid match?
|
||||
vendor = session.query(model.Vendor).get(key)
|
||||
vendor = session.get(model.Vendor, key)
|
||||
if vendor:
|
||||
return vendor
|
||||
|
||||
|
|
@ -107,7 +103,7 @@ class VendorHandler(GenericHandler):
|
|||
return self.get_vendor(session, key, **kwargs)
|
||||
|
||||
def render_vendor(self, vendor, **kwargs):
|
||||
return six.text_type(vendor)
|
||||
return str(vendor)
|
||||
|
||||
def get_all_catalog_parsers(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue