From ab406851751c4f3b40d3e7faeb6e89fa573139a7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 7 Dec 2015 15:07:48 -0600 Subject: [PATCH] Clean up products view imports etc. a bit. --- tailbone/views/products.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 5baf6284..2dc17a7f 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -24,20 +24,18 @@ Product Views """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import os import re import sqlalchemy as sa from sqlalchemy import orm -from sqlalchemy import and_ -from sqlalchemy.orm import joinedload, aliased import formalchemy -from webhelpers.html.tags import link_to from pyramid.httpexceptions import HTTPFound from pyramid.renderers import render_to_response +from webhelpers.html import tags import rattail.labels from rattail import enum @@ -72,15 +70,15 @@ class ProductsGrid(SearchableAlchemyGridView): # These aliases enable the grid queries to filter products which may be # purchased from *any* vendor, and yet sort by only the "preferred" vendor # (since that's what shows up in the grid column). - ProductCostAny = aliased(ProductCost) - VendorAny = aliased(Vendor) + ProductCostAny = orm.aliased(ProductCost) + VendorAny = orm.aliased(Vendor) def join_map(self): def join_vendor(q): q = q.outerjoin( ProductCost, - and_( + sa.and_( ProductCost.product_uuid == Product.uuid, ProductCost.preference == 1, )) @@ -166,12 +164,12 @@ class ProductsGrid(SearchableAlchemyGridView): q = self.make_query() if not self.request.has_perm('products.view_deleted'): q = q.filter(model.Product.deleted == False) - q = q.options(joinedload(Product.brand)) - q = q.options(joinedload(Product.department)) - q = q.options(joinedload(Product.subdepartment)) - q = q.options(joinedload(Product.regular_price)) - q = q.options(joinedload(Product.current_price)) - q = q.options(joinedload(Product.vendor)) + q = q.options(orm.joinedload(Product.brand)) + q = q.options(orm.joinedload(Product.department)) + q = q.options(orm.joinedload(Product.subdepartment)) + q = q.options(orm.joinedload(Product.regular_price)) + q = q.options(orm.joinedload(Product.current_price)) + q = q.options(orm.joinedload(Product.vendor)) return q def grid(self): @@ -214,7 +212,7 @@ class ProductsGrid(SearchableAlchemyGridView): q = Session.query(LabelProfile) if q.count(): def labels(row): - return link_to("Print", '#', class_='print-label') + return tags.link_to("Print", '#', class_='print-label') g.add_column('labels', "Labels", labels) return g