From 39fc5faea6d59acbeb7509ce2c66cb4e7e7f8441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=A9fir=20Destiny?= Date: Sat, 7 Dec 2019 23:11:14 +0100 Subject: [PATCH] First admin page works --- app.py | 25 +++++++++----- connectors.py | 2 +- templates/admin/list.html | 70 +++++++++++++++++++++++++++++++++++++++ templates/list.html | 9 ++--- 4 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 templates/admin/list.html diff --git a/app.py b/app.py index 752740c..057f435 100644 --- a/app.py +++ b/app.py @@ -1,15 +1,15 @@ from operator import itemgetter -from flask import redirect, render_template, url_for, request +from flask import redirect, render_template, request, url_for -from config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, IS_DEBUG, APP_PORT, db +from config import app, auth, db, ADMIN_USERNAME, ADMIN_PASSWORD, APP_PORT, IS_DEBUG from connectors import * -from models import SearchForm, AnimeTitle +from models import SearchForm, AnimeFolder, AnimeTitle @auth.verify_password def verify_password(username, password): - return username is ADMIN_USERNAME and password is ADMIN_PASSWORD + return username == ADMIN_USERNAME and password == ADMIN_PASSWORD @app.template_filter('boldify') @@ -22,9 +22,14 @@ def boldify(name): return name -@app.template_filter('shorten') -def shorten(str_to_replace): - return str_to_replace[:30] + '...' if len(str_to_replace) > 30 else str_to_replace +@app.template_filter('flagify') +def flagify(is_vf): + return ConnectorLang.FR.value if is_vf else ConnectorLang.JP.value + + +@app.template_filter('colorify') +def colorify(model): + return Connector.get_instance(model.link, model.title.keyword).color @app.route('/') @@ -89,13 +94,15 @@ def list_animes(): else: results[title.id].append(link) - return render_template('list.html', form=SearchForm(), titles=results, connector=Connector, flags=ConnectorLang) + return render_template('list.html', form=SearchForm(), titles=results) @app.route('/admin') @auth.login_required def admin(): - return 'Hello!' + folders = AnimeFolder.query.all() + + return render_template('admin/list.html', form=SearchForm(), folders=folders) if __name__ == '__main__': diff --git a/connectors.py b/connectors.py index 9c2b328..ba0b845 100644 --- a/connectors.py +++ b/connectors.py @@ -10,7 +10,7 @@ from sys import platform import requests from bs4 import BeautifulSoup -from models import AnimeLink, AnimeTitle +from models import AnimeTitle, AnimeLink class ConnectorReturn(Enum): diff --git a/templates/admin/list.html b/templates/admin/list.html new file mode 100644 index 0000000..85fb57e --- /dev/null +++ b/templates/admin/list.html @@ -0,0 +1,70 @@ +{% extends "layout.html" %} +{% block title %} - Admin List{% endblock %} +{% block body %} +

+ Quick Scroll : + {% for folder in folders %} + {% if not loop.index0 %} + {{ folder.name }} + {% endif %} + {% endfor %} +

+ + + + + + + + + + + + + + {% for folder in folders %} + + + {% for title in folder.titles %} + {% for link in title.links %} + + {% if not loop.index0 %} + + {% endif %} + + + + + + + + + + {% endfor %} + {% endfor %} + {% endfor %} + + +
NameLinkSeasonCommentTools
{{ folder.name }}
+ {{ title.name }} + + {{ link.vf|flagify }} + {{ link.link|urlize(30, target='_blank') }} + + {{ link.season }} + + {{ link.comment|urlize(target='_blank') }} + + + + +   + + + +   + + + +
+{% endblock %} diff --git a/templates/list.html b/templates/list.html index fc4087d..4df19e2 100644 --- a/templates/list.html +++ b/templates/list.html @@ -21,12 +21,9 @@ {% endif %} - {% set instance = connector.get_instance(link.link, '') %} - - {{ flags.FR.value if link.vf else flags.JP.value }} - - {{ link.link|shorten }} - + + {{ link.vf|flagify }} + {{ link.link|urlize(30, target='_blank') }}