From fa5de8ab3909d74c26b66156029ee8addcad9bcc Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 23 Apr 2017 17:17:54 +0200 Subject: [PATCH] auto-search on multiple matches --- angular_app/js/controllers.js | 3 +++ eventman_server.py | 8 ++++++-- tools/qrcode_reader.py | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 71e024a..441ae49 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -293,6 +293,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', return false; } if (data.error && data.message) { + if (data.searchFor) { + $scope.query = angular.copy(data.searchFor); + } toaster.pop({type: 'error', title: 'Error', body: data.message, timeout: 0, showCloseButton: true}); return; } diff --git a/eventman_server.py b/eventman_server.py index c19352e..ec00567 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -799,6 +799,10 @@ class EventsHandler(CollectionHandler): if '_errorMessage' in arguments: _errorMessage = arguments['_errorMessage'] del arguments['_errorMessage'] + _searchFor = False + if '_searchFor' in arguments: + _searchFor = arguments['_searchFor'] + del arguments['_searchFor'] query = dict([('tickets.%s' % k, v) for k, v in arguments.items()]) query['_id'] = id_ if ticket_id is not None: @@ -818,13 +822,13 @@ class EventsHandler(CollectionHandler): nr_matches = len(matching_tickets) if nr_matches > 1: ret = {'error': True, 'message': 'more than one ticket matched. %s' % _errorMessage, 'query': query, - 'uuid': uuid, 'username': self.current_user_info.get('username', '')} + 'searchFor': _searchFor, 'uuid': uuid, 'username': self.current_user_info.get('username', '')} self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.set_status(400) return ret elif nr_matches == 0: ret = {'error': True, 'message': 'no ticket matched. %s' % _errorMessage, 'query': query, - 'uuid': uuid, 'username': self.current_user_info.get('username', '')} + 'searchFor': _searchFor, 'uuid': uuid, 'username': self.current_user_info.get('username', '')} self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.set_status(400) return ret diff --git a/tools/qrcode_reader.py b/tools/qrcode_reader.py index dc6a5d5..89affbb 100755 --- a/tools/qrcode_reader.py +++ b/tools/qrcode_reader.py @@ -75,7 +75,7 @@ class ImprovedEncoder(json.JSONEncoder): datetime.time, datetime.timedelta)): try: return str(o) - except Exception as e: + except Exception: pass elif isinstance(o, set): return list(o) @@ -127,7 +127,7 @@ class Connector(): pass if limit_field: code = code[:limit_field] - params = {cfg['event']['field']: code, '_errorMessage': 'code: %s' % code} + params = {cfg['event']['field']: code, '_errorMessage': 'code: %s' % code, '_searchFor': code} checkin_url = self.checkin_url + '?' + urllib.parse.urlencode(params) json = convert(dict(self.cfg['actions'])) req = self.session.put(checkin_url, json=json, timeout=TIMEOUT) @@ -135,7 +135,7 @@ class Connector(): try: req.raise_for_status() msg += 'ok' - except requests.exceptions.HTTPError as ex: + except requests.exceptions.HTTPError: error = True msg += 'error: %s' % req.json().get('message') if not error: