add extra error information

This commit is contained in:
Davide Alberani 2017-04-15 14:22:05 +02:00
parent d0e4f2188f
commit 1427ba1623
4 changed files with 27 additions and 13 deletions

View file

@ -508,6 +508,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
ticket_id: ticket._id
}, function() {
$scope._localRemoveTicket(ticket);
var msg = $scope.buildTicketLabel(ticket);
msg += ' successfully removed from event ' + $scope.event.title;
toaster.pop({type: 'error', title: msg});
});
};
@ -558,6 +561,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
// Close the Quick ticket modal.
$scope.$close();
}
var msg = $scope.buildTicketLabel(ret_ticket);
msg += ' successfully added to event ' + $scope.event.title;
toaster.pop({type: 'success', title: msg});
}
});
};
@ -600,9 +606,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
toaster.pop({type: 'info', title: 'ticket successfully updated'});
});
} else {
$scope.addTicket($scope.ticket, function() {
$scope.showAttendedMessage($scope.ticket, true);
});
$scope.addTicket($scope.ticket);
}
};

View file

@ -793,6 +793,10 @@ class EventsHandler(CollectionHandler):
# Update an existing entry for a ticket registered at this event.
self._clean_dict(data)
uuid, arguments = self.uuid_arguments
_errorMessage = ''
if '_errorMessage' in arguments:
_errorMessage = arguments['_errorMessage']
del arguments['_errorMessage']
query = dict([('tickets.%s' % k, v) for k, v in arguments.items()])
query['_id'] = id_
if ticket_id is not None:
@ -811,13 +815,13 @@ class EventsHandler(CollectionHandler):
matching_tickets = self._get_ticket_data(ticket_query, tickets, only_one=False)
nr_matches = len(matching_tickets)
if nr_matches > 1:
ret = {'error': True, 'message': 'more than one ticket matched', 'query': query,
ret = {'error': True, 'message': 'more than one ticket matched. %s' % _errorMessage, 'query': query,
'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', 'query': query,
ret = {'error': True, 'message': 'no ticket matched. %s' % _errorMessage, 'query': query,
'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)

View file

@ -104,7 +104,10 @@ input[type=text].form-control, input[type=search].form-control {
margin-bottom: 4px;
}
:not(.no-enter)#toast-container > div.ng-enter
{
:not(.no-enter)#toast-container > div.ng-enter {
transition-duration: .1s;
}
:not(.no-leave)#toast-container > div.ng-leave {
transition-duration: .2s;
}

View file

@ -60,16 +60,20 @@ class Connector():
sys.exit(1)
def checkin(self, code):
msg = 'scanning code %s: ' % code
limit_field = self.cfg['event'].getint('limit_field')
if limit_field:
code = code[:limit_field]
checkin_url = self.checkin_url + '?' + urllib.parse.urlencode({cfg['event']['field']: code})
params = dict(self.cfg['actions'])
req = self.session.put(checkin_url, json=params)
params = {cfg['event']['field']: code, '_errorMessage': 'code: %s' % code}
checkin_url = self.checkin_url + '?' + urllib.parse.urlencode(params)
json = dict(self.cfg['actions'])
req = self.session.put(checkin_url, json=json)
try:
req.raise_for_status()
msg += 'ok'
except requests.exceptions.HTTPError as ex:
print('error: %s' % req.json().get('message'))
msg += 'error: %s' % req.json().get('message')
print(msg)
req.connection.close()
@ -81,7 +85,7 @@ def scan(port):
ser = serial.Serial(port=port, timeout=1)
break
except serial.serialutil.SerialException as ex:
if retry >= 10:
if retry >= 20:
print('unable to connect: %s' % ex)
sys.exit(2)
time.sleep(1)
@ -101,7 +105,6 @@ if __name__ == '__main__':
connector = Connector(cfg)
try:
for code in scan(port=cfg['connection']['port']):
print('received code %s' % code)
connector.checkin(code)
except KeyboardInterrupt:
print('exiting...')