Add folders management
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2021-07-10 20:59:36 +02:00
parent 72adc1f8c0
commit 4e90a95a0e
7 changed files with 148 additions and 15 deletions

View File

@ -11,7 +11,7 @@ from .config import app, auth, logger, scheduler, ADMIN_USERNAME, ADMIN_PASSWORD
CLOUDPROXY_ENDPOINT CLOUDPROXY_ENDPOINT
from .connectors import get_instance, run_all from .connectors import get_instance, run_all
from .connectors.core import ConnectorLang, ConnectorReturn from .connectors.core import ConnectorLang, ConnectorReturn
from .forms import SearchForm, DeleteForm, EditForm from .forms import SearchForm, DeleteForm, EditForm, FolderDeleteForm, FolderEditForm
if MYSQL_ENABLED: if MYSQL_ENABLED:
from .config import db from .config import db
@ -146,6 +146,50 @@ def admin():
return render_template('admin/list.html', search_form=SearchForm(), folders=folders, action_form=form) return render_template('admin/list.html', search_form=SearchForm(), folders=folders, action_form=form)
@app.route('/admin/folder', methods=['GET', 'POST'])
@mysql_required
@auth.login_required
def folder_list():
form = FolderDeleteForm(request.form)
if form.validate_on_submit():
folder = AnimeFolder.query.filter_by(id=form.id.data).first()
if folder:
form.message = '%s has been successfully deleted' % folder.name
db.session.delete(folder)
db.session.commit()
else:
form._errors = {'id': ['Id %s was not found in the database' % form.id.data]}
folders = AnimeFolder.query.all()
return render_template('admin/folder/list.html', search_form=SearchForm(), folders=folders, action_form=form)
@app.route('/admin/folder/edit', methods=['GET', 'POST'])
@app.route('/admin/folder/edit/<int:folder_id>', methods=['GET', 'POST'])
@mysql_required
@auth.login_required
def folder_edit(folder_id=None):
if folder_id:
folder = AnimeFolder.query.filter_by(id=folder_id).first()
else:
folder = utils.clean_model(AnimeFolder())
form = FolderEditForm(request.form, id=folder.id, name=folder.name, path=folder.path)
if form.validate_on_submit():
# Folder
folder.id = folder_id
folder.name = form.name.data
folder.path = form.path.data
db.session.add(folder)
db.session.commit()
return redirect(url_for('folder_list'))
return render_template('admin/folder/edit.html', search_form=SearchForm(), action_form=form)
@app.route('/admin/edit', methods=['GET', 'POST']) @app.route('/admin/edit', methods=['GET', 'POST'])
@app.route('/admin/edit/<int:link_id>', methods=['GET', 'POST']) @app.route('/admin/edit/<int:link_id>', methods=['GET', 'POST'])
@mysql_required @mysql_required
@ -160,25 +204,30 @@ def admin_edit(link_id=None):
link.vf = False link.vf = False
folders = AnimeFolder.query.all() folders = AnimeFolder.query.all()
form = EditForm(request.form, folder=link.title.folder.id, name=link.title.name, link=link.link, season=link.season, form = EditForm(
keyword=link.title.keyword) request.form,
id=link.id,
folder=link.title.folder.id,
name=link.title.name,
link=link.link,
season=link.season,
keyword=link.title.keyword
)
form.folder.choices = [('', '')] + [(g.id, g.name) for g in folders] form.folder.choices = [('', '')] + [(g.id, g.name) for g in folders]
if form.validate_on_submit(): if form.validate_on_submit():
# Instance for VF tag # Instance for VF tag
instance = get_instance(form.link.data) instance = get_instance(form.link.data)
# Title # Title
link = AnimeLink.query.filter_by(id=form.id.data).first() title = AnimeTitle.query.filter_by(name=form.name.data).first()
link = link if link else AnimeLink()
title = AnimeTitle.query.filter_by(id=link.title_id).first()
title = title if title else AnimeTitle.query.filter_by(name=form.name.data).first()
title = title if title else AnimeTitle() title = title if title else AnimeTitle()
title.folder_id = form.folder.data title.folder_id = form.folder.data
title.name = form.name.data title.name = form.name.data
title.keyword = form.keyword.data.lower() if form.keyword.data else title.keyword title.keyword = form.keyword.data.lower()
db.session.add(title) db.session.add(title)
db.session.commit() db.session.commit()
# Link # Link
link.id = link_id
link.title_id = title.id link.title_id = title.id
link.link = form.link.data link.link = form.link.data
link.season = form.season.data link.season = form.season.data
@ -189,7 +238,7 @@ def admin_edit(link_id=None):
remove_garbage(link) remove_garbage(link)
return redirect(url_for('admin')) return redirect(url_for('admin'))
return render_template('admin/edit.html', search_form=SearchForm(), link=link, folders=folders, action_form=form) return render_template('admin/edit.html', search_form=SearchForm(), folders=folders, action_form=form)
@scheduler.task('interval', id='flaredestroyy', days=1) @scheduler.task('interval', id='flaredestroyy', days=1)

View File

