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 ticket_id: ticket._id
}, function() { }, function() {
$scope._localRemoveTicket(ticket); $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. // Close the Quick ticket modal.
$scope.$close(); $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'}); toaster.pop({type: 'info', title: 'ticket successfully updated'});
}); });
} else { } else {
$scope.addTicket($scope.ticket, function() { $scope.addTicket($scope.ticket);
$scope.showAttendedMessage($scope.ticket, true);
});
} }
}; };

View file

@ -793,6 +793,10 @@ class EventsHandler(CollectionHandler):
# Update an existing entry for a ticket registered at this event. # Update an existing entry for a ticket registered at this event.
self._clean_dict(data) self._clean_dict(data)
uuid, arguments = self.uuid_arguments 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 = dict([('tickets.%s' % k, v) for k, v in arguments.items()])
query['_id'] = id_ query['_id'] = id_
if ticket_id is not None: 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) matching_tickets = self._get_ticket_data(ticket_query, tickets, only_one=False)
nr_matches = len(matching_tickets) nr_matches = len(matching_tickets)
if nr_matches > 1: 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', '')} 'uuid': uuid, 'username': self.current_user_info.get('username', '')}
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
self.set_status(400) self.set_status(400)
return ret return ret
elif nr_matches == 0: 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', '')} 'uuid': uuid, 'username': self.current_user_info.get('username', '')}
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
self.set_status(400) self.set_status(400)

View file

@ -104,7 +104,10 @@ input[type=text].form-control, input[type=search].form-control {
margin-bottom: 4px; margin-bottom: 4px;
} }
:not(.no-enter)#toast-container > div.ng-enter :not(.no-enter)#toast-container > div.ng-enter {
{
transition-duration: .1s; 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) sys.exit(1)
def checkin(self, code): def checkin(self, code):
msg = 'scanning code %s: ' % code
limit_field = self.cfg['event'].getint('limit_field') limit_field = self.cfg['event'].getint('limit_field')
if limit_field: if limit_field:
code = code[:limit_field] code = code[:limit_field]
checkin_url = self.checkin_url + '?' + urllib.parse.urlencode({cfg['event']['field']: code}) params = {cfg['event']['field']: code, '_errorMessage': 'code: %s' % code}
params = dict(self.cfg['actions']) checkin_url = self.checkin_url + '?' + urllib.parse.urlencode(params)
req = self.session.put(checkin_url, json=params) json = dict(self.cfg['actions'])
req = self.session.put(checkin_url, json=json)
try: try:
req.raise_for_status() req.raise_for_status()
msg += 'ok'
except requests.exceptions.HTTPError as ex: 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() req.connection.close()
@ -81,7 +85,7 @@ def scan(port):
ser = serial.Serial(port=port, timeout=1) ser = serial.Serial(port=port, timeout=1)
break break
except serial.serialutil.SerialException as ex: except serial.serialutil.SerialException as ex:
if retry >= 10: if retry >= 20:
print('unable to connect: %s' % ex) print('unable to connect: %s' % ex)
sys.exit(2) sys.exit(2)
time.sleep(1) time.sleep(1)
@ -101,7 +105,6 @@ if __name__ == '__main__':
connector = Connector(cfg) connector = Connector(cfg)
try: try:
for code in scan(port=cfg['connection']['port']): for code in scan(port=cfg['connection']['port']):
print('received code %s' % code)
connector.checkin(code) connector.checkin(code)
except KeyboardInterrupt: except KeyboardInterrupt:
print('exiting...') print('exiting...')