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,34 +26,42 @@
|
||||||
``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,
|
mapped_class = rattail.Product
|
||||||
|
route_name = 'products.list'
|
||||||
|
route_prefix = 'product'
|
||||||
|
|
||||||
|
def join_map(self):
|
||||||
|
return {
|
||||||
|
'brand':
|
||||||
|
lambda q: q.outerjoin(rattail.Brand),
|
||||||
|
'department':
|
||||||
|
lambda q: q.outerjoin(rattail.Department),
|
||||||
|
}
|
||||||
|
|
||||||
|
def filter_map(self):
|
||||||
|
return self.make_filter_map(
|
||||||
exact=['upc'],
|
exact=['upc'],
|
||||||
ilike=['description', 'size'],
|
ilike=['description', 'size'],
|
||||||
department=filters.filter_ilike(rattail.Department.name),
|
brand=filter_ilike(rattail.Brand.name),
|
||||||
brand=filters.filter_ilike(rattail.Brand.name))
|
department=filter_ilike(rattail.Department.name))
|
||||||
|
|
||||||
def search_config(request, fmap):
|
def search_config(self, fmap):
|
||||||
return filters.get_search_config(
|
return self.make_search_config(
|
||||||
'products.list', request, fmap,
|
fmap,
|
||||||
|
include_filter_upc=True,
|
||||||
|
filter_type_upc='eq',
|
||||||
include_filter_brand=True,
|
include_filter_brand=True,
|
||||||
filter_type_brand='lk',
|
filter_type_brand='lk',
|
||||||
include_filter_description=True,
|
include_filter_description=True,
|
||||||
|
@ -61,113 +69,203 @@ def search_config(request, fmap):
|
||||||
include_filter_department=True,
|
include_filter_department=True,
|
||||||
filter_type_department='lk')
|
filter_type_department='lk')
|
||||||
|
|
||||||
def search_form(config):
|
def search_form(self, config):
|
||||||
return filters.get_search_form(
|
return self.make_search_form(
|
||||||
config, upc="UPC")
|
config, upc="UPC")
|
||||||
|
|
||||||
def grid_config(request, search, fmap):
|
def grid_config(self, search, fmap):
|
||||||
return grids.get_grid_config(
|
kwargs = {}
|
||||||
'products.list', request, search,
|
if self.request.has_perm('products.delete'):
|
||||||
filter_map=fmap, sort='description')
|
kwargs['deletable'] = True
|
||||||
|
return self.make_grid_config(
|
||||||
|
search, fmap, sort='description', **kwargs)
|
||||||
|
|
||||||
def sort_map():
|
def sort_map(self):
|
||||||
return grids.get_sort_map(
|
return self.make_sort_map(
|
||||||
rattail.Product,
|
'upc', 'description', 'size', 'regular_price', 'sale_price',
|
||||||
['upc', 'description', 'size'],
|
brand=sorter(rattail.Brand.name),
|
||||||
department=grids.sorter(rattail.Department.name),
|
department=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'))
|
|
||||||
|
|
||||||
|
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(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.upc.with_renderer(UpcFieldRenderer).label("UPC"),
|
g.upc.label("UPC"),
|
||||||
g.brand,
|
g.brand,
|
||||||
g.description,
|
g.description,
|
||||||
g.size,
|
g.size,
|
||||||
g.department,
|
g.department,
|
||||||
|
g.regular_price.label("Reg Price"),
|
||||||
|
g.sale_price.label("Sale Price"),
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
return g
|
||||||
grid = g.render(class_='clickable products')
|
|
||||||
return grids.render_grid(request, grid, search)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(route_name='products.batch')
|
class ProductCrud(Crud):
|
||||||
def batch(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 = query(config)
|
|
||||||
|
|
||||||
home = HTTPFound(location=request.route_url('products.list'))
|
def fieldset(self, obj):
|
||||||
|
fs = self.make_fieldset(obj)
|
||||||
source = util.get_terminal('rattail')
|
fs.configure(
|
||||||
if not source:
|
include=[
|
||||||
return home
|
fs.description,
|
||||||
|
])
|
||||||
dct = util.get_dictionary('ITEM_DCT')
|
return fs
|
||||||
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