mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 19:30:00 +00:00
Clean up user search suggestion
This commit is contained in:
parent
363203dfe0
commit
aeef80edaa
|
@ -10,6 +10,7 @@ from nyaa.search import search_elastic, search_db
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
import re
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
|
@ -181,14 +182,16 @@ def home(rss):
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
user_id = user.id
|
user_id = user.id
|
||||||
|
|
||||||
|
user_query = {
|
||||||
|
'first_word_user': None,
|
||||||
|
'query_sans_user': None
|
||||||
|
}
|
||||||
if search_term:
|
if search_term:
|
||||||
exploded_query = search_term.split(" ")
|
user_word_match = re.match(r'^([a-zA-Z0-9_-]+) *(.*|$)', search_term)
|
||||||
first_word_user = models.User.by_username(exploded_query[0].encode('ascii', 'ignore'))
|
if user_word_match:
|
||||||
exploded_query.pop(0)
|
first_word_username = user_word_match.group(1)
|
||||||
query_sans_user = ' '.join(exploded_query)
|
user_query['first_word_user'] = models.User.by_username(first_word_username)
|
||||||
else:
|
user_query['query_sans_user'] = user_word_match.group(2)
|
||||||
first_word_user = None
|
|
||||||
query_sans_user = None
|
|
||||||
|
|
||||||
query_args = {
|
query_args = {
|
||||||
'user': user_id,
|
'user': user_id,
|
||||||
|
@ -201,10 +204,6 @@ def home(rss):
|
||||||
'per_page': results_per_page
|
'per_page': results_per_page
|
||||||
}
|
}
|
||||||
|
|
||||||
user_query = {
|
|
||||||
'first_word_user': first_word_user,
|
|
||||||
'query_sans_user': query_sans_user
|
|
||||||
}
|
|
||||||
|
|
||||||
if flask.g.user:
|
if flask.g.user:
|
||||||
query_args['logged_in_user'] = flask.g.user
|
query_args['logged_in_user'] = flask.g.user
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% if user_query is defined %}
|
{% if user_query is defined %}
|
||||||
{% if user_query['first_word_user'] and not search['user'] %}
|
{% if user_query.first_word_user and not search.user %}
|
||||||
<div class="alert alert-info">
|
<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>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue