fixes #126: progress bar and ability to not deduplicate entries

This commit is contained in:
Davide Alberani 2017-04-30 10:21:51 +02:00
parent f338da9078
commit 09035932ad
3 changed files with 32 additions and 10 deletions

View file

@ -19,8 +19,16 @@
</select>
</div>
<input type="submit" value="{{'Import' | translate}}" ng-click="upload(file, '/ebcsvpersons')" />
<input type="checkbox" ng-model="deduplicate"> {{'deduplicate entries' | translate}}
<div>
<br />
<input type="submit" value="{{'Import' | translate}}" ng-click="upload(file, '/ebcsvpersons')" />
</div>
<div class="form-group top5">
<uib-progressbar class="progress-striped" ng-class="{active: progressbarType == 'warning'}" max="100" value="progress" type="progressbarType">{{progress}}%</uib-progressbar>
</div>
<div class="form-group top5">
Result: total: <span>{{reply.total}}</span> valid: <span>{{reply.valid}}</span> new: <span>{{reply.new_in_event}}</span>
</div>

View file

@ -771,19 +771,26 @@ eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '
eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
function ($scope, $log, $upload, Event) {
$scope.file = null;
$scope.progress = 0;
$scope.progressbarType = 'warning';
$scope.deduplicate = false;
$scope.reply = {};
$scope.events = Event.all();
$scope.upload = function(file, url) {
$log.debug("FileUploadCtrl.upload");
$scope.progress = 0;
$scope.progressbarType = 'warning';
$upload.upload({
url: url,
file: file,
fields: {targetEvent: $scope.targetEvent}
fields: {targetEvent: $scope.targetEvent, deduplicate: $scope.deduplicate}
}).progress(function(evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$log.debug('progress: ' + progressPercentage + '%');
$scope.progress = parseInt(100.0 * evt.loaded / evt.total);
$log.debug('progress: ' + $scope.progress + '%');
}).success(function(data, status, headers, config) {
$scope.file = null;
$scope.progress = 100;
$scope.progressbarType = 'success';
$scope.reply = angular.fromJson(data);
});
};

View file

@ -1034,20 +1034,25 @@ class EbCSVImportPersonsHandler(BaseHandler):
event_handler.db = self.db
event_handler.logger = self.logger
event_id = None
deduplicate = False
try:
event_id = self.get_body_argument('targetEvent')
except:
pass
try:
deduplicate = self.tobool(self.get_body_argument('deduplicate'))
except:
pass
if event_id is None:
return self.build_error('invalid event')
reply = dict(total=0, valid=0, merged=0, new_in_event=0)
event_details = event_handler.db.query('events', {'_id': event_id})
if not event_details:
return self.build_error('invalid event')
all_emails = set()
all_persons = set()
#[x.get('email') for x in (event_details[0].get('tickets') or []) if x.get('email')])
for ticket in (event_details[0].get('tickets') or []):
all_emails.add('%s_%s_%s' % (ticket.get('name'), ticket.get('surname'), ticket.get('email')))
all_persons.add('%s_%s_%s' % (ticket.get('name'), ticket.get('surname'), ticket.get('email')))
for fieldname, contents in self.request.files.items():
for content in contents:
filename = content['filename']
@ -1060,10 +1065,12 @@ class EbCSVImportPersonsHandler(BaseHandler):
person['attended'] = False
person['from_file'] = filename
self.add_access_info(person)
duplicate_check = '%s_%s_%s' % (person.get('name'), person.get('surname'), person.get('email'))
if duplicate_check in all_emails:
continue
all_emails.add(duplicate_check)
if deduplicate:
duplicate_check = '%s_%s_%s_%s' % (person.get('name'), person.get('surname'),
person.get('email'), person.get('order_nr'))
if duplicate_check in all_persons:
continue
all_persons.add(duplicate_check)
event_handler.handle_post_tickets(event_id, None, person)
reply['new_in_event'] += 1
self.write(reply)