def import_locations(self, upload_id, mappings, location_set_id, channel=None): upload = UserUpload.query.filter(UserUpload.id == upload_id).first() if not upload: logger.error('Upload %s does not exist, aborting', upload_id) return filepath = uploads.path(upload.upload_filename) if not os.path.exists(filepath): logger.error('Upload file %s does not exist, aborting', filepath) upload.delete() return with open(filepath, 'rb') as f: dataframe = helpers.load_source_file(f) location_set = LocationSet.query.filter( LocationSet.id == location_set_id).first() update_locations(dataframe, mappings, location_set, self) os.remove(filepath) upload.delete() msg_body = render_template_string(email_template) send_email(_('Locations Import Report'), msg_body, [upload.user.email])
def import_participants(upload_id, mappings): upload = services.user_uploads.get(pk=upload_id) dataframe = helpers.load_source_file(upload.data) count, errors, warnings = update_participants(dataframe, upload.event, mappings) # delete uploaded file upload.data.delete() upload.delete() msg_body = generate_response_email(count, errors, warnings) send_email(_('Import report'), msg_body, [upload.user.email])
def import_participants(upload_id, mappings): upload = services.user_uploads.get(pk=upload_id) dataframe = helpers.load_source_file(upload.data) count, errors, warnings = update_participants( dataframe, upload.event, mappings ) # delete uploaded file upload.data.delete() upload.delete() msg_body = generate_response_email(count, errors, warnings) send_email(_('Import report'), msg_body, [upload.user.email])
def import_locations(upload_id, mappings): upload = services.user_uploads.get(pk=upload_id) dataframe = helpers.load_source_file(upload.data) update_locations(dataframe, mappings, upload.event) # fetch and update all submissions deployment = upload.event.deployment submissions = services.submissions.all().filter(deployment=deployment) for submission in submissions: if submission.location: submission.location_name_path = helpers.compute_location_path(submission.location) submission.save(clean=False) # delete uploaded file upload.data.delete() upload.delete() msg_body = render_template_string(email_template) send_email(_("Locations Import Report"), msg_body, [upload.user.email])
def import_locations(upload_id, mappings): upload = services.user_uploads.get(pk=upload_id) dataframe = helpers.load_source_file(upload.data) update_locations(dataframe, mappings, upload.event) # fetch and update all submissions deployment = upload.event.deployment submissions = services.submissions.all().filter(deployment=deployment) for submission in submissions: if submission.location: submission.location_name_path = helpers.compute_location_path( submission.location) submission.save(clean=False) # delete uploaded file upload.data.delete() upload.delete() msg_body = render_template_string(email_template) send_email(_('Locations Import Report'), msg_body, [upload.user.email])
def import_participants( self, upload_id, mappings, participant_set_id, channel=None): upload = services.user_uploads.find(id=upload_id).first() if not upload: logger.error('Upload %s does not exist, aborting', upload_id) return filepath = uploads.path(upload.upload_filename) if not os.path.exists(filepath): logger.error('Upload file %s does not exist, aborting', filepath) upload.delete() return with open(filepath, 'rb') as f: dataframe = helpers.load_source_file(f) participant_set = services.participant_sets.find( id=participant_set_id).first() if not participant_set: _cleanup_upload(filepath, upload) logger.error( 'Participant set with id {} does not exist, aborting'.format( participant_set_id)) count, errors, warnings = update_participants( dataframe, mappings, participant_set, self ) # delete uploaded file os.remove(filepath) upload.delete() msg_body = generate_response_email(count, errors, warnings) send_email(_('Import report'), msg_body, [upload.user.email])