Delete ok (real this time)
This commit is contained in:
parent
6fc13c8c40
commit
4e0f25f419
12
app.py
12
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'))
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -57,9 +57,10 @@
|
||||
</a>
|
||||
<i> </i>
|
||||
<form method="post" action="{{ url_for('admin_delete') }}">
|
||||
{{ delete_form.csrf_token }}
|
||||
{{ delete_form.id(value=link.id) }}
|
||||
<button class="fa fa-trash fa-button"></button>
|
||||
<button class="fa fa-trash fa-button"
|
||||
onclick="return confirm('Are you sure you want to delete this item ?')">
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
Reference in New Issue
Block a user