示例#1
0
文件: app.py 项目: Timunroe/world_cup
def lineup():
    # get data
    if request.method == 'POST':
        if request.form['action'] == 'save':
            model.parse_form(request.form)
        if request.form['action'] == 'deploy':
            model.parse_form(request.form)
            data.build_template()
            fetch.put_S3()
        if request.form['action'] == 'fetch':
            model.get_new_data()
    template_data = {"items": model.get_lineup()}
    return render_template('lineup.html', data=template_data, draft_check=False)
示例#2
0
def index():
    if request.method == 'POST':
        if request.form['action'] == 'fetch_cp':
            db = model.get_api()
            return render_template('index.html', data=db)
        if request.form['action'] == 'deploy_cp':
            # read file cp.db
            with open('cp.db') as json_data:
                db = json.load(json_data)
            data.build_template(db)
            fetch.put_S3()
            return render_template('index.html', data=db)
        if request.form['action'] == 'fetch_manual':
            return render_template('index.html', data=model.db)
        if request.form['action'] == 'deploy_manual':
            data.build_template(model.db)
            fetch.put_S3()
            return render_template('index.html', data=model.db)
    return render_template('index.html', data=model.db)
示例#3
0
def lineup(page_id):
    # get data
    # file_name = f'pages_{page_id}_lineup.html'
    if request.method == 'POST':
        if request.form['action'] == 'save':
            model.parse_form(request.form)
        if request.form['action'] == 'deploy':
            model.parse_form(request.form)
            data.build_template(page_id)
            fetch.put_S3(
                page_id
            )  # sometimes tries to send before file above finished writing!!!!
            # StackOverflow: https://stackoverflow.com/questions/36274868/saving-an-image-to-bytes-and-uploading-to-boto3-returning-content-md5-mismatch
            # My answer was to create using ".filename" then:
            #   os.rename(filename.replace(".filename","filename"))
            # This ensured the file was done being created.
        if request.form['action'] == 'fetch':
            model.get_new_data(page_id)
    # template_data = {"items": model.get_lineup('published', page_id)}
    template_data = {"items": model.get_posts('published', page_id)}
    # return render_template(file_name, data=template_data, draft_check=False)
    return render_template('pages_lineup.html',
                           data=template_data,
                           page_id=page_id)