Save OK, heavy tests begins

This commit is contained in:
Michel Roux 2019-12-11 14:45:55 +01:00
parent 12d85cb605
commit e6b4495bad
3 changed files with 26 additions and 2 deletions

24
app.py
View File

@ -142,5 +142,29 @@ def admin_add():
return render_template('admin/add.html', search_form=SearchForm(), titles=titles, add_form=add_form)
@app.route('/admin/save', methods=['POST'])
@auth.login_required
def admin_save():
form = EditForm(request.form)
if form.validate_on_submit():
folder = AnimeFolder.query.filter_by(id=form.folder)
title = AnimeTitle.query.filter_by(name=form.name).first()
title.folder = folder
title.name = form.name
title.keyword = form.keyword.lower() if form.keyword else title.keyword
db.session.add(title)
link = AnimeLink.query.filter_by(id=form.id)
link.title = title
link.link = form.link
link.season = form.season
link.comment = form.comment
link.vf = form.is_vf
db.session.add(link)
db.session.commit()
else:
print(form.errors)
return redirect(url_for('admin'))
if __name__ == '__main__':
app.run('0.0.0.0', APP_PORT, IS_DEBUG)

View File

@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block title %} - Admin Add{% endblock %}
{% block body %}
<form method="post" action="">
<form method="post" action="{{ url_for('admin_save') }}">
{{ add_form.csrf_token }}
{{ add_form.id }}

View File

@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block title %} - Admin Edit {{ link.name }}{% endblock %}
{% block body %}
<form method="post" action="">
<form method="post" action="{{ url_for('admin_save') }}">
{{ edit_form.csrf_token }}
{{ edit_form.id(value=link.id) }}