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 config import app, auth, db, ADMIN_USERNAME, ADMIN_PASSWORD, APP_PORT, IS_DEBUG
|
||||||
from connectors import *
|
from connectors import *
|
||||||
from models import AnimeFolder, AnimeTitle, DeleteForm, SearchForm
|
from models import AnimeFolder, DeleteForm, SearchForm
|
||||||
|
|
||||||
|
|
||||||
@auth.verify_password
|
@auth.verify_password
|
||||||
@ -108,14 +108,16 @@ def admin():
|
|||||||
@app.route('/admin/delete', methods=['POST'])
|
@app.route('/admin/delete', methods=['POST'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def admin_delete():
|
def admin_delete():
|
||||||
form = DeleteForm()
|
form = DeleteForm(request.form)
|
||||||
form_id = request.form.id
|
if form.validate_on_submit():
|
||||||
if form.validate_on_submit() and form_id:
|
link = AnimeLink.query.filter_by(id=form.id.data).first()
|
||||||
link = AnimeLink.query.filter_by(id=form_id).first()
|
|
||||||
title = link.title
|
title = link.title
|
||||||
db.session.delete(link)
|
db.session.delete(link)
|
||||||
if not len(title.links):
|
if not len(title.links):
|
||||||
db.session.delete(title)
|
db.session.delete(title)
|
||||||
|
db.session.commit()
|
||||||
|
else:
|
||||||
|
print(form.errors)
|
||||||
return redirect(url_for('admin'))
|
return redirect(url_for('admin'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,11 +30,14 @@ class AnimeLink(db.Model):
|
|||||||
|
|
||||||
|
|
||||||
class SearchForm(FlaskForm):
|
class SearchForm(FlaskForm):
|
||||||
q = SearchField('search', validators=[DataRequired])
|
q = SearchField('search', validators=[DataRequired()])
|
||||||
|
|
||||||
|
|
||||||
class DeleteForm(FlaskForm):
|
class DeleteForm(FlaskForm):
|
||||||
id = HiddenField('id', validators=[DataRequired])
|
class Meta:
|
||||||
|
csrf = False
|
||||||
|
|
||||||
|
id = HiddenField('id', validators=[DataRequired()])
|
||||||
|
|
||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
@ -57,9 +57,10 @@
|
|||||||
</a>
|
</a>
|
||||||
<i> </i>
|
<i> </i>
|
||||||
<form method="post" action="{{ url_for('admin_delete') }}">
|
<form method="post" action="{{ url_for('admin_delete') }}">
|
||||||
{{ delete_form.csrf_token }}
|
|
||||||
{{ delete_form.id(value=link.id) }}
|
{{ 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>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Reference in New Issue
Block a user