First admin page works
This commit is contained in:
parent
820014e8d8
commit
39fc5faea6
25
app.py
25
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__':
|
||||
|
@ -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):
|
||||
|
70
templates/admin/list.html
Normal file
70
templates/admin/list.html
Normal 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> </i>
|
||||
<a href="EDIT_ID">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</a>
|
||||
<i> </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 %}
|
@ -21,12 +21,9 @@
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
{% set instance = connector.get_instance(link.link, '') %}
|
||||
<td class="{{ instance.color }}">
|
||||
{{ flags.FR.value if link.vf else flags.JP.value }}
|
||||
<a href="{{ link.link }}" target="_blank">
|
||||
{{ link.link|shorten }}
|
||||
</a>
|
||||
<td class="{{ link|colorify }}">
|
||||
{{ link.vf|flagify }}
|
||||
{{ link.link|urlize(30, target='_blank') }}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
Reference in New Issue
Block a user