Delete ok

This commit is contained in:
Michel Roux 2019-12-09 12:10:57 +01:00
parent 39fc5faea6
commit 6fc13c8c40
5 changed files with 49 additions and 6 deletions

24
app.py
View File

@ -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 SearchForm, AnimeFolder, AnimeTitle from models import AnimeFolder, AnimeTitle, DeleteForm, SearchForm
@auth.verify_password @auth.verify_password
@ -102,7 +102,27 @@ def list_animes():
def admin(): def admin():
folders = AnimeFolder.query.all() 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__': if __name__ == '__main__':

View File

@ -1,4 +1,5 @@
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import HiddenField
from wtforms.fields.html5 import SearchField from wtforms.fields.html5 import SearchField
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
@ -32,4 +33,8 @@ class SearchForm(FlaskForm):
q = SearchField('search', validators=[DataRequired]) q = SearchField('search', validators=[DataRequired])
class DeleteForm(FlaskForm):
id = HiddenField('id', validators=[DataRequired])
db.create_all() db.create_all()

View File

@ -35,6 +35,10 @@ div.navbar-end {
white-space: nowrap; white-space: nowrap;
} }
.table td:last-child form {
display: inline;
}
.table td.is-primary, .table tr.is-primary { .table td.is-primary, .table tr.is-primary {
background-color: rgba(0, 209, 178, 0.2) !important; background-color: rgba(0, 209, 178, 0.2) !important;
border-color: rgba(0, 209, 178, 0.1); border-color: rgba(0, 209, 178, 0.1);
@ -87,6 +91,13 @@ div.navbar-end {
top: 2px; top: 2px;
} }
.fa-button {
padding: 0;
cursor: pointer;
background: none;
border: none;
}
.tooltip.is-tooltip-bottom::before { .tooltip.is-tooltip-bottom::before {
left: 100%; left: 100%;
} }

View File

@ -0,0 +1,5 @@
{% extends "layout.html" %}
{% block title %} - Admin Edit {% endblock %}
{% block body %}
{% endblock %}

View File

@ -52,13 +52,15 @@
<i class="fa fa-search"></i> <i class="fa fa-search"></i>
</a> </a>
<i>&nbsp;</i> <i>&nbsp;</i>
<a href="EDIT_ID"> <a href="{{ url_for('admin_edit', id=link.id) }}">
<i class="fa fa-pencil"></i> <i class="fa fa-pencil"></i>
</a> </a>
<i>&nbsp;</i> <i>&nbsp;</i>
<a href="DELETE_ID" onclick="return confirm('Are you sure you want to delete this item ?')"> <form method="post" action="{{ url_for('admin_delete') }}">
<i class="fa fa-trash"></i> {{ delete_form.csrf_token }}
</a> {{ delete_form.id(value=link.id) }}
<button class="fa fa-trash fa-button"></button>
</form>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}