1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 08:10:03 +00:00

AutoPEP8 (after elasticsearch merge)

This commit is contained in:
Kfir Hadas 2017-05-16 12:47:06 +03:00
parent 9ac56ba3d7
commit 4e9409fb30
3 changed files with 20 additions and 11 deletions

View file

@ -162,7 +162,8 @@ def home(rss):
if not max_search_results:
max_search_results = DEFAULT_MAX_SEARCH_RESULT
max_page = min(query_args['page'], int(math.ceil(max_search_results / float(per_page)))) # Only allow up to (max_search_results / page) pages
# Only allow up to (max_search_results / page) pages
max_page = min(query_args['page'], int(math.ceil(max_search_results / float(per_page))))
query_args['page'] = max_page
query_args['max_search_results'] = max_search_results
@ -188,7 +189,7 @@ def home(rss):
# If ES is enabled, default to db search for browsing
if use_elastic:
query_args['term'] = ''
else: # Otherwise, use db search for everything
else: # Otherwise, use db search for everything
query_args['term'] = term or ''
query = search_db(**query_args)
@ -253,7 +254,8 @@ def view_user(user_name):
if not max_search_results:
max_search_results = DEFAULT_MAX_SEARCH_RESULT
max_page = min(query_args['page'], int(math.ceil(max_search_results / float(per_page)))) # Only allow up to (max_search_results / page) pages
# Only allow up to (max_search_results / page) pages
max_page = min(query_args['page'], int(math.ceil(max_search_results / float(per_page))))
query_args['page'] = max_page
query_args['max_search_results'] = max_search_results
@ -293,6 +295,7 @@ def view_user(user_name):
def _jinja2_filter_rfc822(date, fmt=None):
return formatdate(float(date.strftime('%s')))
@app.template_filter('rfc822_es')
def _jinja2_filter_rfc822(datestr, fmt=None):
return formatdate(float(datetime.strptime(datestr, '%Y-%m-%dT%H:%M:%S').strftime('%s')))
@ -629,4 +632,4 @@ def site_help():
@app.route('/api/upload', methods=['POST'])
def api_upload():
api_response = api_handler.api_upload(flask.request)
return api_response
return api_response

View file

@ -167,8 +167,8 @@ def search_elastic(term='', user=None, sort='id', order='desc',
s = s[0:per_page]
else:
max_page = min(page, int(math.ceil(max_search_results / float(per_page))))
from_idx = (max_page-1)*per_page
to_idx = min(max_search_results, max_page*per_page)
from_idx = (max_page - 1) * per_page
to_idx = min(max_search_results, max_page * per_page)
s = s[from_idx:to_idx]
highlight = app.config.get('ENABLE_ELASTIC_SEARCH_HIGHLIGHT')
@ -267,10 +267,12 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
if not admin:
# Hide all DELETED torrents if regular user
query = query.filter(models.Torrent.flags.op('&')(int(models.TorrentFlags.DELETED)).is_(False))
query = query.filter(models.Torrent.flags.op('&')(
int(models.TorrentFlags.DELETED)).is_(False))
# If logged in user is not the same as the user being viewed, show only torrents that aren't hidden or anonymous
# If logged in user is the same as the user being viewed, show all torrents including hidden and anonymous ones
# On RSS pages in user view, show only torrents that aren't hidden or anonymous no matter what
# On RSS pages in user view, show only torrents that aren't hidden or
# anonymous no matter what
if not same_user or rss:
query = query.filter(models.Torrent.flags.op('&')(int(models.TorrentFlags.HIDDEN |
models.TorrentFlags.ANONYMOUS)).is_(False))
@ -278,7 +280,8 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
else:
if not admin:
# Hide all DELETED torrents if regular user
query = query.filter(models.Torrent.flags.op('&')(int(models.TorrentFlags.DELETED)).is_(False))
query = query.filter(models.Torrent.flags.op('&')(
int(models.TorrentFlags.DELETED)).is_(False))
# If logged in, show all torrents that aren't hidden unless they belong to you
# On RSS pages, show all public torrents and nothing more.
if logged_in_user and not rss:
@ -286,7 +289,8 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
(models.Torrent.uploader_id == logged_in_user.id))
# Otherwise, show all torrents that aren't hidden
else:
query = query.filter(models.Torrent.flags.op('&')(int(models.TorrentFlags.HIDDEN)).is_(False))
query = query.filter(models.Torrent.flags.op('&')(
int(models.TorrentFlags.HIDDEN)).is_(False))
if main_category:
query = query.filter(models.Torrent.main_category_id == main_cat_id)
@ -295,7 +299,8 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
(models.Torrent.sub_category_id == sub_cat_id))
if filter_tuple:
query = query.filter(models.Torrent.flags.op('&')(int(filter_tuple[0])).is_(filter_tuple[1]))
query = query.filter(models.Torrent.flags.op('&')(
int(filter_tuple[0])).is_(filter_tuple[1]))
if term:
for item in shlex.split(term, posix=False):

View file

@ -54,6 +54,7 @@ def get_trackers(torrent):
return list(trackers)
def get_trackers_magnet():
trackers = OrderedSet()