1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 14:19:59 +00:00

Don't use a keyword as a variable name!

This commit is contained in:
TheAMM 2017-05-13 08:20:14 +03:00
parent 5af55245ec
commit 43406fb831

View file

@ -54,7 +54,7 @@ def filter_truthy(input_list):
the search_results.html template ''' the search_results.html template '''
return [item for item in input_list if item] return [item for item in input_list if item]
def search(term='', user=None, sort='id', order='desc', category='0_0', filter='0', page=1, rss=False, admin=False): def search(term='', user=None, sort='id', order='desc', category='0_0', quality_filter='0', page=1, rss=False, admin=False):
sort_keys = { sort_keys = {
'id': models.Torrent.id, 'id': models.Torrent.id,
'size': models.Torrent.filesize, 'size': models.Torrent.filesize,
@ -85,10 +85,10 @@ def search(term='', user=None, sort='id', order='desc', category='0_0', filter='
'3': (models.TorrentFlags.COMPLETE, True) '3': (models.TorrentFlags.COMPLETE, True)
} }
filter_ = filter.lower() sentinel = object()
if filter_ not in filter_keys: filter_tuple = filter_keys.get(quality_filter.lower(), sentinel)
if filter_tuple is sentinel:
flask.abort(400) flask.abort(400)
filter = filter_keys[filter_]
if user: if user:
user = models.User.by_id(user) user = models.User.by_id(user)
@ -149,8 +149,8 @@ def search(term='', user=None, sort='id', order='desc', category='0_0', filter='
query = query.filter((models.Torrent.main_category_id == main_cat_id) & query = query.filter((models.Torrent.main_category_id == main_cat_id) &
(models.Torrent.sub_category_id == sub_cat_id)) (models.Torrent.sub_category_id == sub_cat_id))
if filter: if filter_tuple:
query = query.filter(models.Torrent.flags.op('&')(int(filter[0])).is_(filter[1])) query = query.filter(models.Torrent.flags.op('&')(int(filter_tuple[0])).is_(filter_tuple[1]))
# If admin, show everything # If admin, show everything
if not admin: if not admin:
@ -221,7 +221,7 @@ def home(rss):
sort = flask.request.args.get('s') sort = flask.request.args.get('s')
order = flask.request.args.get('o') order = flask.request.args.get('o')
category = flask.request.args.get('c') category = flask.request.args.get('c')
filter = flask.request.args.get('f') quality_filter = flask.request.args.get('f')
user_name = flask.request.args.get('u') user_name = flask.request.args.get('u')
page = flask.request.args.get('p') page = flask.request.args.get('p')
if page: if page:
@ -240,7 +240,7 @@ def home(rss):
'sort': sort or 'id', 'sort': sort or 'id',
'order': order or 'desc', 'order': order or 'desc',
'category': category or '0_0', 'category': category or '0_0',
'filter': filter or '0', 'quality_filter': quality_filter or '0',
'page': page or 1, 'page': page or 1,
'rss': rss 'rss': rss
} }
@ -254,7 +254,7 @@ def home(rss):
if rss: if rss:
return render_rss('/', query) return render_rss('/', query)
else: else:
rss_query_string = _generate_query_string(term, category, filter, user_name) rss_query_string = _generate_query_string(term, category, quality_filter, user_name)
return flask.render_template('home.html', return flask.render_template('home.html',
torrent_query=query, torrent_query=query,
search=query_args, search=query_args,
@ -272,7 +272,7 @@ def view_user(user_name):
sort = flask.request.args.get('s') sort = flask.request.args.get('s')
order = flask.request.args.get('o') order = flask.request.args.get('o')
category = flask.request.args.get('c') category = flask.request.args.get('c')
filter = flask.request.args.get('f') quality_filter = flask.request.args.get('f')
page = flask.request.args.get('p') page = flask.request.args.get('p')
if page: if page:
page = int(page) page = int(page)
@ -283,7 +283,7 @@ def view_user(user_name):
'sort': sort or 'id', 'sort': sort or 'id',
'order': order or 'desc', 'order': order or 'desc',
'category': category or '0_0', 'category': category or '0_0',
'filter': filter or '0', 'quality_filter': quality_filter or '0',
'page': page or 1, 'page': page or 1,
'rss': False 'rss': False
} }
@ -294,7 +294,7 @@ def view_user(user_name):
query = search(**query_args) query = search(**query_args)
rss_query_string = _generate_query_string(term, category, filter, user_name) rss_query_string = _generate_query_string(term, category, quality_filter, user_name)
return flask.render_template('user.html', return flask.render_template('user.html',
torrent_query=query, torrent_query=query,
search=query_args, search=query_args,