From 2a04caaf994667367efc1452ef1ccae6c3d41140 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 18 Dec 2014 15:43:49 -0600 Subject: [PATCH] Make product UPC search view strip non-digit chars from input. This is to accomodate the apparently frequent use case of copy/paste which includes the check digit as a "-X" type suffix. --- tailbone/views/products.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 92a32990..7c25fa4d 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -20,7 +20,6 @@ # along with Rattail. If not, see . # ################################################################################ - """ Product Views """ @@ -28,6 +27,7 @@ Product Views from __future__ import unicode_literals import os +import re from sqlalchemy import and_ from sqlalchemy.orm import joinedload, aliased @@ -295,9 +295,9 @@ def products_search(request): Eventually this should be more generic, or at least offer more fields for search. For now it operates only on the ``Product.upc`` field. """ - product = None - upc = request.GET.get('upc') + upc = request.GET.get('upc', '').strip() + upc = re.sub(r'\D', '', upc) if upc: product = get_product_by_upc(Session, upc) if not product: