コード例 #1
0
def export_attendees_csv_task(self, event_id):
    attendees = db.session.query(TicketHolder).filter_by(event_id=event_id)
    try:
        filedir = os.path.join(current_app.config.get('BASE_DIR'),
                               'static/uploads/temp/')
        if not os.path.isdir(filedir):
            os.makedirs(filedir)
        filename = "attendees-{}.csv".format(uuid.uuid1().hex)
        file_path = os.path.join(filedir, filename)

        with open(file_path, "w") as temp_file:
            writer = csv.writer(temp_file)
            from app.api.helpers.csv_jobs_util import export_attendees_csv
            content = export_attendees_csv(attendees)
            for row in content:
                writer.writerow(row)
        attendees_csv_file = UploadedFile(file_path=file_path,
                                          filename=filename)
        attendees_csv_url = upload(
            attendees_csv_file,
            UPLOAD_PATHS['exports-temp']['csv'].format(event_id=event_id,
                                                       identifier=''))
        result = {'download_url': attendees_csv_url}
    except Exception as e:
        result = {'__error': True, 'result': str(e)}
        logging.error('Error in exporting attendees list as CSV')

    return result
コード例 #2
0
def export_attendees_csv_task(self, event_id):
    attendees = db.session.query(TicketHolder).filter_by(event_id=event_id)
    try:
        filedir = os.path.join(current_app.config.get('BASE_DIR'), 'static/uploads/temp/')
        if not os.path.isdir(filedir):
            os.makedirs(filedir)
        filename = "attendees-{}.csv".format(uuid.uuid1().hex)
        file_path = os.path.join(filedir, filename)

        with open(file_path, "w") as temp_file:
            writer = csv.writer(temp_file)
            from app.api.helpers.csv_jobs_util import export_attendees_csv
            content = export_attendees_csv(attendees)
            for row in content:
                writer.writerow(row)
        attendees_csv_file = UploadedFile(file_path=file_path, filename=filename)
        attendees_csv_url = upload(attendees_csv_file,
                                   UPLOAD_PATHS['exports-temp']['csv'].format(event_id=event_id, identifier=''))
        result = {
            'download_url': attendees_csv_url
        }
    except Exception as e:
        print(traceback.format_exc())
        result = {'__error': True, 'result': str(e)}

    return result