Page list finished
This commit is contained in:
parent
a4a9e23607
commit
374e24efc0
35
app.py
35
app.py
@ -1,18 +1,15 @@
|
||||
from operator import itemgetter
|
||||
from os import environ
|
||||
|
||||
from flask import redirect, render_template, url_for, request
|
||||
|
||||
from config import app, auth
|
||||
from config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, IS_DEBUG, APP_PORT, db
|
||||
from connectors import *
|
||||
from models import SearchForm, AnimeTitle
|
||||
|
||||
|
||||
@auth.verify_password
|
||||
def verify_password(username, password):
|
||||
admin_username = environ.get('ADMIN_USERNAME', 'admin')
|
||||
admin_password = environ.get('ADMIN_USERNAME', 'secret')
|
||||
return username is admin_username and password is admin_password
|
||||
return username is ADMIN_USERNAME and password is ADMIN_PASSWORD
|
||||
|
||||
|
||||
@app.template_filter('boldify')
|
||||
@ -26,8 +23,8 @@ def boldify(name):
|
||||
|
||||
|
||||
@app.template_filter('shorten')
|
||||
def shorten(str):
|
||||
return str[:30] + '...' if len(str) > 30 else str
|
||||
def shorten(str_to_replace):
|
||||
return str_to_replace[:30] + '...' if len(str_to_replace) > 30 else str_to_replace
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@ -76,11 +73,23 @@ def latest():
|
||||
|
||||
@app.route('/list')
|
||||
def list_animes():
|
||||
filters = request.args.get('s', 'nyaa,yggtorrent').split(',')
|
||||
titles = AnimeTitle.query.order_by(AnimeTitle.name).all()
|
||||
filters = None
|
||||
for i, to_filter in enumerate(request.args.get('s', 'nyaa,yggtorrent').split(',')):
|
||||
if not i:
|
||||
filters = AnimeLink.link.contains(to_filter)
|
||||
else:
|
||||
filters = filters | AnimeLink.link.contains(to_filter)
|
||||
|
||||
return render_template('list.html', form=SearchForm(), titles=titles, filters=filters, connector=Connector,
|
||||
flags=ConnectorLang)
|
||||
titles = db.session.query(AnimeTitle, AnimeLink).join(AnimeLink).filter(filters).order_by(AnimeTitle.name).all()
|
||||
|
||||
results = {}
|
||||
for title, link in titles:
|
||||
if title.id not in results:
|
||||
results[title.id] = [link]
|
||||
else:
|
||||
results[title.id].append(link)
|
||||
|
||||
return render_template('list.html', form=SearchForm(), titles=results, connector=Connector, flags=ConnectorLang)
|
||||
|
||||
|
||||
@app.route('/admin')
|
||||
@ -90,6 +99,4 @@ def admin():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app_debug = environ.get('FLASK_ENV', 'production') == 'development'
|
||||
app_port = environ.get('FLASK_PORT', 5000)
|
||||
app.run('0.0.0.0', app_port, app_debug)
|
||||
app.run('0.0.0.0', APP_PORT, IS_DEBUG)
|
||||
|
@ -17,9 +17,16 @@ if not db_host or not db_user or not db_password or not db_name:
|
||||
print('Missing connection environment variables')
|
||||
exit()
|
||||
|
||||
# load app constants
|
||||
IS_DEBUG = environ.get('FLASK_ENV', 'production') == 'development'
|
||||
ADMIN_USERNAME = environ.get('ADMIN_USERNAME', 'admin')
|
||||
ADMIN_PASSWORD = environ.get('ADMIN_PASSWORD', 'secret')
|
||||
APP_PORT = environ.get('FLASK_PORT', 5000)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = urandom(24).hex()
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name)
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
app.secret_key = urandom(24).hex()
|
||||
app.config['SQLALCHEMY_ECHO'] = IS_DEBUG
|
||||
auth = HTTPBasicAuth()
|
||||
db = SQLAlchemy(app)
|
||||
|
@ -12,12 +12,12 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for title in titles %}
|
||||
{% for link in title.links %}
|
||||
{% for title in titles.values() %}
|
||||
{% for link in title %}
|
||||
<tr>
|
||||
{% if not loop.index0 %}
|
||||
<td rowspan="{{ title.links|length }}">
|
||||
{{ title.name }}
|
||||
<td rowspan="{{ title|length }}">
|
||||
{{ link.title.name }}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
</td>
|
||||
|
||||
{% if not loop.index0 %}
|
||||
<td rowspan="{{ title.links|length }}">
|
||||
<a href="{{ url_for('search', q=title.keyword) }}" target="_blank">
|
||||
<td rowspan="{{ title|length }}">
|
||||
<a href="{{ url_for('search', q=link.title.keyword) }}" target="_blank">
|
||||
<i class="fa fa-search"></i>
|
||||
</a>
|
||||
</td>
|
||||
|
Reference in New Issue
Block a user