Esempio n. 1
0
def saiki_templates_edit():
    """Docstring."""
    if only_check():
        if request.method == 'POST':
            template_form = TemplateForm()
            template_form.validate_on_submit()
            print(template_form)
            if template_form.validate() is False:
                flash('Please check that all the fields are valid!.',
                      'critical')
                return check_and_render('saiki_templates_edit.html',
                                        form=template_form)
            else:
                update_template(template_form)
                flash('updated Config for Topic : ' +
                      template_form.template_name.data)
                return redirect(url_for('saiki_templates'))
        elif request.method == 'GET':
            template = request.args.get('template')
            if template != '' and template is not None:
                template_data = get_saiki_template_single(template)
            else:
                template = ''
                template_data = '{}'
            template_form = TemplateForm(template_name=template,
                                         template_data=template_data)
            return check_and_render('saiki_templates_edit.html',
                                    form=template_form,
                                    template_data=template_data)
    else:
        return check_and_render('index.html')