auto-search on multiple matches

This commit is contained in:
Davide Alberani 2017-04-23 17:17:54 +02:00
parent abb22ab0f8
commit fa5de8ab39
3 changed files with 12 additions and 5 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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: