First admin page works

This commit is contained in:
Michel Roux 2019-12-07 23:11:14 +01:00
parent 820014e8d8
commit 39fc5faea6
4 changed files with 90 additions and 16 deletions

25
app.py
View File

@ -1,15 +1,15 @@
from operator import itemgetter 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 connectors import *
from models import SearchForm, AnimeTitle from models import SearchForm, AnimeFolder, AnimeTitle
@auth.verify_password @auth.verify_password
def verify_password(username, 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') @app.template_filter('boldify')
@ -22,9 +22,14 @@ def boldify(name):
return name return name
@app.template_filter('shorten') @app.template_filter('flagify')
def shorten(str_to_replace): def flagify(is_vf):
return str_to_replace[:30] + '...' if len(str_to_replace) > 30 else str_to_replace 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('/') @app.route('/')
@ -89,13 +94,15 @@ def list_animes():
else: else:
results[title.id].append(link) 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') @app.route('/admin')
@auth.login_required @auth.login_required
def admin(): def admin():
return 'Hello!' folders = AnimeFolder.query.all()
return render_template('admin/list.html', form=SearchForm(), folders=folders)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -10,7 +10,7 @@ from sys import platform
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from models import AnimeLink, AnimeTitle from models import AnimeTitle, AnimeLink
class ConnectorReturn(Enum): class ConnectorReturn(Enum):

70
templates/admin/list.html Normal file
View File

@ -0,0 +1,70 @@
{% extends "layout.html" %}
{% block title %} - Admin List{% endblock %}
{% block body %}
<p id="quick_scroll">
Quick Scroll :
{% for folder in folders %}
{% if not loop.index0 %}
<a href="#{{ folder.name }}">{{ folder.name }}</a>
{% endif %}
{% endfor %}
</p>
<table class="table is-bordered is-striped is-narrow is-fullwidth is-hoverable is-size-7">
<thead>
<tr>
<th>Name</th>
<th>Link</th>
<th>Season</th>
<th>Comment</th>
<th>Tools</th>
</tr>
</thead>
<tbody>
{% for folder in folders %}
<th colspan="5" id="{{ folder.name }}">{{ folder.name }}</th>
{% for title in folder.titles %}
{% for link in title.links %}
<tr>
{% if not loop.index0 %}
<td rowspan="{{ title.links|length }}">
{{ title.name }}
</td>
{% endif %}
<td class="{{ link|colorify }}">
{{ link.vf|flagify }}
{{ link.link|urlize(30, target='_blank') }}
</td>
<td>
{{ link.season }}
</td>
<td>
{{ link.comment|urlize(target='_blank') }}
</td>
<td>
<a href="{{ url_for('search', q=link.title.keyword) }}" target="_blank">
<i class="fa fa-search"></i>
</a>
<i>&nbsp;</i>
<a href="EDIT_ID">
<i class="fa fa-pencil"></i>
</a>
<i>&nbsp;</i>
<a href="DELETE_ID" onclick="return confirm('Are you sure you want to delete this item ?')">
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
{% endfor %}
{% endfor %}
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -21,12 +21,9 @@
</td> </td>
{% endif %} {% endif %}
{% set instance = connector.get_instance(link.link, '') %} <td class="{{ link|colorify }}">
<td class="{{ instance.color }}"> {{ link.vf|flagify }}
{{ flags.FR.value if link.vf else flags.JP.value }} {{ link.link|urlize(30, target='_blank') }}
<a href="{{ link.link }}" target="_blank">
{{ link.link|shorten }}
</a>
</td> </td>
<td> <td>