コード例 #1
0
ファイル: reports.py プロジェクト: KillAChicken/AutoStorage
def download_report(file_id):
    """Download report file."""
    api = get_autostorage_api()
    report_manager = ReportManager(api)

    report_file_query = report_manager.get_report_files().filter_by(file_id=file_id)
    with api.get_session() as session:
        report_file = report_file_query.with_session(session).one()
        file_path = report_file.file_path
    return send_file(REPORTS.path(file_path))
コード例 #2
0
ファイル: reports.py プロジェクト: KillAChicken/AutoStorage
def reports():
    """Return page with report files."""
    api = get_autostorage_api()
    report_manager = ReportManager(api)

    upload_form = UploadReportFileForm()
    if upload_form.validate_on_submit():
        report_file = upload_form.report_file.data
        prepared_name = secure_filename(report_file.filename)  # pylint: disable=no-member
        file_name = REPORTS.save(report_file, name=prepared_name)
        report_manager.add_report_file(file_name)

        flash("File has been uploaded")
        return redirect(url_for("reports"))

    with api.get_session() as session:
        report_files = report_manager.get_report_files().with_session(session).all()

    return render_template("reports.html", report_files=report_files, upload_form=upload_form)