Refactor Query.get() => Session.get() per SQLAlchemy 1.4

This commit is contained in:
Lance Edgar 2023-02-11 22:05:45 -06:00
parent 81aa0ae109
commit f611a5a521
38 changed files with 169 additions and 205 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,13 +24,9 @@
Tailbone Web API - Batch Views Tailbone Web API - Batch Views
""" """
from __future__ import unicode_literals, absolute_import
import logging import logging
import warnings import warnings
import six
from cornice import Service from cornice import Service
from tailbone.api import APIMasterView from tailbone.api import APIMasterView
@ -104,25 +100,25 @@ class APIBatchView(APIBatchMixin, APIMasterView):
return { return {
'uuid': batch.uuid, 'uuid': batch.uuid,
'_str': six.text_type(batch), '_str': str(batch),
'id': batch.id, 'id': batch.id,
'id_str': batch.id_str, 'id_str': batch.id_str,
'description': batch.description, 'description': batch.description,
'notes': batch.notes, 'notes': batch.notes,
'params': batch.params or {}, 'params': batch.params or {},
'rowcount': batch.rowcount, 'rowcount': batch.rowcount,
'created': six.text_type(created), 'created': str(created),
'created_display': self.pretty_datetime(created), 'created_display': self.pretty_datetime(created),
'created_by_uuid': batch.created_by.uuid, '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, 'complete': batch.complete,
'status_code': batch.status_code, 'status_code': batch.status_code,
'status_display': batch.STATUS.get(batch.status_code, 'status_display': batch.STATUS.get(batch.status_code,
six.text_type(batch.status_code)), str(batch.status_code)),
'executed': six.text_type(executed) if executed else None, 'executed': str(executed) if executed else None,
'executed_display': self.pretty_datetime(executed) if executed else None, 'executed_display': self.pretty_datetime(executed) if executed else None,
'executed_by_uuid': batch.executed_by_uuid, '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), 'mutable': self.batch_handler.is_mutable(batch),
} }
@ -273,8 +269,8 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
batch = row.batch batch = row.batch
return { return {
'uuid': row.uuid, 'uuid': row.uuid,
'_str': six.text_type(row), '_str': str(row),
'_parent_str': six.text_type(batch), '_parent_str': str(batch),
'_parent_uuid': batch.uuid, '_parent_uuid': batch.uuid,
'batch_uuid': batch.uuid, 'batch_uuid': batch.uuid,
'batch_id': batch.id, 'batch_id': batch.id,
@ -285,7 +281,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
'batch_mutable': self.batch_handler.is_mutable(batch), 'batch_mutable': self.batch_handler.is_mutable(batch),
'sequence': row.sequence, 'sequence': row.sequence,
'status_code': row.status_code, '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): def update_object(self, row, data):
@ -320,7 +316,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
data = self.request.json_body data = self.request.json_body
uuid = data['batch_uuid'] 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: if not batch:
raise self.notfound() raise self.notfound()
@ -332,7 +328,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
log.warning("quick entry failed for '%s' batch %s: %s", log.warning("quick entry failed for '%s' batch %s: %s",
self.batch_handler.batch_key, batch.id_str, entry, self.batch_handler.batch_key, batch.id_str, entry,
exc_info=True) exc_info=True)
msg = six.text_type(error) msg = str(error)
if not msg and isinstance(error, NotImplementedError): if not msg and isinstance(error, NotImplementedError):
msg = "Feature is not implemented" msg = "Feature is not implemented"
return {'error': msg} return {'error': msg}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,11 +24,8 @@
Tailbone Web API - Receiving Batches Tailbone Web API - Receiving Batches
""" """
from __future__ import unicode_literals, absolute_import
import logging import logging
import six
import humanize import humanize
from rattail.db import model from rattail.db import model
@ -64,10 +61,10 @@ class ReceivingBatchViews(APIBatchView):
data = super(ReceivingBatchViews, self).normalize(batch) data = super(ReceivingBatchViews, self).normalize(batch)
data['vendor_uuid'] = batch.vendor.uuid 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_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['po_total'] = batch.po_total
data['invoice_total'] = batch.invoice_total data['invoice_total'] = batch.invoice_total
@ -115,7 +112,7 @@ class ReceivingBatchViews(APIBatchView):
def eligible_purchases(self): def eligible_purchases(self):
uuid = self.request.params.get('vendor_uuid') 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: if not vendor:
return {'error': "Vendor not found"} return {'error': "Vendor not found"}
@ -289,7 +286,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
data['product_uuid'] = row.product_uuid data['product_uuid'] = row.product_uuid
data['item_id'] = row.item_id 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['upc_pretty'] = row.upc.pretty() if row.upc else None
data['brand_name'] = row.brand_name data['brand_name'] = row.brand_name
data['description'] = row.description data['description'] = row.description
@ -415,7 +412,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
return {'error': "Form did not validate"} return {'error': "Form did not validate"}
# fetch / validate row object # 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(): if row is not self.get_object():
return {'error': "Specified row does not match the route!"} return {'error': "Specified row does not match the route!"}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Tailbone Web API - "Common" Views Tailbone Web API - "Common" Views
""" """
from __future__ import unicode_literals, absolute_import
import rattail import rattail
from rattail.db import model from rattail.db import model
from rattail.mail import send_email from rattail.mail import send_email
@ -97,7 +95,7 @@ class CommonView(APIView):
if self.request.user: if self.request.user:
data['user'] = self.request.user data['user'] = self.request.user
elif data['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 # TODO: should provide URL to view user
if data['user']: if data['user']:

View file

@ -339,7 +339,7 @@ class APIMasterView(APIView):
if not uuid: if not uuid:
uuid = self.request.matchdict['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: if obj:
return obj return obj
@ -390,7 +390,7 @@ class APIMasterView(APIView):
""" """
if not uuid: if not uuid:
uuid = self.request.matchdict['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: if not obj:
raise self.notfound() raise self.notfound()

View file

@ -24,11 +24,8 @@
Tailbone Web API - Product Views Tailbone Web API - Product Views
""" """
from __future__ import unicode_literals, absolute_import
import logging import logging
import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
@ -84,7 +81,7 @@ class ProductView(APIMasterView):
# but must supplement # but must supplement
cost = product.cost cost = product.cost
data.update({ data.update({
'upc': six.text_type(product.upc), 'upc': str(product.upc),
'scancode': product.scancode, 'scancode': product.scancode,
'item_id': product.item_id, 'item_id': product.item_id,
'item_type': product.item_type, 'item_type': product.item_type,
@ -135,12 +132,12 @@ class ProductView(APIMasterView):
data = self.request.json_body data = self.request.json_body
uuid = data.get('label_profile_uuid') 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: if not profile:
return {'error': "Label profile not found"} return {'error': "Label profile not found"}
uuid = data.get('product_uuid') 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}
@ -157,7 +154,7 @@ class ProductView(APIMasterView):
printer.print_labels([({'product': product}, quantity)]) printer.print_labels([({'product': product}, quantity)])
except Exception as error: except Exception as error:
log.warning("error occurred while printing labels", exc_info=True) log.warning("error occurred while printing labels", exc_info=True)
return {'error': six.text_type(error)} return {'error': str(error)}
return {'ok': True} return {'ok': True}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Authentication & Authorization Authentication & Authorization
""" """
from __future__ import unicode_literals, absolute_import
import logging import logging
from rattail import enum from rattail import enum
@ -107,7 +105,7 @@ class TailboneAuthorizationPolicy(object):
# re-creating the database, which means new user uuids. # re-creating the database, which means new user uuids.
# TODO: the odds of this query returning a user in that # TODO: the odds of this query returning a user in that
# case, are probably nil, and we should just skip this bit? # 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 user:
if auth.has_permission(Session(), user, permission): if auth.has_permission(Session(), user, permission):
return True return True

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Common Forms Common Forms
""" """
from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
import colander import colander
@ -35,7 +33,7 @@ import colander
def validate_user(node, kw): def validate_user(node, kw):
session = kw['session'] session = kw['session']
def validate(node, value): def validate(node, value):
user = session.query(model.User).get(value) user = session.get(model.User, value)
if not user: if not user:
raise colander.Invalid(node, "User not found") raise colander.Invalid(node, "User not found")
return user.uuid return user.uuid

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Forms for Receiving Forms for Receiving
""" """
from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
import colander import colander
@ -35,7 +33,7 @@ import colander
def valid_purchase_batch_row(node, kw): def valid_purchase_batch_row(node, kw):
session = kw['session'] session = kw['session']
def validate(node, value): def validate(node, value):
row = session.query(model.PurchaseBatchRow).get(value) row = session.get(model.PurchaseBatchRow, value)
if not row: if not row:
raise colander.Invalid(node, "Batch row not found") raise colander.Invalid(node, "Batch row not found")
if row.batch.executed: if row.batch.executed:

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,13 +24,9 @@
Form Schema Types Form Schema Types
""" """
from __future__ import unicode_literals, absolute_import
import re import re
import datetime import datetime
import six
from rattail.db import model from rattail.db import model
from rattail.gpc import GPC from rattail.gpc import GPC
@ -84,7 +80,7 @@ class GPCType(colander.SchemaType):
def serialize(self, node, appstruct): def serialize(self, node, appstruct):
if appstruct is colander.null: if appstruct is colander.null:
return colander.null return colander.null
return six.text_type(appstruct) return str(appstruct)
def deserialize(self, node, cstruct): def deserialize(self, node, cstruct):
if not cstruct: if not cstruct:
@ -95,7 +91,7 @@ class GPCType(colander.SchemaType):
try: try:
return GPC(digits) return GPC(digits)
except Exception as err: except Exception as err:
raise colander.Invalid(node, six.text_type(err)) raise colander.Invalid(node, str(err))
class ProductQuantity(colander.MappingSchema): class ProductQuantity(colander.MappingSchema):
@ -133,12 +129,12 @@ class ModelType(colander.SchemaType):
def serialize(self, node, appstruct): def serialize(self, node, appstruct):
if appstruct is colander.null: if appstruct is colander.null:
return colander.null return colander.null
return six.text_type(appstruct) return str(appstruct)
def deserialize(self, node, cstruct): def deserialize(self, node, cstruct):
if not cstruct: if not cstruct:
return None return None
obj = self.session.query(self.model_class).get(cstruct) obj = self.session.get(self.model_class, cstruct)
if not obj: if not obj:
raise colander.Invalid(node, "{} not found".format(self.model_title)) raise colander.Invalid(node, "{} not found".format(self.model_title))
return obj return obj

View file

@ -410,7 +410,7 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
# fetch customer to provide button label, if we have a value # fetch customer to provide button label, if we have a value
if cstruct: if cstruct:
model = self.request.rattail_config.get_model() model = self.request.rattail_config.get_model()
customer = Session.query(model.Customer).get(cstruct) customer = Session.get(model.Customer, cstruct)
if customer: if customer:
self.field_display = str(customer) self.field_display = str(customer)

View file

@ -74,7 +74,7 @@ def new_request(event):
uuid = request.authenticated_userid uuid = request.authenticated_userid
if uuid: if uuid:
model = request.rattail_config.get_model() model = request.rattail_config.get_model()
user = Session.query(model.User).get(uuid) user = Session.get(model.User, uuid)
if user: if user:
Session().set_continuum_user(user) Session().set_continuum_user(user)
return user return user

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -89,7 +89,7 @@ class WebsocketView(object):
session=session) as s: session=session) as s:
# load user proper # load user proper
return s.query(model.User).get(user_uuid) return s.get(model.User, user_uuid)
def get_user_session(self, scope): def get_user_session(self, scope):
settings = self.registry.settings settings = self.registry.settings

View file

@ -32,7 +32,6 @@ import logging
import socket import socket
import subprocess import subprocess
import tempfile import tempfile
from six import StringIO
import json import json
import markdown import markdown
@ -236,7 +235,7 @@ class BatchMasterView(MasterView):
Thread target for updating a batch from worksheet. Thread target for updating a batch from worksheet.
""" """
session = self.make_isolated_session() session = self.make_isolated_session()
batch = session.query(self.model_class).get(batch_uuid) batch = session.get(self.model_class, batch_uuid)
try: try:
self.handler.update_from_worksheet(batch, path, progress=progress) 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): def catchup_versions(self, port, batch_uuid, username, *models):
with short_session() as s: 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 batch_id = batch.id_str
description = str(batch) description = str(batch)
@ -1047,8 +1046,8 @@ class BatchMasterView(MasterView):
""" """
# mustn't use tailbone web session here # mustn't use tailbone web session here
session = RattailSession() session = RattailSession()
batch = session.query(self.model_class).get(batch_uuid) batch = session.get(self.model_class, batch_uuid)
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
self.handler.do_populate(batch, user, progress=progress) self.handler.do_populate(batch, user, progress=progress)
session.flush() session.flush()
@ -1104,8 +1103,8 @@ class BatchMasterView(MasterView):
# rattail session here; can't use tailbone because it has web request # rattail session here; can't use tailbone because it has web request
# transaction binding etc. # transaction binding etc.
session = RattailSession() session = RattailSession()
batch = session.query(self.model_class).get(batch_uuid) batch = session.get(self.model_class, batch_uuid)
cognizer = session.query(model.User).get(user_uuid) if user_uuid else None cognizer = session.get(model.User, user_uuid) if user_uuid else None
try: try:
self.refresh_data(session, batch, cognizer, progress=progress) self.refresh_data(session, batch, cognizer, progress=progress)
session.flush() session.flush()
@ -1158,7 +1157,7 @@ class BatchMasterView(MasterView):
""" """
session = RattailSession() session = RattailSession()
batches = batches.with_session(session).all() batches = batches.with_session(session).all()
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
self.handler.refresh_many(batches, user=user, progress=progress) self.handler.refresh_many(batches, user=user, progress=progress)
@ -1298,7 +1297,7 @@ class BatchMasterView(MasterView):
# transaction binding etc. # transaction binding etc.
session = RattailSession() session = RattailSession()
batch = self.get_instance_for_key(key, session) batch = self.get_instance_for_key(key, session)
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
result = self.handler.do_execute(batch, user=user, progress=progress, **kwargs) result = self.handler.do_execute(batch, user=user, progress=progress, **kwargs)
@ -1373,7 +1372,7 @@ class BatchMasterView(MasterView):
""" """
session = RattailSession() session = RattailSession()
batches = batches.with_session(session).all() batches = batches.with_session(session).all()
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
result = self.handler.execute_many(batches, user=user, progress=progress, **kwargs) result = self.handler.execute_many(batches, user=user, progress=progress, **kwargs)

View file

@ -190,7 +190,7 @@ class ImporterBatchView(BatchMasterView):
def get_parent(self, row): def get_parent(self, row):
uuid = self.current_row_table.name uuid = self.current_row_table.name
return self.Session.query(model.ImporterBatch).get(uuid) return self.Session.get(model.ImporterBatch, uuid)
def get_row_instance_title(self, row): def get_row_instance_title(self, row):
if row.object_str: if row.object_str:

View file

@ -214,7 +214,7 @@ class InventoryBatchView(BatchMasterView):
return super(InventoryBatchView, self).save_edit_row_form(form) return super(InventoryBatchView, self).save_edit_row_form(form)
def delete_row(self): 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: if not row:
raise self.notfound() raise self.notfound()
batch = row.batch batch = row.batch
@ -235,7 +235,7 @@ class InventoryBatchView(BatchMasterView):
if self.request.method == 'POST': if self.request.method == 'POST':
if form.validate(newstyle=True): 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 row = None
if self.should_aggregate_products(batch): if self.should_aggregate_products(batch):
@ -515,7 +515,7 @@ class InventoryBatchView(BatchMasterView):
def valid_product(node, kw): def valid_product(node, kw):
session = kw['session'] session = kw['session']
def validate(node, value): def validate(node, value):
product = session.query(model.Product).get(value) product = session.get(model.Product, value)
if not product: if not product:
raise colander.Invalid(node, "Product not found") raise colander.Invalid(node, "Product not found")
return product.uuid return product.uuid

View file

@ -225,7 +225,7 @@ class VendorCatalogView(FileBatchMasterView):
vendor_display = "" vendor_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('vendor_uuid'): if self.request.POST.get('vendor_uuid'):
vendor = self.Session.query(model.Vendor).get( vendor = self.Session.get(model.Vendor,
self.request.POST['vendor_uuid']) self.request.POST['vendor_uuid'])
if vendor: if vendor:
vendor_display = str(vendor) vendor_display = str(vendor)

View file

@ -163,7 +163,7 @@ class CommonView(View):
if form.validate(newstyle=True): if form.validate(newstyle=True):
data = dict(form.validated) data = dict(form.validated)
if data['user']: 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['user_url'] = self.request.route_url('users.view', uuid=data['user'].uuid)
data['client_ip'] = self.request.client_addr data['client_ip'] = self.request.client_addr
app.send_email('user_feedback', data=data) app.send_email('user_feedback', data=data)

View file

@ -97,7 +97,7 @@ class View(object):
if self.request.method == 'POST': if self.request.method == 'POST':
uuid = self.request.POST.get('late-login-user') uuid = self.request.POST.get('late-login-user')
if uuid: if uuid:
return Session.query(model.User).get(uuid) return Session.get(model.User, uuid)
def user_is_protected(self, user): def user_is_protected(self, user):
""" """

View file

@ -187,12 +187,12 @@ class CustomerView(MasterView):
return instance return instance
# search by CustomerPerson.uuid # search by CustomerPerson.uuid
instance = self.Session.query(model.CustomerPerson).get(key) instance = self.Session.get(model.CustomerPerson, key)
if instance: if instance:
return instance.customer return instance.customer
# search by CustomerGroupAssignment.uuid # search by CustomerGroupAssignment.uuid
instance = self.Session.query(model.CustomerGroupAssignment).get(key) instance = self.Session.get(model.CustomerGroupAssignment, key)
if instance: if instance:
return instance.customer return instance.customer
@ -438,7 +438,7 @@ class CustomerView(MasterView):
def detach_person(self): def detach_person(self):
customer = self.get_instance() 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: if not person:
return self.notfound() return self.notfound()
@ -612,7 +612,7 @@ class PendingCustomerView(MasterView):
redirect = self.redirect(self.get_action_url('view', pending)) redirect = self.redirect(self.get_action_url('view', pending))
uuid = self.request.POST['person_uuid'] uuid = self.request.POST['person_uuid']
person = self.Session.query(model.Person).get(uuid) person = self.Session.get(model.Person, uuid)
if not person: if not person:
self.request.session.flash("Person not found!", 'error') self.request.session.flash("Person not found!", 'error')
return redirect return redirect
@ -670,7 +670,7 @@ def customer_info(request):
View which returns simple dictionary of info for a particular customer. View which returns simple dictionary of info for a particular customer.
""" """
uuid = request.params.get('uuid') 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: if not customer:
return {} return {}
return { return {

View file

@ -408,7 +408,7 @@ class CustomerOrderItemView(MasterView):
uuids = self.request.POST['uuids'] uuids = self.request.POST['uuids']
if uuids: if uuids:
for uuid in uuids.split(','): for uuid in uuids.split(','):
item = self.Session.query(model.CustomerOrderItem).get(uuid) item = self.Session.get(model.CustomerOrderItem, uuid)
if item: if item:
order_items.append(item) order_items.append(item)

View file

@ -24,12 +24,9 @@
Customer Order Views Customer Order Views
""" """
from __future__ import unicode_literals, absolute_import
import decimal import decimal
import logging import logging
import six
from sqlalchemy import orm from sqlalchemy import orm
from rattail.db import model from rattail.db import model
@ -195,7 +192,7 @@ class CustomerOrderView(MasterView):
person = order.person person = order.person
if not person: if not person:
return "" return ""
text = six.text_type(person) text = str(person)
url = self.request.route_url('people.view', uuid=person.uuid) url = self.request.route_url('people.view', uuid=person.uuid)
return tags.link_to(text, url) return tags.link_to(text, url)
@ -203,7 +200,7 @@ class CustomerOrderView(MasterView):
pending = batch.pending_customer pending = batch.pending_customer
if not pending: if not pending:
return return
text = six.text_type(pending) text = str(pending)
url = self.request.route_url('pending_customers.view', uuid=pending.uuid) url = self.request.route_url('pending_customers.view', uuid=pending.uuid)
return tags.link_to(text, url, return tags.link_to(text, url,
class_='has-background-warning') class_='has-background-warning')
@ -275,7 +272,7 @@ class CustomerOrderView(MasterView):
def render_row_status_code(self, item, field): def render_row_status_code(self, item, field):
text = self.enum.CUSTORDER_ITEM_STATUS.get(item.status_code, text = self.enum.CUSTORDER_ITEM_STATUS.get(item.status_code,
six.text_type(item.status_code)) str(item.status_code))
if item.status_text: if item.status_text:
return HTML.tag('span', title=item.status_text, c=[text]) return HTML.tag('span', title=item.status_text, c=[text])
return text return text
@ -445,7 +442,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a customer 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: if not customer:
return {'error': "Customer not found"} return {'error': "Customer not found"}
@ -472,14 +469,14 @@ class CustomerOrderView(MasterView):
if self.batch_handler.new_order_requires_customer(): 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: if not customer:
return {'error': "Customer not found"} return {'error': "Customer not found"}
kwargs['customer'] = customer kwargs['customer'] = customer
else: else:
person = self.Session.query(model.Person).get(uuid) person = self.Session.get(model.Person, uuid)
if not person: if not person:
return {'error': "Person not found"} return {'error': "Person not found"}
kwargs['person'] = person kwargs['person'] = person
@ -488,7 +485,7 @@ class CustomerOrderView(MasterView):
try: try:
self.batch_handler.assign_contact(batch, **kwargs) self.batch_handler.assign_contact(batch, **kwargs)
except ValueError as error: except ValueError as error:
return {'error': six.text_type(error)} return {'error': str(error)}
self.Session.flush() self.Session.flush()
context = self.get_context_contact(batch) context = self.get_context_contact(batch)
@ -590,7 +587,7 @@ class CustomerOrderView(MasterView):
self.batch_handler.update_pending_customer(batch, self.request.user, self.batch_handler.update_pending_customer(batch, self.request.user,
data) data)
except Exception as error: except Exception as error:
return {'error': six.text_type(error)} return {'error': str(error)}
self.Session.flush() self.Session.flush()
context = self.get_context_contact(batch) context = self.get_context_contact(batch)
@ -619,7 +616,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a product 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}
@ -635,7 +632,7 @@ class CustomerOrderView(MasterView):
try: try:
info = self.batch_handler.get_product_info(batch, product) info = self.batch_handler.get_product_info(batch, product)
except Exception as error: except Exception as error:
return {'error': six.text_type(error)} return {'error': str(error)}
else: else:
info['url'] = self.request.route_url('products.view', uuid=info['uuid']) info['url'] = self.request.route_url('products.view', uuid=info['uuid'])
app = self.get_rattail_app() app = self.get_rattail_app()
@ -661,7 +658,7 @@ class CustomerOrderView(MasterView):
def normalize_batch(self, batch): def normalize_batch(self, batch):
return { return {
'uuid': batch.uuid, '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), 'total_price_display': "${:0.2f}".format(batch.total_price or 0),
'status_code': batch.status_code, 'status_code': batch.status_code,
'status_text': batch.status_text, 'status_text': batch.status_text,
@ -690,7 +687,7 @@ class CustomerOrderView(MasterView):
'sequence': row.sequence, 'sequence': row.sequence,
'item_entry': row.item_entry, 'item_entry': row.item_entry,
'product_uuid': row.product_uuid, '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_item_id': row.product_item_id,
'product_scancode': row.product_scancode, 'product_scancode': row.product_scancode,
'product_upc_pretty': row.product_upc.pretty() if row.product_upc else None, '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) data['unit_sale_price_display'] = app.render_currency(row.unit_sale_price)
if row.sale_ends: if row.sale_ends:
sale_ends = app.localtime(row.sale_ends, from_utc=True).date() 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) data['sale_ends_display'] = app.render_date(sale_ends)
if row.unit_sale_price and row.unit_price == row.unit_sale_price: if row.unit_sale_price and row.unit_price == row.unit_sale_price:
@ -748,7 +745,7 @@ class CustomerOrderView(MasterView):
pending = row.pending_product pending = row.pending_product
data['pending_product'] = { data['pending_product'] = {
'uuid': pending.uuid, '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, 'item_id': pending.item_id,
'scancode': pending.scancode, 'scancode': pending.scancode,
'brand_name': pending.brand_name, 'brand_name': pending.brand_name,
@ -826,7 +823,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a product 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}
@ -871,7 +868,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a row 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: if not row:
return {'error': "Row not found"} return {'error': "Row not found"}
@ -888,7 +885,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a product 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}
@ -929,7 +926,7 @@ class CustomerOrderView(MasterView):
if not uuid: if not uuid:
return {'error': "Must specify a row 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: if not row:
return {'error': "Row not found"} return {'error': "Row not found"}

View file

@ -249,7 +249,7 @@ class EmployeeView(MasterView):
employee._stores.append(model.EmployeeStore(store_uuid=uuid)) employee._stores.append(model.EmployeeStore(store_uuid=uuid))
for uuid in old_stores: for uuid in old_stores:
if uuid not in new_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) employee.stores.remove(store)
def update_departments(self, employee, data): def update_departments(self, employee, data):
@ -262,7 +262,7 @@ class EmployeeView(MasterView):
employee._departments.append(model.EmployeeDepartment(department_uuid=uuid)) employee._departments.append(model.EmployeeDepartment(department_uuid=uuid))
for uuid in old_depts: for uuid in old_depts:
if uuid not in new_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) employee.departments.remove(dept)
def get_possible_stores(self): def get_possible_stores(self):

View file

@ -1024,7 +1024,7 @@ class MasterView(View):
""" """
# mustn't use tailbone web session here # mustn't use tailbone web session here
session = RattailSession() session = RattailSession()
obj = session.query(self.model_class).get(uuid) obj = session.get(self.model_class, uuid)
try: try:
self.populate_object(session, obj, progress=progress) self.populate_object(session, obj, progress=progress)
except Exception as error: except Exception as error:
@ -1727,7 +1727,7 @@ class MasterView(View):
if uuids: if uuids:
uuids = uuids.split(',') uuids = uuids.split(',')
# TODO: probably need to allow override of fetcher callable # 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 = [] objects = []
for uuid in uuids: for uuid in uuids:
obj = fetcher(uuid) obj = fetcher(uuid)
@ -1856,7 +1856,7 @@ class MasterView(View):
model_key = self.get_model_key(as_tuple=True) model_key = self.get_model_key(as_tuple=True)
if len(model_key) == 1 and model_key[0] == 'uuid': if len(model_key) == 1 and model_key[0] == 'uuid':
uuid = key[0] uuid = key[0]
return session.query(self.model_class).get(uuid) return session.get(self.model_class, uuid)
raise NotImplementedError raise NotImplementedError
def execute_thread(self, key, user_uuid, progress=None, **kwargs): def execute_thread(self, key, user_uuid, progress=None, **kwargs):
@ -1865,7 +1865,7 @@ class MasterView(View):
""" """
session = RattailSession() session = RattailSession()
obj = self.get_instance_for_key(key, session) obj = self.get_instance_for_key(key, session)
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
success_msg = self.execute_instance(obj, user, success_msg = self.execute_instance(obj, user,
progress=progress, progress=progress,
@ -2021,8 +2021,8 @@ class MasterView(View):
if self.request.method == 'POST': if self.request.method == 'POST':
uuids = self.request.POST.get('uuids', '').split(',') uuids = self.request.POST.get('uuids', '').split(',')
if len(uuids) == 2: if len(uuids) == 2:
object_to_remove = self.Session.query(self.get_model_class()).get(uuids[0]) object_to_remove = self.Session.get(self.get_model_class(), uuids[0])
object_to_keep = self.Session.query(self.get_model_class()).get(uuids[1]) 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': if object_to_remove and object_to_keep and self.request.POST.get('commit-merge') == 'yes':
msg = str(object_to_remove) msg = str(object_to_remove)
@ -4447,7 +4447,7 @@ class MasterView(View):
# TODO: is this right..? # TODO: is this right..?
# key = self.request.matchdict[self.get_model_key()] # key = self.request.matchdict[self.get_model_key()]
key = self.request.matchdict['row_uuid'] 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: if not instance:
raise self.notfound() raise self.notfound()
return instance return instance

View file

@ -279,7 +279,7 @@ class MessageView(MasterView):
message.sender = self.request.user message.sender = self.request.user
for uuid in data['set_recipients']: for uuid in data['set_recipients']:
user = self.Session.query(model.User).get(uuid) user = self.Session.get(model.User, uuid)
if user: if user:
message.add_recipient(user, status=self.enum.MESSAGE_STATUS_INBOX) message.add_recipient(user, status=self.enum.MESSAGE_STATUS_INBOX)

View file

@ -171,10 +171,10 @@ class PersonView(MasterView):
# TODO: I don't recall why this fallback check for a vendor contact # TODO: I don't recall why this fallback check for a vendor contact
# exists here, but leaving it intact for now. # exists here, but leaving it intact for now.
key = self.request.matchdict['uuid'] key = self.request.matchdict['uuid']
instance = self.Session.query(model.Person).get(key) instance = self.Session.get(model.Person, key)
if instance: if instance:
return instance return instance
instance = self.Session.query(model.VendorContact).get(key) instance = self.Session.get(model.VendorContact, key)
if instance: if instance:
return instance.person return instance.person
raise HTTPNotFound raise HTTPNotFound
@ -677,7 +677,7 @@ class PersonView(MasterView):
person = self.get_instance() person = self.get_instance()
data = dict(self.request.json_body) 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: if not phone:
return {'error': "Phone not found."} return {'error': "Phone not found."}
@ -708,7 +708,7 @@ class PersonView(MasterView):
data = dict(self.request.json_body) data = dict(self.request.json_body)
# validate phone # validate phone
phone = self.Session.query(model.PersonPhoneNumber).get(data['phone_uuid']) phone = self.Session.get(model.PersonPhoneNumber, data['phone_uuid'])
if not phone: if not phone:
return {'error': "Phone not found."} return {'error': "Phone not found."}
if phone not in person.phones: if phone not in person.phones:
@ -731,7 +731,7 @@ class PersonView(MasterView):
data = dict(self.request.json_body) data = dict(self.request.json_body)
# validate phone # validate phone
phone = self.Session.query(model.PersonPhoneNumber).get(data['phone_uuid']) phone = self.Session.get(model.PersonPhoneNumber, data['phone_uuid'])
if not phone: if not phone:
return {'error': "Phone not found."} return {'error': "Phone not found."}
if phone not in person.phones: if phone not in person.phones:
@ -792,7 +792,7 @@ class PersonView(MasterView):
person = self.get_instance() person = self.get_instance()
data = dict(self.request.json_body) 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: if not email:
return {'error': "Email not found."} return {'error': "Email not found."}
@ -819,7 +819,7 @@ class PersonView(MasterView):
data = dict(self.request.json_body) data = dict(self.request.json_body)
# validate email # validate email
email = self.Session.query(model.PersonEmailAddress).get(data['email_uuid']) email = self.Session.get(model.PersonEmailAddress, data['email_uuid'])
if not email: if not email:
return {'error': "Email not found."} return {'error': "Email not found."}
if email not in person.emails: if email not in person.emails:
@ -843,7 +843,7 @@ class PersonView(MasterView):
data = dict(self.request.json_body) data = dict(self.request.json_body)
# validate email # validate email
email = self.Session.query(model.PersonEmailAddress).get(data['email_uuid']) email = self.Session.get(model.PersonEmailAddress, data['email_uuid'])
if not email: if not email:
return {'error': "Email not found."} return {'error': "Email not found."}
if email not in person.emails: if email not in person.emails:
@ -944,7 +944,7 @@ class PersonView(MasterView):
employee = person.employee employee = person.employee
uuid = self.request.json_body['uuid'] 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: if not history or history not in employee.history:
return {'error': "Must specify a valid Employee History record for this Person."} 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) return self.profile_edit_note_failure(person, form)
def update_note(self, 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.subject = form.validated['note_subject']
note.text = form.validated['note_text'] note.text = form.validated['note_text']
return note return note
@ -1054,7 +1054,7 @@ class PersonView(MasterView):
return self.profile_delete_note_failure(person, form) return self.profile_delete_note_failure(person, form)
def delete_note(self, 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) self.Session.delete(note)
def profile_delete_note_success(self, person): def profile_delete_note_success(self, person):
@ -1065,7 +1065,7 @@ class PersonView(MasterView):
def make_user(self): def make_user(self):
uuid = self.request.POST['person_uuid'] uuid = self.request.POST['person_uuid']
person = self.Session.query(model.Person).get(uuid) person = self.Session.get(model.Person, uuid)
if not person: if not person:
return self.notfound() return self.notfound()
if person.users: if person.users:
@ -1355,7 +1355,7 @@ def valid_note_uuid(node, kw):
session = kw['session'] session = kw['session']
person_uuid = kw['person_uuid'] person_uuid = kw['person_uuid']
def validate(node, value): def validate(node, value):
note = session.query(model.PersonNote).get(value) note = session.get(model.PersonNote, value)
if not note: if not note:
raise colander.Invalid(node, "Note not found") raise colander.Invalid(node, "Note not found")
if note.person.uuid != person_uuid: if note.person.uuid != person_uuid:
@ -1425,15 +1425,15 @@ class MergePeopleRequestView(MasterView):
def render_referenced_person_name(self, merge_request, field): def render_referenced_person_name(self, merge_request, field):
uuid = getattr(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: if person:
return str(person) return str(person)
return "(person not found)" return "(person not found)"
def get_instance_title(self, merge_request): def get_instance_title(self, merge_request):
model = self.model model = self.model
removing = self.Session.query(model.Person).get(merge_request.removing_uuid) removing = self.Session.get(model.Person, merge_request.removing_uuid)
keeping = self.Session.query(model.Person).get(merge_request.keeping_uuid) keeping = self.Session.get(model.Person, merge_request.keeping_uuid)
return "{} -> {}".format( return "{} -> {}".format(
removing or "(not found)", removing or "(not found)",
keeping or "(not found)") keeping or "(not found)")
@ -1446,7 +1446,7 @@ class MergePeopleRequestView(MasterView):
def render_referenced_person(self, merge_request, field): def render_referenced_person(self, merge_request, field):
uuid = getattr(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: if person:
text = str(person) text = str(person)
url = self.request.route_url('people.view', uuid=person.uuid) url = self.request.route_url('people.view', uuid=person.uuid)

View file

@ -808,10 +808,10 @@ class ProductView(MasterView):
def get_instance(self): def get_instance(self):
key = self.request.matchdict['uuid'] key = self.request.matchdict['uuid']
product = self.Session.query(model.Product).get(key) product = self.Session.get(model.Product, key)
if product: if product:
return product return product
price = self.Session.query(model.ProductPrice).get(key) price = self.Session.get(model.ProductPrice, key)
if price: if price:
return price.product return price.product
raise self.notfound() raise self.notfound()
@ -956,7 +956,7 @@ class ProductView(MasterView):
brand_display = "" brand_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('brand_uuid'): 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: if brand:
brand_display = str(brand) brand_display = str(brand)
elif self.editing: elif self.editing:
@ -1751,12 +1751,12 @@ class ProductView(MasterView):
model = self.model model = self.model
profile = self.request.params.get('profile') 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: if not profile:
return {'error': "Label profile not found"} return {'error': "Label profile not found"}
product = self.request.params.get('product') 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}
@ -1901,7 +1901,7 @@ class ProductView(MasterView):
} }
uuid = self.request.GET.get('with_vendor_cost') uuid = self.request.GET.get('with_vendor_cost')
if uuid: if uuid:
vendor = self.Session.query(model.Vendor).get(uuid) vendor = self.Session.get(model.Vendor, uuid)
if not vendor: if not vendor:
return {'error': "Vendor not found"} return {'error': "Vendor not found"}
cost = product.cost_for_vendor(vendor) cost = product.cost_for_vendor(vendor)
@ -2068,7 +2068,7 @@ class ProductView(MasterView):
Threat target for making a batch from current products query. Threat target for making a batch from current products query.
""" """
session = RattailSession() session = RattailSession()
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
assert user assert user
params['created_by'] = user params['created_by'] = user
try: try:
@ -2288,7 +2288,7 @@ class PendingProductView(MasterView):
brand_display = "" brand_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('brand_uuid'): 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: if brand:
brand_display = str(brand) brand_display = str(brand)
elif self.editing: elif self.editing:
@ -2315,7 +2315,7 @@ class PendingProductView(MasterView):
vendor_display = "" vendor_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('vendor_uuid'): 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: if vendor:
vendor_display = str(vendor) vendor_display = str(vendor)
f.set_widget('vendor_uuid', forms.widgets.JQueryAutocompleteWidget( f.set_widget('vendor_uuid', forms.widgets.JQueryAutocompleteWidget(
@ -2414,7 +2414,7 @@ class PendingProductView(MasterView):
redirect = self.redirect(self.get_action_url('view', pending)) redirect = self.redirect(self.get_action_url('view', pending))
uuid = self.request.POST['product_uuid'] uuid = self.request.POST['product_uuid']
product = self.Session.query(model.Product).get(uuid) product = self.Session.get(model.Product, uuid)
if not product: if not product:
self.request.session.flash("Product not found!", 'error') self.request.session.flash("Product not found!", 'error')
return redirect return redirect

View file

@ -150,7 +150,7 @@ class PurchaseCreditView(MasterView):
for uuid in self.request.POST.get('uuids', '').split(','): for uuid in self.request.POST.get('uuids', '').split(','):
uuid = uuid.strip() uuid = uuid.strip()
if uuid: if uuid:
credit = self.Session.query(model.PurchaseCredit).get(uuid) credit = self.Session.get(model.PurchaseCredit, uuid)
if credit: if credit:
credits_.append(credit) credits_.append(credit)
if not credits_: if not credits_:

View file

@ -271,7 +271,7 @@ class PurchasingBatchView(BatchMasterView):
vendor_display = "" vendor_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('vendor_uuid'): 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: if vendor:
vendor_display = str(vendor) vendor_display = str(vendor)
vendors_url = self.request.route_url('vendors.autocomplete') vendors_url = self.request.route_url('vendors.autocomplete')
@ -304,7 +304,7 @@ class PurchasingBatchView(BatchMasterView):
buyer_display = "" buyer_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('buyer_uuid'): 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: if buyer:
buyer_display = str(buyer) buyer_display = str(buyer)
elif self.creating: elif self.creating:
@ -331,7 +331,7 @@ class PurchasingBatchView(BatchMasterView):
kwargs = {} kwargs = {}
if 'vendor_uuid' in self.request.matchdict: if 'vendor_uuid' in self.request.matchdict:
vendor = self.Session.query(model.Vendor).get( vendor = self.Session.get(model.Vendor,
self.request.matchdict['vendor_uuid']) self.request.matchdict['vendor_uuid'])
if vendor: if vendor:
kwargs['vendor'] = vendor kwargs['vendor'] = vendor
@ -397,7 +397,7 @@ class PurchasingBatchView(BatchMasterView):
def valid_vendor_uuid(self, node, value): def valid_vendor_uuid(self, node, value):
model = self.model model = self.model
vendor = self.Session.query(model.Vendor).get(value) vendor = self.Session.get(model.Vendor, value)
if not vendor: if not vendor:
raise colander.Invalid(node, "Invalid vendor selection") raise colander.Invalid(node, "Invalid vendor selection")
@ -495,7 +495,7 @@ class PurchasingBatchView(BatchMasterView):
def eligible_purchases(self, vendor_uuid=None, mode=None): def eligible_purchases(self, vendor_uuid=None, mode=None):
if not vendor_uuid: if not vendor_uuid:
vendor_uuid = self.request.GET.get('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: if not vendor:
return {'error': "Must specify a vendor."} return {'error': "Must specify a vendor."}
@ -572,7 +572,7 @@ class PurchasingBatchView(BatchMasterView):
self.enum.PURCHASE_BATCH_MODE_COSTING): self.enum.PURCHASE_BATCH_MODE_COSTING):
purchase = batch.purchase purchase = batch.purchase
if not purchase and batch.purchase_uuid: 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 assert purchase
if purchase: if purchase:
kwargs['purchase'] = purchase kwargs['purchase'] = purchase

View file

@ -207,7 +207,7 @@ class CostingBatchView(PurchasingBatchView):
vendor_display = "" vendor_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('vendor'): 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: if vendor:
vendor_display = str(vendor) vendor_display = str(vendor)
vendors_url = self.request.route_url('vendors.autocomplete') vendors_url = self.request.route_url('vendors.autocomplete')
@ -258,7 +258,7 @@ class CostingBatchView(PurchasingBatchView):
if self.creating and workflow: if self.creating and workflow:
# display vendor but do not allow changing # display vendor but do not allow changing
vendor = self.Session.query(model.Vendor).get( vendor = self.Session.get(model.Vendor,
self.request.matchdict['vendor_uuid']) self.request.matchdict['vendor_uuid'])
assert vendor assert vendor

View file

@ -241,7 +241,7 @@ class OrderingBatchView(PurchasingBatchView):
assert not (batch.executed or batch.complete) assert not (batch.executed or batch.complete)
uuid = data.get('row_uuid') 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: if not row:
return {'error': "Row not found"} return {'error': "Row not found"}
if row.batch is not batch or row.removed: 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)} return {'error': "Invalid value for units ordered: {}".format(units_ordered)}
uuid = data.get('product_uuid') 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: if not product:
return {'error': "Product not found"} return {'error': "Product not found"}

View file

@ -280,7 +280,7 @@ class ReceivingBatchView(PurchasingBatchView):
# someone e.g. navigates to a URL by accident etc. we want # someone e.g. navigates to a URL by accident etc. we want
# to gracefully handle and redirect # to gracefully handle and redirect
uuid = self.request.matchdict['vendor_uuid'] uuid = self.request.matchdict['vendor_uuid']
vendor = self.Session.query(model.Vendor).get(uuid) vendor = self.Session.get(model.Vendor, uuid)
if not vendor: if not vendor:
self.request.session.flash("Invalid vendor selection. " self.request.session.flash("Invalid vendor selection. "
"Please choose an existing vendor.", "Please choose an existing vendor.",
@ -337,7 +337,7 @@ class ReceivingBatchView(PurchasingBatchView):
vendor_display = "" vendor_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('vendor'): 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: if vendor:
vendor_display = str(vendor) vendor_display = str(vendor)
vendors_url = self.request.route_url('vendors.autocomplete') vendors_url = self.request.route_url('vendors.autocomplete')
@ -417,7 +417,7 @@ class ReceivingBatchView(PurchasingBatchView):
if self.creating and workflow: if self.creating and workflow:
# display vendor but do not allow changing # display vendor but do not allow changing
vendor = self.Session.query(model.Vendor).get( vendor = self.Session.get(model.Vendor,
self.request.matchdict['vendor_uuid']) self.request.matchdict['vendor_uuid'])
assert vendor assert vendor
f.set_readonly('vendor_uuid') f.set_readonly('vendor_uuid')
@ -944,7 +944,7 @@ class ReceivingBatchView(PurchasingBatchView):
def validate_purchase(node, kw): def validate_purchase(node, kw):
session = kw['session'] session = kw['session']
def validate(node, value): def validate(node, value):
purchase = session.query(model.Purchase).get(value) purchase = session.get(model.Purchase, value)
if not purchase: if not purchase:
raise colander.Invalid(node, "Purchase not found") raise colander.Invalid(node, "Purchase not found")
return purchase.uuid return purchase.uuid
@ -1439,7 +1439,7 @@ class ReceivingBatchView(PurchasingBatchView):
credit = None credit = None
uuid = data.get('uuid') uuid = data.get('uuid')
if uuid: if uuid:
credit = self.Session.query(model.PurchaseBatchCredit).get(uuid) credit = self.Session.get(model.PurchaseBatchCredit, uuid)
if not credit: if not credit:
return {'error': "Credit not found"} return {'error': "Credit not found"}
@ -1479,7 +1479,7 @@ class ReceivingBatchView(PurchasingBatchView):
batch = self.get_instance() batch = self.get_instance()
row_uuid = self.request.params.get('row_uuid') 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: if row and row.batch is batch and not row.removed:
pass # we're good pass # we're good
else: else:
@ -1841,7 +1841,7 @@ class ReceivingBatchView(PurchasingBatchView):
# validate row # validate row
uuid = data.get('row_uuid') 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: if not row or row.batch is not batch:
return {'error': "Row not found"} return {'error': "Row not found"}
@ -1910,7 +1910,7 @@ class ReceivingBatchView(PurchasingBatchView):
Thread target for receiving all items on the given batch. Thread target for receiving all items on the given batch.
""" """
session = RattailSession() session = RattailSession()
batch = session.query(model.PurchaseBatch).get(uuid) batch = session.get(model.PurchaseBatch, uuid)
# user = session.query(model.User).get(user_uuid) # user = session.query(model.User).get(user_uuid)
try: try:
self.handler.auto_receive_all_items(batch, progress=progress) self.handler.auto_receive_all_items(batch, progress=progress)

View file

@ -81,13 +81,13 @@ class OrderingWorksheet(View):
def __call__(self): def __call__(self):
if self.request.params.get('vendor'): 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: if vendor:
departments = [] departments = []
uuids = self.request.params.get('departments') uuids = self.request.params.get('departments')
if uuids: if uuids:
for uuid in uuids.split(','): for uuid in uuids.split(','):
dept = Session.query(model.Department).get(uuid) dept = Session.get(model.Department, uuid)
if dept: if dept:
departments.append(dept) departments.append(dept)
preferred_only = self.request.params.get('preferred_only') == '1' preferred_only = self.request.params.get('preferred_only') == '1'
@ -495,7 +495,7 @@ class ReportOutputView(ExportMasterView):
object. object.
""" """
session = RattailSession() session = RattailSession()
user = session.query(model.User).get(user_uuid) user = session.get(model.User, user_uuid)
try: try:
output = self.report_handler.generate_output(session, report, params, user, progress=progress) output = self.report_handler.generate_output(session, report, params, user, progress=progress)

View file

@ -218,7 +218,7 @@ class SettingView(MasterView):
f.set_validator('name', self.unique_name) f.set_validator('name', self.unique_name)
def unique_name(self, node, value): def unique_name(self, node, value):
setting = self.Session.query(model.Setting).get(value) setting = self.Session.get(model.Setting, value)
if setting: if setting:
raise colander.Invalid(node, "Setting name must be unique") raise colander.Invalid(node, "Setting name must be unique")

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,11 +24,8 @@
Base views for time sheets Base views for time sheets
""" """
from __future__ import unicode_literals, absolute_import
import datetime import datetime
import six
import sqlalchemy as sa import sqlalchemy as sa
from rattail import enum 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: if store_key in self.request.session or department_key in self.request.session:
store_uuid = self.request.session.get(store_key) store_uuid = self.request.session.get(store_key)
if store_uuid: 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) department_uuid = self.request.session.get(department_key)
if department_uuid: if department_uuid:
department = Session.query(model.Department).get(department_uuid) department = Session.get(model.Department, department_uuid)
else: # no store/department in session else: # no store/department in session
if self.default_filter_store: if self.default_filter_store:
store = self.rattail_config.get('rattail', 'store') store = self.rattail_config.get('rattail', 'store')
@ -151,7 +148,7 @@ class TimeSheetView(View):
employee_key = 'timesheet.{}.employee'.format(self.key) employee_key = 'timesheet.{}.employee'.format(self.key)
if employee_key in self.request.session: if employee_key in self.request.session:
employee_uuid = self.request.session[employee_key] 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: if not employee:
employee = self.request.user.employee employee = self.request.user.employee
@ -238,7 +235,7 @@ class TimeSheetView(View):
form = forms.Form(schema=EmployeeShiftFilter(), request=self.request) form = forms.Form(schema=EmployeeShiftFilter(), request=self.request)
if self.request.has_perm('{}.viewall'.format(permission_prefix)): 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') employees_url = self.request.route_url('employees.autocomplete')
form.set_widget('employee', forms.widgets.JQueryAutocompleteWidget( form.set_widget('employee', forms.widgets.JQueryAutocompleteWidget(
field_display=employee_display, service_url=employees_url)) field_display=employee_display, service_url=employees_url))
@ -470,7 +467,7 @@ class TimeSheetView(View):
if hours_style == 'pretty': if hours_style == 'pretty':
display = pretty_hours(hours) display = pretty_hours(hours)
else: # decimal else: # decimal
display = six.text_type(hours_as_decimal(hours)) display = str(hours_as_decimal(hours))
if empday['hours_incomplete']: if empday['hours_incomplete']:
display = '{} ?'.format(display) display = '{} ?'.format(display)
empday['{}_hours_display'.format(shift_type)] = display empday['{}_hours_display'.format(shift_type)] = display
@ -481,7 +478,7 @@ class TimeSheetView(View):
if hours_style == 'pretty': if hours_style == 'pretty':
display = pretty_hours(hours) display = pretty_hours(hours)
else: # decimal else: # decimal
display = six.text_type(hours_as_decimal(hours)) display = str(hours_as_decimal(hours))
if hours_incomplete: if hours_incomplete:
display = '{} ?'.format(display) display = '{} ?'.format(display)
setattr(employee, '{}_hours_display'.format(shift_type), display) setattr(employee, '{}_hours_display'.format(shift_type), display)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Views for employee schedules Views for employee schedules
""" """
from __future__ import unicode_literals, absolute_import
import datetime import datetime
from rattail.db import model from rattail.db import model
@ -81,7 +79,7 @@ class ScheduleView(TimeSheetView):
deleted = [] deleted = []
for uuid, value in data['delete'].items(): for uuid, value in data['delete'].items():
if value == 'delete': if value == 'delete':
shift = Session.query(model.ScheduledShift).get(uuid) shift = Session.get(model.ScheduledShift, uuid)
if shift: if shift:
Session.delete(shift) Session.delete(shift)
deleted.append(uuid) deleted.append(uuid)
@ -103,7 +101,7 @@ class ScheduleView(TimeSheetView):
Session.add(shift) Session.add(shift)
created[uuid] = shift created[uuid] = shift
else: else:
shift = Session.query(model.ScheduledShift).get(uuid) shift = Session.get(model.ScheduledShift, uuid)
assert shift assert shift
updated[uuid] = shift updated[uuid] = shift
start_time = datetime.datetime.strptime(data['start_time'][uuid], time_format) start_time = datetime.datetime.strptime(data['start_time'][uuid], time_format)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,8 +24,6 @@
Views for employee time sheets Views for employee time sheets
""" """
from __future__ import unicode_literals, absolute_import
import datetime import datetime
from rattail.db import model from rattail.db import model
@ -74,7 +72,7 @@ class TimeSheetView(BaseTimeSheetView):
deleted = [] deleted = []
for uuid, value in list(data['delete'].items()): for uuid, value in list(data['delete'].items()):
assert value == 'delete' assert value == 'delete'
shift = Session.query(model.WorkedShift).get(uuid) shift = Session.get(model.WorkedShift, uuid)
assert shift assert shift
Session.delete(shift) Session.delete(shift)
deleted.append(uuid) deleted.append(uuid)
@ -93,7 +91,7 @@ class TimeSheetView(BaseTimeSheetView):
Session.add(shift) Session.add(shift)
created[uuid] = shift created[uuid] = shift
else: else:
shift = Session.query(model.WorkedShift).get(uuid) shift = Session.get(model.WorkedShift, uuid)
assert shift assert shift
updated[uuid] = shift updated[uuid] = shift

View file

@ -45,7 +45,7 @@ class TempmonDashboardView(View):
appliance = None appliance = None
uuid = self.request.POST.get('appliance_uuid') uuid = self.request.POST.get('appliance_uuid')
if uuid: if uuid:
appliance = TempmonSession.query(tempmon.Appliance).get(uuid) appliance = TempmonSession.get(tempmon.Appliance, uuid)
if appliance: if appliance:
self.request.session[self.session_key] = appliance.uuid self.request.session[self.session_key] = appliance.uuid
if not appliance: if not appliance:
@ -91,7 +91,7 @@ class TempmonDashboardView(View):
uuid = self.request.params.get('appliance_uuid') uuid = self.request.params.get('appliance_uuid')
if not uuid: if not uuid:
return {'error': "Must specify valid appliance_uuid"} return {'error': "Must specify valid appliance_uuid"}
appliance = TempmonSession.query(tempmon.Appliance).get(uuid) appliance = TempmonSession.get(tempmon.Appliance, uuid)
if not appliance: if not appliance:
return {'error': "Must specify valid appliance_uuid"} return {'error': "Must specify valid appliance_uuid"}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,9 +24,6 @@
User Views User Views
""" """
from __future__ import unicode_literals, absolute_import
import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
@ -168,7 +165,7 @@ class UserView(PrincipalMasterView):
""" """
if value: if value:
model = self.model model = self.model
person = self.Session.query(model.Person).get(value) person = self.Session.get(model.Person, value)
if not person: if not person:
raise colander.Invalid(node, "Person not found (you must *select* a record)") raise colander.Invalid(node, "Person not found (you must *select* a record)")
@ -189,11 +186,11 @@ class UserView(PrincipalMasterView):
person_display = "" person_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('person_uuid'): 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: if person:
person_display = six.text_type(person) person_display = str(person)
elif self.editing: 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') people_url = self.request.route_url('people.autocomplete')
f.set_widget('person_uuid', forms.widgets.JQueryAutocompleteWidget( f.set_widget('person_uuid', forms.widgets.JQueryAutocompleteWidget(
field_display=person_display, service_url=people_url)) field_display=person_display, service_url=people_url))
@ -224,7 +221,7 @@ class UserView(PrincipalMasterView):
f.remove_field('roles') f.remove_field('roles')
else: else:
roles = self.get_possible_roles().all() 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()) f.set_node('roles', colander.Set())
size = len(roles) size = len(roles)
if size < 3: if size < 3:
@ -358,7 +355,7 @@ class UserView(PrincipalMasterView):
for uuid in old_roles: for uuid in old_roles:
if uuid not in new_roles: if uuid not in new_roles:
if self.request.is_root or uuid != admin.uuid: 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) user.roles.remove(role)
# also record a change to the role, for datasync. # also record a change to the role, for datasync.
@ -373,7 +370,7 @@ class UserView(PrincipalMasterView):
person = user.person person = user.person
if not person: if not person:
return "" return ""
text = six.text_type(person) text = str(person)
url = self.request.route_url('people.view', uuid=person.uuid) url = self.request.route_url('people.view', uuid=person.uuid)
return tags.link_to(person, url) return tags.link_to(person, url)
@ -383,7 +380,7 @@ class UserView(PrincipalMasterView):
name = getattr(user, field[:-1], None) name = getattr(user, field[:-1], None)
if not name: if not name:
return "" return ""
return six.text_type(name) return str(name)
def render_roles(self, user, field): def render_roles(self, user, field):
roles = sorted(user.roles, key=lambda r: r.name) roles = sorted(user.roles, key=lambda r: r.name)