diff --git a/app.py b/app.py index 057f435..17353d1 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 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/') +@auth.login_required +def admin_edit(id): + return True if __name__ == '__main__': diff --git a/models.py b/models.py index 6481184..f0f0f55 100644 --- a/models.py +++ b/models.py @@ -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() diff --git a/static/css/styles.css b/static/css/styles.css index c8e3910..a8cf405 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -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%; } diff --git a/templates/admin/edit.html b/templates/admin/edit.html new file mode 100644 index 0000000..df54bea --- /dev/null +++ b/templates/admin/edit.html @@ -0,0 +1,5 @@ +{% extends "layout.html" %} +{% block title %} - Admin Edit {% endblock %} +{% block body %} + +{% endblock %} diff --git a/templates/admin/list.html b/templates/admin/list.html index 85fb57e..91266c6 100644 --- a/templates/admin/list.html +++ b/templates/admin/list.html @@ -52,13 +52,15 @@   - +   - - - +
+ {{ delete_form.csrf_token }} + {{ delete_form.id(value=link.id) }} + +
{% endfor %}