Clean up products view imports etc. a bit.

This commit is contained in:
Lance Edgar 2015-12-07 15:07:48 -06:00
parent fee00b96a2
commit ab40685175

View file

@ -24,20 +24,18 @@
Product Views Product Views
""" """
from __future__ import unicode_literals from __future__ import unicode_literals, absolute_import
import os import os
import re import re
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
from sqlalchemy import and_
from sqlalchemy.orm import joinedload, aliased
import formalchemy import formalchemy
from webhelpers.html.tags import link_to
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from webhelpers.html import tags
import rattail.labels import rattail.labels
from rattail import enum from rattail import enum
@ -72,15 +70,15 @@ class ProductsGrid(SearchableAlchemyGridView):
# These aliases enable the grid queries to filter products which may be # These aliases enable the grid queries to filter products which may be
# purchased from *any* vendor, and yet sort by only the "preferred" vendor # purchased from *any* vendor, and yet sort by only the "preferred" vendor
# (since that's what shows up in the grid column). # (since that's what shows up in the grid column).
ProductCostAny = aliased(ProductCost) ProductCostAny = orm.aliased(ProductCost)
VendorAny = aliased(Vendor) VendorAny = orm.aliased(Vendor)
def join_map(self): def join_map(self):
def join_vendor(q): def join_vendor(q):
q = q.outerjoin( q = q.outerjoin(
ProductCost, ProductCost,
and_( sa.and_(
ProductCost.product_uuid == Product.uuid, ProductCost.product_uuid == Product.uuid,
ProductCost.preference == 1, ProductCost.preference == 1,
)) ))
@ -166,12 +164,12 @@ class ProductsGrid(SearchableAlchemyGridView):
q = self.make_query() q = self.make_query()
if not self.request.has_perm('products.view_deleted'): if not self.request.has_perm('products.view_deleted'):
q = q.filter(model.Product.deleted == False) q = q.filter(model.Product.deleted == False)
q = q.options(joinedload(Product.brand)) q = q.options(orm.joinedload(Product.brand))
q = q.options(joinedload(Product.department)) q = q.options(orm.joinedload(Product.department))
q = q.options(joinedload(Product.subdepartment)) q = q.options(orm.joinedload(Product.subdepartment))
q = q.options(joinedload(Product.regular_price)) q = q.options(orm.joinedload(Product.regular_price))
q = q.options(joinedload(Product.current_price)) q = q.options(orm.joinedload(Product.current_price))
q = q.options(joinedload(Product.vendor)) q = q.options(orm.joinedload(Product.vendor))
return q return q
def grid(self): def grid(self):
@ -214,7 +212,7 @@ class ProductsGrid(SearchableAlchemyGridView):
q = Session.query(LabelProfile) q = Session.query(LabelProfile)
if q.count(): if q.count():
def labels(row): def labels(row):
return link_to("Print", '#', class_='print-label') return tags.link_to("Print", '#', class_='print-label')
g.add_column('labels', "Labels", labels) g.add_column('labels', "Labels", labels)
return g return g