@ -5,7 +5,7 @@ class AnimeFolder(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False) name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False)
path = db.Column(db.String(length=100, collation='utf8mb4_general_ci')) path = db.Column(db.String(length=100, collation='utf8mb4_general_ci'))
titles = db.relationship("AnimeTitle", backref="folder") titles = db.relationship("AnimeTitle", backref="folder", cascade='all,delete-orphan')
class AnimeTitle(db.Model): class AnimeTitle(db.Model):
@ -13,7 +13,7 @@ class AnimeTitle(db.Model):
name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False) name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False)
keyword = db.Column(db.Text(collation='utf8mb4_general_ci'), nullable=False) keyword = db.Column(db.Text(collation='utf8mb4_general_ci'), nullable=False)
folder_id = db.Column(db.Integer, db.ForeignKey('anime_folder.id')) folder_id = db.Column(db.Integer, db.ForeignKey('anime_folder.id'))
links = db.relationship('AnimeLink', backref="title") links = db.relationship('AnimeLink', backref="title", cascade='all,delete-orphan')
class AnimeLink(db.Model): class AnimeLink(db.Model):

View File

@ -121,4 +121,10 @@ label.checkbox {
.table.is-hoverable tbody tr:not(.is-selected):hover { .table.is-hoverable tbody tr:not(.is-selected):hover {
background-color: #333 !important; background-color: #333 !important;
} }
.select > select {
border-color: #363636 !important;
background-color: #0a0a0a !important;
color: #dbdbdb !important;
}
} }

View File

@ -1,9 +1,8 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block title %}- Admin Edit {{ link.name }}{% endblock %} {% block title %}- Admin Edit {{ action_form.name.data }}{% endblock %}
{% block body %} {% block body %}
<form method="post"> <form method="post">
{{ action_form.csrf_token }} {{ action_form.csrf_token }}
{{ action_form.id(value=link.id) }}
<div class="field is-horizontal"> <div class="field is-horizontal">
<div class="field-body"> <div class="field-body">
@ -22,7 +21,7 @@
<datalist id="animes"> <datalist id="animes">
{% for folder in folders %} {% for folder in folders %}
{% for title in folder.titles %} {% for title in folder.titles %}
<option {{ 'selected' if title.id == link.title.id }} <option {{ 'selected' if title.name == action_form.name.data }}
data-folder="{{ title.folder.id }}" value="{{ title.name }}" data-folder="{{ title.folder.id }}" value="{{ title.name }}"
data-keyword="{{ title.keyword }}"> data-keyword="{{ title.keyword }}">
{% endfor %} {% endfor %}
@ -76,7 +75,7 @@
<datalist id="keywords"> <datalist id="keywords">
{% for folder in folders %} {% for folder in folders %}
{% for title in folder.titles %} {% for title in folder.titles %}
<option {{ 'selected' if title.keyword == link.title.keyword }} <option {{ 'selected' if title.keyword == action_form.keyword.data }}
value="{{ title.keyword }}"> value="{{ title.keyword }}">
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -0,0 +1,33 @@
{% extends "layout.html" %}
{% block title %}- Folder Edit {{ action_form.name.data }}{% endblock %}
{% block body %}
<form method="post">
{{ action_form.csrf_token }}
<div class="field is-horizontal">
<div class="field-body">
<div class="field column is-6">
<div class="control is-expanded">
{{ action_form.name(class='input', placeholder='Name') }}
</div>
</div>
<div class="field column">
<div class="control is-expanded">
{{ action_form.path(class='input', placeholder='Path') }}
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-body">
<div class="field column">
<div class="control is-expanded">
<input class="button is-info" type="submit">
</div>
</div>
</div>
</div>
</form>
{% endblock %}

View File

@ -0,0 +1,42 @@
{% extends "layout.html" %}
{% block title %}- Folder List{% endblock %}
{% block add_button %}
<a class="navbar-item has-tooltip-bottom has-tooltip-hidden-desktop" data-tooltip="Add folder"
href="{{ url_for('folder_edit') }}">
<i class="fa fa-plus"></i><i>&nbsp;</i>
<span class="is-hidden-mobile">Add folder</span>
</a>
{% endblock %}
{% block body %}
<table class="table is-bordered is-striped is-narrow is-fullwidth is-hoverable is-size-7">
<thead>
<tr>
<th>Name</th>
<th>Path</th>
<th>Tools</th>
</tr>
</thead>
<tbody>
{% for folder in folders %}
<tr>
<td>{{ folder.name }}</td>
<td>{{ folder.path }}</td>
<td>
<a href="{{ url_for('folder_edit', folder_id=folder.id) }}">
<i class="fa fa-pencil"></i>
</a>
<i>&nbsp;</i>
<form method="post">
{{ action_form.id(value=folder.id) }}
<button class="fa fa-trash fa-button"
onclick="return confirm('Are you sure you want to delete this item ?')">
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -5,6 +5,10 @@
<i class="fa fa-plus"></i><i>&nbsp;</i> <i class="fa fa-plus"></i><i>&nbsp;</i>
<span class="is-hidden-mobile">Add entry</span> <span class="is-hidden-mobile">Add entry</span>
</a> </a>
<a class="navbar-item has-tooltip-bottom has-tooltip-hidden-desktop" data-tooltip="Manage folders" href="{{ url_for('folder_list') }}">
<i class="fa fa-folder-open"></i><i>&nbsp;</i>
<span class="is-hidden-mobile">Manage folders</span>
</a>
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<div class="level-right quick-scroll"> <div class="level-right quick-scroll">