mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 09:00:00 +00:00
Add per-user filter on search page based on query.
This commit is contained in:
parent
63a469e08b
commit
f215f0803c
|
@ -181,6 +181,15 @@ def home(rss):
|
|||
flask.abort(404)
|
||||
user_id = user.id
|
||||
|
||||
if search_term:
|
||||
exploded_query = search_term.split(" ")
|
||||
first_word_user = models.User.by_username(exploded_query[0])
|
||||
exploded_query.pop(0)
|
||||
query_sans_user = ' '.join(exploded_query)
|
||||
else:
|
||||
first_word_user = None
|
||||
query_sans_user = None
|
||||
|
||||
query_args = {
|
||||
'user': user_id,
|
||||
'sort': sort_key or 'id',
|
||||
|
@ -192,6 +201,11 @@ def home(rss):
|
|||
'per_page': results_per_page
|
||||
}
|
||||
|
||||
user_query = {
|
||||
'first_word_user': first_word_user,
|
||||
'query_sans_user': query_sans_user
|
||||
}
|
||||
|
||||
if flask.g.user:
|
||||
query_args['logged_in_user'] = flask.g.user
|
||||
if flask.g.user.is_moderator: # God mode
|
||||
|
@ -229,7 +243,8 @@ def home(rss):
|
|||
pagination=pagination,
|
||||
torrent_query=query_results,
|
||||
search=query_args,
|
||||
rss_filter=rss_query_string)
|
||||
rss_filter=rss_query_string,
|
||||
user_query=user_query)
|
||||
else:
|
||||
# If ES is enabled, default to db search for browsing
|
||||
if use_elastic:
|
||||
|
@ -250,7 +265,8 @@ def home(rss):
|
|||
use_elastic=False,
|
||||
torrent_query=query,
|
||||
search=query_args,
|
||||
rss_filter=rss_query_string)
|
||||
rss_filter=rss_query_string,
|
||||
user_query=user_query)
|
||||
|
||||
|
||||
@app.route('/user/<user_name>', methods=['GET', 'POST'])
|
||||
|
|
|
@ -8,6 +8,15 @@
|
|||
{{ caller() }}
|
||||
</th>
|
||||
{% endmacro %}
|
||||
|
||||
{% if user_query is defined %}
|
||||
{% if user_query['first_word_user'] and not search['user'] %}
|
||||
<div class="alert alert-info">
|
||||
<a href="/user/{{ user_query['first_word_user'].username }}{{ modify_query(q=user_query['query_sans_user'])[1:] }}">Click here to see only results uploaded by {{ user_query['first_word_user'].username }}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if (use_elastic and torrent_query.hits.total > 0) or (torrent_query.items) %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover table-striped torrent-list">
|
||||
|
|
Loading…
Reference in a new issue