diff --git a/app.py b/app.py index 546b51c..1020857 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 AnimeFolder, DeleteForm, SearchForm +from models import AnimeFolder, DeleteForm, SearchForm, EditForm @auth.verify_password @@ -34,7 +34,7 @@ def colorify(model): @app.route('/') def home(): - return render_template('layout.html', form=SearchForm()) + return render_template('layout.html', search_form=SearchForm()) @app.route('/search') @@ -51,7 +51,7 @@ def search(): AnimeUltime(query).run(), ] - return render_template('search.html', form=SearchForm(), connectors=results) + return render_template('search.html', search_form=SearchForm(), connectors=results) @app.route('/latest') @@ -73,7 +73,7 @@ def latest(): result['self'] = Connector.get_instance(result['href'], '') results.sort(key=itemgetter('date'), reverse=True) - return render_template('latest.html', form=SearchForm(), torrents=results, page=page) + return render_template('latest.html', search_form=SearchForm(), torrents=results, page=page) @app.route('/list') @@ -94,7 +94,7 @@ def list_animes(): else: results[title.id].append(link) - return render_template('list.html', form=SearchForm(), titles=results) + return render_template('list.html', search_form=SearchForm(), titles=results) @app.route('/admin') @@ -102,7 +102,7 @@ def list_animes(): def admin(): folders = AnimeFolder.query.all() - return render_template('admin/list.html', form=SearchForm(), folders=folders, delete_form=DeleteForm()) + return render_template('admin/list.html', search_form=SearchForm(), folders=folders, delete_form=DeleteForm()) @app.route('/admin/delete', methods=['POST']) @@ -121,10 +121,25 @@ def admin_delete(): return redirect(url_for('admin')) -@app.route('/admin/edit/') +@app.route('/admin/edit/') @auth.login_required -def admin_edit(id): - return True +def admin_edit(link_id): + link = AnimeLink.query.filter_by(id=link_id).first() + edit_form = EditForm() + edit_form.folder.choices = [(query.id, query.name) for query in AnimeFolder.query.all()] + titles = AnimeTitle.query.all() + + return render_template('admin/edit.html', search_form=SearchForm(), link=link, titles=titles, edit_form=edit_form) + + +@app.route('/admin/add') +@auth.login_required +def admin_add(): + add_form = EditForm() + add_form.folder.choices = [('', '')] + [(query.id, query.name) for query in AnimeFolder.query.all()] + titles = AnimeTitle.query.all() + + return render_template('admin/add.html', search_form=SearchForm(), titles=titles, add_form=add_form) if __name__ == '__main__': diff --git a/models.py b/models.py index ac87a95..9b7677c 100644 --- a/models.py +++ b/models.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm -from wtforms import HiddenField -from wtforms.fields.html5 import SearchField +from wtforms import BooleanField, HiddenField, SelectField, StringField +from wtforms.fields.html5 import SearchField, URLField from wtforms.validators import DataRequired from config import db @@ -40,4 +40,15 @@ class DeleteForm(FlaskForm): id = HiddenField('id', validators=[DataRequired()]) +class EditForm(FlaskForm): + id = HiddenField('id', validators=[DataRequired()]) + folder = SelectField('folder', validators=[DataRequired()]) + name = StringField('name', validators=[DataRequired()]) + link = URLField('link', validators=[DataRequired()]) + season = StringField('season', validators=[DataRequired()]) + comment = StringField('comment') + keyword = StringField('keyword') + is_vf = BooleanField('is_vf') + + db.create_all() diff --git a/templates/admin/add.html b/templates/admin/add.html new file mode 100644 index 0000000..4d14848 --- /dev/null +++ b/templates/admin/add.html @@ -0,0 +1,91 @@ +{% extends "layout.html" %} +{% block title %} - Admin Add{% endblock %} +{% block body %} +
+ {{ add_form.csrf_token }} + {{ add_form.id }} + +
+
+
+
+
+ {{ add_form.folder }} +
+
+
+ +
+
+
+ {{ add_form.name(list='animes', class='input', placeholder='Name') }} + + {% for title in titles %} + + {% endfor %} + +
+
+
+
+
+ +
+
+
+
+ {{ add_form.link(class='input', placeholder='Link') }} +
+
+ +
+
+ {{ add_form.season(class='input', placeholder='Season') }} +
+
+
+
+ +
+
+
+
+ {{ add_form.comment(class='input', placeholder='Comment') }} +
+
+ +
+
+
+ {{ add_form.keyword(list='keywords', class='input', placeholder='Keyword') }} + + {% for title in titles %} + + {% endfor %} + +
+
+
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+{% endblock %} diff --git a/templates/admin/edit.html b/templates/admin/edit.html index df54bea..3b62b7a 100644 --- a/templates/admin/edit.html +++ b/templates/admin/edit.html @@ -1,5 +1,91 @@ {% extends "layout.html" %} -{% block title %} - Admin Edit {% endblock %} +{% block title %} - Admin Edit {{ link.name }}{% endblock %} {% block body %} +
+ {{ edit_form.csrf_token }} + {{ edit_form.id(value=link.id) }} +
+
+
+
+
+ {{ edit_form.folder }} +
+
+
+ +
+
+
+ {{ edit_form.name(value=link.title.name, list='animes', class='input', placeholder='Name') }} + + {% for title in titles %} + + {% endfor %} + +
+
+
+
+
+ +
+
+
+
+ {{ edit_form.link(value=link.link, class='input', placeholder='Link') }} +
+
+ +
+
+ {{ edit_form.season(value=link.season, class='input', placeholder='Season') }} +
+
+
+
+ +
+
+
+
+
+ {{ edit_form.comment(value=link.comment, class='input', placeholder='Comment') }} +
+
+
+ +
+
+ {{ edit_form.keyword(value=link.title.keyword, list='keywords', class='input', placeholder='Keyword') }} + + {% for title in titles %} + + {% endfor %} + +
+
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index 23109dd..773a4fc 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -46,7 +46,7 @@