diff --git a/angular_app/import-persons.html b/angular_app/import-persons.html index e94d014..3f22ea0 100644 --- a/angular_app/import-persons.html +++ b/angular_app/import-persons.html @@ -19,8 +19,16 @@ - + {{'deduplicate entries' | translate}} +
+
+ +
+ +
+ {{progress}}% +
Result: total: {{reply.total}} valid: {{reply.valid}} new: {{reply.new_in_event}}
diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 4facb25..e0be19d 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -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); }); }; diff --git a/eventman_server.py b/eventman_server.py index 331acda..69f25be 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -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)