Delete ok
This commit is contained in:
parent
39fc5faea6
commit
6fc13c8c40
24
app.py
24
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 SearchForm, AnimeFolder, AnimeTitle
|
||||
from models import AnimeFolder, AnimeTitle, DeleteForm, SearchForm
|
||||
|
||||
|
||||
@auth.verify_password
|
||||
@ -102,7 +102,27 @@ def list_animes():
|
||||
def admin():
|
||||
folders = AnimeFolder.query.all()
|
||||
|
||||
return render_template('admin/list.html', form=SearchForm(), folders=folders)
|
||||
return render_template('admin/list.html', form=SearchForm(), folders=folders, delete_form=DeleteForm())
|
||||
|
||||
|
||||
@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()
|
||||
title = link.title
|
||||
db.session.delete(link)
|
||||
if not len(title.links):
|
||||
db.session.delete(title)
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
|
||||
@app.route('/admin/edit/<id>')
|
||||
@auth.login_required
|
||||
def admin_edit(id):
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,4 +1,5 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import HiddenField
|
||||
from wtforms.fields.html5 import SearchField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
@ -32,4 +33,8 @@ class SearchForm(FlaskForm):
|
||||
q = SearchField('search', validators=[DataRequired])
|
||||
|
||||
|
||||
class DeleteForm(FlaskForm):
|
||||
id = HiddenField('id', validators=[DataRequired])
|
||||
|
||||
|
||||
db.create_all()
|
||||
|
@ -35,6 +35,10 @@ div.navbar-end {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.table td:last-child form {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.table td.is-primary, .table tr.is-primary {
|
||||
background-color: rgba(0, 209, 178, 0.2) !important;
|
||||
border-color: rgba(0, 209, 178, 0.1);
|
||||
@ -87,6 +91,13 @@ div.navbar-end {
|
||||
top: 2px;
|
||||
}
|
||||
|
||||
.fa-button {
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.tooltip.is-tooltip-bottom::before {
|
||||
left: 100%;
|
||||
}
|
||||
|
5
templates/admin/edit.html
Normal file
5
templates/admin/edit.html
Normal file
@ -0,0 +1,5 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %} - Admin Edit {% endblock %}
|
||||
{% block body %}
|
||||
|
||||
{% endblock %}
|
@ -52,13 +52,15 @@
|
||||
<i class="fa fa-search"></i>
|
||||
</a>
|
||||
<i> </i>
|
||||
<a href="EDIT_ID">
|
||||
<a href="{{ url_for('admin_edit', id=link.id) }}">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</a>
|
||||
<i> </i>
|
||||
<a href="DELETE_ID" onclick="return confirm('Are you sure you want to delete this item ?')">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
<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>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
Reference in New Issue
Block a user