From 6212932f7418d618a117e88ec1eb2d3804ede5fb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 1 Aug 2012 05:54:03 -0700 Subject: [PATCH] add label printing to product index --- rattail/pyramid/subscribers.py | 3 + rattail/pyramid/templates/products/index.mako | 70 ++++++++++++++++++- rattail/pyramid/views/products.py | 33 +++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/rattail/pyramid/subscribers.py b/rattail/pyramid/subscribers.py index 25fa04a3..d2219dba 100644 --- a/rattail/pyramid/subscribers.py +++ b/rattail/pyramid/subscribers.py @@ -38,6 +38,9 @@ def before_render(event): * ``rattail`` """ + # Import labels module so it's available if/when needed. + import rattail.labels + request = event.get('request') or threadlocal.get_current_request() renderer_globals = event diff --git a/rattail/pyramid/templates/products/index.mako b/rattail/pyramid/templates/products/index.mako index 31c15174..17933a73 100644 --- a/rattail/pyramid/templates/products/index.mako +++ b/rattail/pyramid/templates/products/index.mako @@ -7,14 +7,80 @@ ${parent.head_tags()} + % if edbob.config.getboolean('rattail.labels', 'enabled', default=False): + + % endif + + +<%def name="tools()"> + % if edbob.config.getboolean('rattail.labels', 'enabled', default=False): + + + + + + + + + + + +
LabelQty.
+ + + +
+ % endif ${parent.body()} diff --git a/rattail/pyramid/views/products.py b/rattail/pyramid/views/products.py index 09d530fb..bb41a463 100644 --- a/rattail/pyramid/views/products.py +++ b/rattail/pyramid/views/products.py @@ -26,12 +26,18 @@ ``rattail.pyramid.views.products`` -- Product Views """ +from webhelpers.html.tags import link_to + from edbob.pyramid.filters import filter_ilike from edbob.pyramid.grids import sorter from edbob.pyramid.views import GridView from edbob.pyramid.views.crud import Crud +import edbob +from edbob.pyramid import Session + import rattail +import rattail.labels from rattail.pyramid.forms import ( UpcFieldRenderer, RegularPriceFieldRenderer, SalePriceFieldRenderer) @@ -102,6 +108,12 @@ class ProductGrid(GridView): g.sale_price.label("Sale Price"), ], readonly=True) + + def callback(prod): + return link_to("Print", '#', class_='print-label') + + if edbob.config.getboolean('rattail.labels', 'enabled', default=False): + g.add_column('labels', "Labels", callback) return g @@ -119,10 +131,31 @@ class ProductCrud(Crud): return fs +def print_label(request): + profile = request.params.get('profile') + profile = rattail.labels.get_profile(profile) if profile else None + assert profile + + uuid = request.params.get('uuid') + product = Session.query(rattail.Product).get(uuid) if uuid else None + assert product + + quantity = request.params.get('quantity') + assert quantity.isdigit() + quantity = int(quantity) + + printer = profile.get_printer() + printer.print_labels([(product, quantity)]) + return {} + + def includeme(config): ProductGrid.add_route(config, 'products.list', '/products') ProductCrud.add_routes(config) + config.add_route('products.print_label', '/products/label') + config.add_view(print_label, route_name='products.print_label', renderer='json') + # from sqlalchemy.orm import joinedload