Changeset - e46fbbd62ccd
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-10-15 16:50:18
lance@edbob.org
Limit autocomplete results for customer/phone lookup in new custorder

otherwise it's possible for the whole thing to bog down and freeze the
browser page...
1 file changed with 8 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -352,12 +352,16 @@ class CustomerOrderBatchHandler(BatchHandler):
 
                        for word in term.split()]
 
            query = query.filter(sa.and_(*criteria))
 

	
 
        # oh, and sort by something useful
 
        query = query.order_by(model.Customer.name)
 

	
 
        # and finally, limit the number of results to something a
 
        # browser is likely to be able to handle easily!
 
        query = query[:100]     # TODO: make configurable?
 

	
 
        # generate result list from query
 
        results = []
 
        for customer in query:
 
            phone = customer.first_phone()
 
            if phone:
 
                label = "{} {}".format(customer.name, phone.number)
 
@@ -398,12 +402,16 @@ class CustomerOrderBatchHandler(BatchHandler):
 
                        for word in term.split()]
 
            query = query.filter(sa.and_(*criteria))
 

	
 
        # oh, and sort by something useful
 
        query = query.order_by(model.Person.display_name)
 

	
 
        # and finally, limit the number of results to something a
 
        # browser is likely to be able to handle easily!
 
        query = query[:100]     # TODO: make configurable?
 

	
 
        # generate result list from query
 
        results = []
 
        for person in query:
 
            phone = person.first_phone()
 
            if phone:
 
                label = "{} {}".format(person.display_name, phone.number)
0 comments (0 inline, 0 general)