update import persons

This commit is contained in:
Davide Alberani 2016-07-07 23:10:52 +02:00
parent 1fbc069890
commit 2ac2b09bee
2 changed files with 7 additions and 22 deletions

View file

@ -15,7 +15,7 @@
<div class="form-group"> <div class="form-group">
<label for="forEvent">{{'Associate users to this event' | translate}}</label> <label for="forEvent">{{'Associate users to this event' | translate}}</label>
<select class="form-control" id="forEvent" ng-model="targetEvent"> <select class="form-control" id="forEvent" ng-model="targetEvent" ng-required="true">
<option ng-repeat="event in events" value="{{event._id}}">{{event.title}}</option> <option ng-repeat="event in events" value="{{event._id}}">{{event.title}}</option>
</select> </select>
</div> </div>

View file

@ -789,9 +789,9 @@ class EbCSVImportPersonsHandler(BaseHandler):
# import a CSV list of persons # import a CSV list of persons
event_handler = EventsHandler(self.application, self.request) event_handler = EventsHandler(self.application, self.request)
event_handler.db = self.db event_handler.db = self.db
targetEvent = None event_id = None
try: try:
targetEvent = self.get_body_argument('targetEvent') event_id = self.get_body_argument('targetEvent')
except: except:
pass pass
reply = dict(total=0, valid=0, merged=0, new_in_event=0) reply = dict(total=0, valid=0, merged=0, new_in_event=0)
@ -802,24 +802,9 @@ class EbCSVImportPersonsHandler(BaseHandler):
reply['total'] += parseStats['total'] reply['total'] += parseStats['total']
reply['valid'] += parseStats['valid'] reply['valid'] += parseStats['valid']
for person in persons: for person in persons:
person_data = dict([(k, person[k]) for k in self.keepPersonData person['attended'] = False
if k in person]) person['from_file'] = filename
merged, stored_person = self.db.update('persons', event_handler.handle_post_persons(event_id, None, person)
[('email', 'name', 'surname')],
person_data)
if merged:
reply['merged'] += 1
if targetEvent and stored_person:
event_id = targetEvent
person_id = stored_person['_id']
registered_data = {
'person_id': person_id,
'attended': False,
'from_file': filename}
person.update(registered_data)
if not self.db.query('events',
{'_id': event_id, 'persons.person_id': person_id}):
event_handler.handle_post_persons(event_id, person_id, person)
reply['new_in_event'] += 1 reply['new_in_event'] += 1
self.write(reply) self.write(reply)