計算機科学のブログ

ほしい物リスト

Python - SQLite - List Comprehensions: Database Integrations - file

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 13.(List Comprehensions: Database Integrations)、SHARPEN YOUR PENCIL(606/682)の解答を求めてみる。

コード

webapp/app.py

# import os

from flask import Flask, render_template, request, session


# import swimclub

app = Flask(__name__)
app.secret_key = 'You will never guess'


@app.get('/')
def index():
    return render_template(
        'index.html.j2', title='Welcome to the Swimclub system'
    )


# def populate_data():
#     if 'swimmers' not in session:
#         session['swimmers'] = {}
#         files = os.listdir(swimclub.FOLDER)
#         files.remove('.DS_Store')
#         for file in files:
#             name, *_ = swimclub.read_swim_data(file)
#             if name not in session['swimmers']:
#                 session['swimmers'][name].append(file)


@app.get('/swimmers')
def display_swimmers():
    # populate_data()
    return render_template(
        'select.html.j2',
        title='Select a swimmer',
        url='/showfiles',
        select_id='swimmer',
        data=sorted(session['swimmers']),
    )


@app.post('/showfiles')
def display_swimmer_files():
    # populate_data()
    name = request.form['name']
    return render_template(
        'select.html.j2',
        title='Select an event',
        url='/showbarchart',
        select_id='file',
        data=session['swimmers'][name],
    )


@app.post('/showbarchart')
def show_bar_chart():
    file_id = request.form['file']
    # location = swimclub.produce_bar_chart(file_id, 'templates/')
    # return render_template(location.splot('/')[-1])


if __name__ == '__main__':
    app.run()