diff --git a/app.py b/app.py index 17353d1..546b51c 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,7 @@ from flask import redirect, render_template, request, url_for from config import app, auth, db, ADMIN_USERNAME, ADMIN_PASSWORD, APP_PORT, IS_DEBUG from connectors import * -from models import AnimeFolder, AnimeTitle, DeleteForm, SearchForm +from models import AnimeFolder, DeleteForm, SearchForm @auth.verify_password @@ -108,14 +108,16 @@ def admin(): @app.route('/admin/delete', methods=['POST']) @auth.login_required def admin_delete(): - form = DeleteForm() - form_id = request.form.id - if form.validate_on_submit() and form_id: - link = AnimeLink.query.filter_by(id=form_id).first() + form = DeleteForm(request.form) + if form.validate_on_submit(): + link = AnimeLink.query.filter_by(id=form.id.data).first() title = link.title db.session.delete(link) if not len(title.links): db.session.delete(title) + db.session.commit() + else: + print(form.errors) return redirect(url_for('admin')) diff --git a/models.py b/models.py index f0f0f55..ac87a95 100644 --- a/models.py +++ b/models.py @@ -30,11 +30,14 @@ class AnimeLink(db.Model): class SearchForm(FlaskForm): - q = SearchField('search', validators=[DataRequired]) + q = SearchField('search', validators=[DataRequired()]) class DeleteForm(FlaskForm): - id = HiddenField('id', validators=[DataRequired]) + class Meta: + csrf = False + + id = HiddenField('id', validators=[DataRequired()]) db.create_all() diff --git a/templates/admin/list.html b/templates/admin/list.html index 91266c6..289b9a3 100644 --- a/templates/admin/list.html +++ b/templates/admin/list.html @@ -57,9 +57,10 @@