improve product views (plus temp hacks)
This commit is contained in:
parent
36c969c7f8
commit
b4193db0f2
|
@ -1,7 +1,20 @@
|
||||||
<%inherit file="/products/base.mako" />
|
<%inherit file="/products/base.mako" />
|
||||||
<%inherit file="/index.mako" />
|
<%inherit file="/index.mako" />
|
||||||
<%def name="menu()">
|
|
||||||
<p>${h.link_to("New Batch from Results", url('products.batch'))}</p>
|
|
||||||
</%def>
|
|
||||||
<%def name="title()">Products</%def>
|
<%def name="title()">Products</%def>
|
||||||
|
|
||||||
|
<%def name="head_tags()">
|
||||||
|
${parent.head_tags()}
|
||||||
|
<style type="text/css">
|
||||||
|
|
||||||
|
div.grid.Product table tbody td.size,
|
||||||
|
div.grid.Product table tbody td.regular_price,
|
||||||
|
div.grid.Product table tbody td.sale_price {
|
||||||
|
padding-right: 6px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</%def>
|
||||||
|
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
|
@ -26,148 +26,246 @@
|
||||||
``rattail.pyramid.views.products`` -- Product Views
|
``rattail.pyramid.views.products`` -- Product Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sqlalchemy.orm import joinedload
|
from edbob.pyramid.filters import filter_ilike
|
||||||
|
from edbob.pyramid.grids import sorter
|
||||||
import transaction
|
from edbob.pyramid.views import GridView
|
||||||
from pyramid.httpexceptions import HTTPFound
|
from edbob.pyramid.views.crud import Crud
|
||||||
from pyramid.view import view_config
|
|
||||||
|
|
||||||
from edbob.pyramid import filters
|
|
||||||
from edbob.pyramid import forms
|
|
||||||
from edbob.pyramid import grids
|
|
||||||
from edbob.pyramid import Session
|
|
||||||
|
|
||||||
import rattail
|
import rattail
|
||||||
from rattail.batches import next_batch_id
|
from rattail.pyramid.forms import (
|
||||||
from rattail.pyramid import util
|
UpcFieldRenderer, RegularPriceFieldRenderer, SalePriceFieldRenderer)
|
||||||
from rattail.pyramid.forms import UpcFieldRenderer
|
|
||||||
|
|
||||||
|
|
||||||
def filter_map():
|
class ProductGrid(GridView):
|
||||||
return filters.get_filter_map(
|
|
||||||
rattail.Product,
|
|
||||||
exact=['upc'],
|
|
||||||
ilike=['description', 'size'],
|
|
||||||
department=filters.filter_ilike(rattail.Department.name),
|
|
||||||
brand=filters.filter_ilike(rattail.Brand.name))
|
|
||||||
|
|
||||||
def search_config(request, fmap):
|
mapped_class = rattail.Product
|
||||||
return filters.get_search_config(
|
route_name = 'products.list'
|
||||||
'products.list', request, fmap,
|
route_prefix = 'product'
|
||||||
include_filter_brand=True,
|
|
||||||
filter_type_brand='lk',
|
|
||||||
include_filter_description=True,
|
|
||||||
filter_type_description='lk',
|
|
||||||
include_filter_department=True,
|
|
||||||
filter_type_department='lk')
|
|
||||||
|
|
||||||
def search_form(config):
|
def join_map(self):
|
||||||
return filters.get_search_form(
|
return {
|
||||||
config, upc="UPC")
|
'brand':
|
||||||
|
lambda q: q.outerjoin(rattail.Brand),
|
||||||
|
'department':
|
||||||
|
lambda q: q.outerjoin(rattail.Department),
|
||||||
|
}
|
||||||
|
|
||||||
def grid_config(request, search, fmap):
|
def filter_map(self):
|
||||||
return grids.get_grid_config(
|
return self.make_filter_map(
|
||||||
'products.list', request, search,
|
exact=['upc'],
|
||||||
filter_map=fmap, sort='description')
|
ilike=['description', 'size'],
|
||||||
|
brand=filter_ilike(rattail.Brand.name),
|
||||||
|
department=filter_ilike(rattail.Department.name))
|
||||||
|
|
||||||
def sort_map():
|
def search_config(self, fmap):
|
||||||
return grids.get_sort_map(
|
return self.make_search_config(
|
||||||
rattail.Product,
|
fmap,
|
||||||
['upc', 'description', 'size'],
|
include_filter_upc=True,
|
||||||
department=grids.sorter(rattail.Department.name),
|
filter_type_upc='eq',
|
||||||
brand=grids.sorter(rattail.Brand.name))
|
include_filter_brand=True,
|
||||||
|
filter_type_brand='lk',
|
||||||
|
include_filter_description=True,
|
||||||
|
filter_type_description='lk',
|
||||||
|
include_filter_department=True,
|
||||||
|
filter_type_department='lk')
|
||||||
|
|
||||||
def query(config):
|
def search_form(self, config):
|
||||||
jmap = {
|
return self.make_search_form(
|
||||||
'department': lambda q: q.outerjoin(rattail.Department),
|
config, upc="UPC")
|
||||||
'brand': lambda q: q.outerjoin(rattail.Brand),
|
|
||||||
}
|
def grid_config(self, search, fmap):
|
||||||
smap = sort_map()
|
kwargs = {}
|
||||||
q = Session.query(rattail.Product)
|
if self.request.has_perm('products.delete'):
|
||||||
q = q.options(joinedload(rattail.Product.department))
|
kwargs['deletable'] = True
|
||||||
q = q.options(joinedload(rattail.Product.brand))
|
return self.make_grid_config(
|
||||||
q = filters.filter_query(q, config, jmap)
|
search, fmap, sort='description', **kwargs)
|
||||||
q = grids.sort_query(q, config, smap, jmap)
|
|
||||||
return q
|
def sort_map(self):
|
||||||
|
return self.make_sort_map(
|
||||||
|
'upc', 'description', 'size', 'regular_price', 'sale_price',
|
||||||
|
brand=sorter(rattail.Brand.name),
|
||||||
|
department=sorter(rattail.Department.name))
|
||||||
|
|
||||||
|
def grid(self, data, config):
|
||||||
|
g = self.make_grid(data, config)
|
||||||
|
g.upc.set(renderer=UpcFieldRenderer)
|
||||||
|
g.regular_price.set(renderer=RegularPriceFieldRenderer)
|
||||||
|
g.sale_price.set(renderer=SalePriceFieldRenderer)
|
||||||
|
g.configure(
|
||||||
|
include=[
|
||||||
|
g.upc.label("UPC"),
|
||||||
|
g.brand,
|
||||||
|
g.description,
|
||||||
|
g.size,
|
||||||
|
g.department,
|
||||||
|
g.regular_price.label("Reg Price"),
|
||||||
|
g.sale_price.label("Sale Price"),
|
||||||
|
],
|
||||||
|
readonly=True)
|
||||||
|
return g
|
||||||
|
|
||||||
|
|
||||||
@view_config(route_name='products.list', renderer='/products/index.mako')
|
class ProductCrud(Crud):
|
||||||
def products(context, request):
|
|
||||||
|
|
||||||
fmap = filter_map()
|
mapped_class = rattail.Product
|
||||||
config = search_config(request, fmap)
|
home_route = 'products.list'
|
||||||
search = search_form(config)
|
|
||||||
config = grid_config(request, search, fmap)
|
|
||||||
products = grids.get_pager(query, config)
|
|
||||||
|
|
||||||
g = forms.AlchemyGrid(
|
def fieldset(self, obj):
|
||||||
rattail.Product, products, config,
|
fs = self.make_fieldset(obj)
|
||||||
gridurl=request.route_url('products.list'))
|
fs.configure(
|
||||||
|
include=[
|
||||||
g.configure(
|
fs.description,
|
||||||
include=[
|
])
|
||||||
g.upc.with_renderer(UpcFieldRenderer).label("UPC"),
|
return fs
|
||||||
g.brand,
|
|
||||||
g.description,
|
|
||||||
g.size,
|
|
||||||
g.department,
|
|
||||||
],
|
|
||||||
readonly=True)
|
|
||||||
|
|
||||||
grid = g.render(class_='clickable products')
|
|
||||||
return grids.render_grid(request, grid, search)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(route_name='products.batch')
|
|
||||||
def batch(context, request):
|
|
||||||
|
|
||||||
fmap = filter_map()
|
|
||||||
config = search_config(request, fmap)
|
|
||||||
search = search_form(config)
|
|
||||||
config = grid_config(request, search, fmap)
|
|
||||||
products = query(config)
|
|
||||||
|
|
||||||
home = HTTPFound(location=request.route_url('products.list'))
|
|
||||||
|
|
||||||
source = util.get_terminal('rattail')
|
|
||||||
if not source:
|
|
||||||
return home
|
|
||||||
|
|
||||||
dct = util.get_dictionary('ITEM_DCT')
|
|
||||||
if not dct:
|
|
||||||
return home
|
|
||||||
|
|
||||||
with transaction.manager:
|
|
||||||
batch = rattail.Batch()
|
|
||||||
Session.add(batch)
|
|
||||||
|
|
||||||
batch.source = source
|
|
||||||
batch.source_description = source.description
|
|
||||||
batch.batch_id = next_batch_id(source.sil_id, consume=True,
|
|
||||||
session=Session())
|
|
||||||
batch.name = '%s.%08u' % (source.sil_id, batch.batch_id)
|
|
||||||
batch.dictionary = dct
|
|
||||||
batch.action_type = rattail.BATCH_ADD
|
|
||||||
batch.description = "products from Rattail"
|
|
||||||
|
|
||||||
for i, col in enumerate(source.source_columns(dct), 1):
|
|
||||||
batch.columns.append(rattail.BatchColumn(
|
|
||||||
ordinal=i,
|
|
||||||
sil_column=col.sil_column,
|
|
||||||
source=source,
|
|
||||||
targeted=True,
|
|
||||||
))
|
|
||||||
|
|
||||||
batch.create_table()
|
|
||||||
batch.add_rows(source, dct, query=products)
|
|
||||||
batch.rowcount = products.count()
|
|
||||||
|
|
||||||
url = request.route_url('batch.edit', uuid=batch.uuid)
|
|
||||||
|
|
||||||
return HTTPFound(location=url)
|
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
config.add_route('products.list', '/products')
|
ProductGrid.add_route(config, 'products.list', '/products')
|
||||||
config.add_route('products.batch', '/products/batch')
|
ProductCrud.add_routes(config)
|
||||||
config.scan(__name__)
|
|
||||||
|
|
||||||
|
# from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
|
# import transaction
|
||||||
|
# from pyramid.httpexceptions import HTTPFound
|
||||||
|
# from pyramid.view import view_config
|
||||||
|
|
||||||
|
# from edbob.pyramid import filters
|
||||||
|
# from edbob.pyramid import forms
|
||||||
|
# from edbob.pyramid import grids
|
||||||
|
# from edbob.pyramid import Session
|
||||||
|
|
||||||
|
# import rattail
|
||||||
|
# from rattail.batches import next_batch_id
|
||||||
|
# from rattail.pyramid import util
|
||||||
|
# from rattail.pyramid.forms import UpcFieldRenderer
|
||||||
|
|
||||||
|
|
||||||
|
# def filter_map():
|
||||||
|
# return filters.get_filter_map(
|
||||||
|
# rattail.Product,
|
||||||
|
# exact=['upc'],
|
||||||
|
# ilike=['description', 'size'],
|
||||||
|
# department=filters.filter_ilike(rattail.Department.name),
|
||||||
|
# brand=filters.filter_ilike(rattail.Brand.name))
|
||||||
|
|
||||||
|
# def search_config(request, fmap):
|
||||||
|
# return filters.get_search_config(
|
||||||
|
# 'products.list', request, fmap,
|
||||||
|
# include_filter_brand=True,
|
||||||
|
# filter_type_brand='lk',
|
||||||
|
# include_filter_description=True,
|
||||||
|
# filter_type_description='lk',
|
||||||
|
# include_filter_department=True,
|
||||||
|
# filter_type_department='lk')
|
||||||
|
|
||||||
|
# def search_form(config):
|
||||||
|
# return filters.get_search_form(
|
||||||
|
# config, upc="UPC")
|
||||||
|
|
||||||
|
# def grid_config(request, search, fmap):
|
||||||
|
# return grids.get_grid_config(
|
||||||
|
# 'products.list', request, search,
|
||||||
|
# filter_map=fmap, sort='description')
|
||||||
|
|
||||||
|
# def sort_map():
|
||||||
|
# return grids.get_sort_map(
|
||||||
|
# rattail.Product,
|
||||||
|
# ['upc', 'description', 'size'],
|
||||||
|
# department=grids.sorter(rattail.Department.name),
|
||||||
|
# brand=grids.sorter(rattail.Brand.name))
|
||||||
|
|
||||||
|
# def query(config):
|
||||||
|
# jmap = {
|
||||||
|
# 'department': lambda q: q.outerjoin(rattail.Department),
|
||||||
|
# 'brand': lambda q: q.outerjoin(rattail.Brand),
|
||||||
|
# }
|
||||||
|
# smap = sort_map()
|
||||||
|
# q = Session.query(rattail.Product)
|
||||||
|
# q = q.options(joinedload(rattail.Product.department))
|
||||||
|
# q = q.options(joinedload(rattail.Product.brand))
|
||||||
|
# q = filters.filter_query(q, config, jmap)
|
||||||
|
# q = grids.sort_query(q, config, smap, jmap)
|
||||||
|
# return q
|
||||||
|
|
||||||
|
|
||||||
|
# @view_config(route_name='products.list', renderer='/products/index.mako')
|
||||||
|
# def products(context, request):
|
||||||
|
|
||||||
|
# fmap = filter_map()
|
||||||
|
# config = search_config(request, fmap)
|
||||||
|
# search = search_form(config)
|
||||||
|
# config = grid_config(request, search, fmap)
|
||||||
|
# products = grids.get_pager(query, config)
|
||||||
|
|
||||||
|
# g = forms.AlchemyGrid(
|
||||||
|
# rattail.Product, products, config,
|
||||||
|
# gridurl=request.route_url('products.list'))
|
||||||
|
|
||||||
|
# g.configure(
|
||||||
|
# include=[
|
||||||
|
# g.upc.with_renderer(UpcFieldRenderer).label("UPC"),
|
||||||
|
# g.brand,
|
||||||
|
# g.description,
|
||||||
|
# g.size,
|
||||||
|
# g.department,
|
||||||
|
# ],
|
||||||
|
# readonly=True)
|
||||||
|
|
||||||
|
# grid = g.render(class_='clickable products')
|
||||||
|
# return grids.render_grid(request, grid, search)
|
||||||
|
|
||||||
|
|
||||||
|
# @view_config(route_name='products.batch')
|
||||||
|
# def batch(context, request):
|
||||||
|
|
||||||
|
# fmap = filter_map()
|
||||||
|
# config = search_config(request, fmap)
|
||||||
|
# search = search_form(config)
|
||||||
|
# config = grid_config(request, search, fmap)
|
||||||
|
# products = query(config)
|
||||||
|
|
||||||
|
# home = HTTPFound(location=request.route_url('products.list'))
|
||||||
|
|
||||||
|
# source = util.get_terminal('rattail')
|
||||||
|
# if not source:
|
||||||
|
# return home
|
||||||
|
|
||||||
|
# dct = util.get_dictionary('ITEM_DCT')
|
||||||
|
# if not dct:
|
||||||
|
# return home
|
||||||
|
|
||||||
|
# with transaction.manager:
|
||||||
|
# batch = rattail.Batch()
|
||||||
|
# Session.add(batch)
|
||||||
|
|
||||||
|
# batch.source = source
|
||||||
|
# batch.source_description = source.description
|
||||||
|
# batch.batch_id = next_batch_id(source.sil_id, consume=True,
|
||||||
|
# session=Session())
|
||||||
|
# batch.name = '%s.%08u' % (source.sil_id, batch.batch_id)
|
||||||
|
# batch.dictionary = dct
|
||||||
|
# batch.action_type = rattail.BATCH_ADD
|
||||||
|
# batch.description = "products from Rattail"
|
||||||
|
|
||||||
|
# for i, col in enumerate(source.source_columns(dct), 1):
|
||||||
|
# batch.columns.append(rattail.BatchColumn(
|
||||||
|
# ordinal=i,
|
||||||
|
# sil_column=col.sil_column,
|
||||||
|
# source=source,
|
||||||
|
# targeted=True,
|
||||||
|
# ))
|
||||||
|
|
||||||
|
# batch.create_table()
|
||||||
|
# batch.add_rows(source, dct, query=products)
|
||||||
|
# batch.rowcount = products.count()
|
||||||
|
|
||||||
|
# url = request.route_url('batch.edit', uuid=batch.uuid)
|
||||||
|
|
||||||
|
# return HTTPFound(location=url)
|
||||||
|
|
||||||
|
|
||||||
|
# def includeme(config):
|
||||||
|
# config.add_route('products.list', '/products')
|
||||||
|
# config.add_route('products.batch', '/products/batch')
|
||||||
|
# config.scan(__name__)
|
||||||
|
|
Loading…
Reference in a new issue