More refactoring, Query.get() => Session.get()

This commit is contained in:
Lance Edgar 2023-02-12 09:34:38 -06:00
parent f1496c771e
commit b434fa108d
2 changed files with 11 additions and 16 deletions

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,10 +24,6 @@
Base class for customer order batch views Base class for customer order batch views
""" """
from __future__ import unicode_literals, absolute_import
import six
from rattail.db import model from rattail.db import model
import colander import colander
@ -152,12 +148,12 @@ class CustomerOrderBatchView(BatchMasterView):
customer_display = "" customer_display = ""
if self.request.method == 'POST': if self.request.method == 'POST':
if self.request.POST.get('customer_uuid'): if self.request.POST.get('customer_uuid'):
customer = self.Session.query(model.Customer)\ customer = self.Session.get(model.Customer,
.get(self.request.POST['customer_uuid']) self.request.POST['customer_uuid'])
if customer: if customer:
customer_display = six.text_type(customer) customer_display = str(customer)
elif self.editing: elif self.editing:
customer_display = six.text_type(order.customer or "") customer_display = str(order.customer or "")
customers_url = self.request.route_url('customers.autocomplete') customers_url = self.request.route_url('customers.autocomplete')
f.set_widget('customer_uuid', forms.widgets.JQueryAutocompleteWidget( f.set_widget('customer_uuid', forms.widgets.JQueryAutocompleteWidget(
field_display=customer_display, service_url=customers_url)) field_display=customer_display, service_url=customers_url))
@ -172,12 +168,12 @@ class CustomerOrderBatchView(BatchMasterView):
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)\ person = self.Session.get(model.Person,
.get(self.request.POST['person_uuid']) 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(order.person or "") person_display = str(order.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))
@ -194,7 +190,7 @@ class CustomerOrderBatchView(BatchMasterView):
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)

View file

@ -66,8 +66,7 @@ class TempmonDashboardView(View):
self.request.session[self.session_key] = selected_uuid self.request.session[self.session_key] = selected_uuid
if not selected_appliance and selected_uuid: if not selected_appliance and selected_uuid:
selected_appliance = TempmonSession.query(tempmon.Appliance)\ selected_appliance = TempmonSession.get(tempmon.Appliance, selected_uuid)
.get(selected_uuid)
context = { context = {
'index_url': self.request.route_url('tempmon.appliances'), 'index_url': self.request.route_url('tempmon.appliances'),