Esempio n. 1
0
def feed():
    if request.method == 'POST':
        if request.form['action'] == 'save':
            model.parse_form(request.form)
        if request.form['action'] == 'fetch':
            model.get_new_data('feed')
    template_data = {"items": model.get_lineup('feed')}
    return render_template('feed.html', data=template_data)
Esempio n. 2
0
def feed():
    if request.method == 'POST':
        if request.form['action'] == 'save':
            model.parse_form(request.form)
        if request.form['action'] == 'fetch':
            model.get_new_data()
    template_data = {"items": model.get_posts('published')}
    return render_template('feed.html', data=template_data, page_id='feed')
Esempio n. 3
0
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)
Esempio n. 4
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)
Esempio n. 5
0
    with io.open(f"{build_directory}/{s_name}", "w+", encoding='utf8') as file:
        file.write(s_contents)
    print(f"File saved in {build_directory}: {s_name}")
    return


def build_template():
    print("Building template for DNN")
    template_data = {"posts": model.get_lineup()}
    # html = Environment().from_string(tmpl.core_template).render(data=template_data)
    j2_env = Environment(loader=FileSystemLoader('templates'),
                         trim_blocks=True)
    html = j2_env.get_template('ext_core.html').render(data=template_data)
    html_minified = minify_html(html)
    css = fetch.fetch_css()
    script = Template(tmpl.script_template).substitute(css=css,
                                                       minified=html_minified)
    script_name = f"{cfg.config['project_name']}_{cfg.config['name']}.js"
    save_file_overwrite(script, script_name)
    page = Template(tmpl.page_template).substitute(css=css, core=html)
    page_name = f"{cfg.config['project_name']}_{cfg.config['name']}_preview.html"
    save_file_overwrite(page, page_name)
    pass


if __name__ == "__main__":
    # call api, update database
    model.get_new_data()
    # build template
    build_template()