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