forked from rDrama/rDrama
add sentto seach query for messages + make before and after work for user search
parent
01f671d19a
commit
97911f261b
|
@ -19,6 +19,7 @@ valid_params = [
|
||||||
'before',
|
'before',
|
||||||
'after',
|
'after',
|
||||||
'title',
|
'title',
|
||||||
|
'sentto',
|
||||||
search_operator_hole,
|
search_operator_hole,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -345,6 +346,13 @@ def searchmessages(v:User):
|
||||||
except: abort(400)
|
except: abort(400)
|
||||||
comments = comments.filter(Comment.created_utc < before)
|
comments = comments.filter(Comment.created_utc < before)
|
||||||
|
|
||||||
|
if 'sentto' in criteria:
|
||||||
|
sentto = criteria['sentto']
|
||||||
|
try: sentto = get_user(sentto, graceful=True)
|
||||||
|
except:
|
||||||
|
abort(400, "The `sentto` field must contain a user's username!")
|
||||||
|
comments = comments.filter(Comment.sentto == sentto.id)
|
||||||
|
|
||||||
comments = sort_objects(sort, comments, Comment)
|
comments = sort_objects(sort, comments, Comment)
|
||||||
|
|
||||||
total = comments.count()
|
total = comments.count()
|
||||||
|
@ -366,31 +374,51 @@ def searchmessages(v:User):
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
||||||
@auth_required
|
@auth_required
|
||||||
def searchusers(v:User):
|
def searchusers(v:User):
|
||||||
|
|
||||||
query = request.values.get("q", '').strip()
|
query = request.values.get("q", '').strip()
|
||||||
|
if not query:
|
||||||
|
abort(403, "Empty searches aren't allowed!")
|
||||||
|
|
||||||
try: page = max(1, int(request.values.get("page", 1)))
|
try: page = max(1, int(request.values.get("page", 1)))
|
||||||
except: abort(400, "Invalid page input!")
|
except: abort(400, "Invalid page input!")
|
||||||
|
|
||||||
sort = request.values.get("sort", "new").lower()
|
users = g.db.query(User)
|
||||||
t = request.values.get('t', 'all').lower()
|
|
||||||
term=query.lstrip('@')
|
criteria = searchparse(query)
|
||||||
|
|
||||||
|
if 'after' in criteria:
|
||||||
|
after = criteria['after']
|
||||||
|
try: after = int(after)
|
||||||
|
except:
|
||||||
|
try: after = timegm(time.strptime(after, "%Y-%m-%d"))
|
||||||
|
except: abort(400)
|
||||||
|
users = users.filter(User.created_utc > after)
|
||||||
|
|
||||||
|
if 'before' in criteria:
|
||||||
|
before = criteria['before']
|
||||||
|
try: before = int(before)
|
||||||
|
except:
|
||||||
|
try: before = timegm(time.strptime(before, "%Y-%m-%d"))
|
||||||
|
except: abort(400)
|
||||||
|
users = users.filter(User.created_utc < before)
|
||||||
|
|
||||||
|
if 'q' in criteria:
|
||||||
|
term = criteria['q'][0]
|
||||||
|
term = term.lstrip('@')
|
||||||
term = term.replace('\\','').replace('_','\_').replace('%','')
|
term = term.replace('\\','').replace('_','\_').replace('%','')
|
||||||
|
|
||||||
users=g.db.query(User).filter(
|
users = users.filter(
|
||||||
or_(
|
or_(
|
||||||
User.username.ilike(f'%{term}%'),
|
User.username.ilike(f'%{term}%'),
|
||||||
User.original_username.ilike(f'%{term}%')
|
User.original_username.ilike(f'%{term}%')
|
||||||
)
|
)
|
||||||
)
|
).order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())
|
||||||
|
|
||||||
users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())
|
|
||||||
|
|
||||||
total = users.count()
|
total = users.count()
|
||||||
|
|
||||||
users = users.offset(PAGE_SIZE * (page-1)).limit(PAGE_SIZE+1).all()
|
users = users.offset(PAGE_SIZE * (page-1)).limit(PAGE_SIZE+1).all()
|
||||||
|
|
||||||
next_exists = (len(users)>PAGE_SIZE)
|
next_exists = (len(users)>PAGE_SIZE)
|
||||||
users = users[:PAGE_SIZE]
|
users = users[:PAGE_SIZE]
|
||||||
|
|
||||||
if v.client: return {"data": [x.json for x in users]}
|
if v.client: return {"data": [x.json for x in users]}
|
||||||
return render_template("search_users.html", v=v, query=query, total=total, page=page, users=users, sort=sort, t=t, next_exists=next_exists)
|
return render_template("search_users.html", v=v, query=query, total=total, page=page, users=users, next_exists=next_exists)
|
||||||
|
|
|
@ -28,29 +28,10 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body pb-2">
|
<div class="card-body pb-2">
|
||||||
<div class="pl-md-3">
|
<div>
|
||||||
{% if not request.path.startswith('/search/users') %}
|
|
||||||
<div id="searchparams-dropdown" class="dropdown dropdown-actions">
|
<div id="searchparams-dropdown" class="dropdown dropdown-actions">
|
||||||
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton2" data-bs-toggle="dropdown" data-bs-display="static"><strong>Advanced search parameters (with examples)</strong></button>
|
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton2" data-bs-toggle="dropdown" data-bs-display="static"><strong>Advanced search parameters (with examples)</strong></button>
|
||||||
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px);">
|
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px);">
|
||||||
<div>
|
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">Author:</div>
|
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">author:quadnarca</button>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">Domain:</div>
|
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">domain:reddit.com</button>
|
|
||||||
</div>
|
|
||||||
{% if FEATURES['NSFW_MARKING'] %}
|
|
||||||
<div>
|
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">NSFW:</div>
|
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">over18:true</button>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div>
|
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">{{HOLE_NAME | capitalize }}:</div>
|
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">{{HOLE_NAME}}:music</button>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">Before Date:</div>
|
<div style="display: inline-block; width: 150px; text-align: center;">Before Date:</div>
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">before:2022-12-30</button>
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">before:2022-12-30</button>
|
||||||
|
@ -59,23 +40,51 @@
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">After Date:</div>
|
<div style="display: inline-block; width: 150px; text-align: center;">After Date:</div>
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">after:2022-12-30</button>
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">after:2022-12-30</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if not request.path.startswith('/search/users') %}
|
||||||
|
<div>
|
||||||
|
<div style="display: inline-block; width: 150px; text-align: center;">Author:</div>
|
||||||
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">author:quadnarca</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if request.path.startswith('/search/messages') %}
|
||||||
|
<div>
|
||||||
|
<div style="display: inline-block; width: 150px; text-align: center;">Sent To:</div>
|
||||||
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">sentto:carpathianflorist</button>
|
||||||
|
</div>
|
||||||
|
{% elif request.path.startswith('/search/posts') or request.path.startswith('/search/comments') %}
|
||||||
|
<div>
|
||||||
|
<div style="display: inline-block; width: 150px; text-align: center;">{{HOLE_NAME | capitalize }}:</div>
|
||||||
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">{{HOLE_NAME}}:music</button>
|
||||||
|
</div>
|
||||||
|
{% if FEATURES['NSFW_MARKING'] %}
|
||||||
|
<div>
|
||||||
|
<div style="display: inline-block; width: 150px; text-align: center;">NSFW:</div>
|
||||||
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">over18:true</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if request.path.startswith('/search/comments') %}
|
{% if request.path.startswith('/search/comments') %}
|
||||||
<div>
|
<div>
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">Post ID:</div>
|
<div style="display: inline-block; width: 150px; text-align: center;">Post ID:</div>
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">post:504</button>
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">post:504</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% elif request.path.startswith('/search/posts') %}
|
||||||
{% if request.path.startswith('/search/posts') %}
|
<div>
|
||||||
|
<div style="display: inline-block; width: 150px; text-align: center;">Domain:</div>
|
||||||
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">domain:reddit.com</button>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div style="display: inline-block; width: 150px; text-align: center;">Post Title Only:</div>
|
<div style="display: inline-block; width: 150px; text-align: center;">Post Title Only:</div>
|
||||||
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">title:true</button>
|
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">title:true</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<script defer src="{{'js/search.js' | asset}}"></script>
|
<script defer src="{{'js/search.js' | asset}}"></script>
|
||||||
{% endif %}
|
|
||||||
<div class="text-muted text-small mb-1">Showing {% block listinglength %}{{listing | length}}{% endblock %} of {{total}} result{{'s' if total != 1 else ''}} for</div>
|
<div class="text-muted text-small mb-1">Showing {% block listinglength %}{{listing | length}}{% endblock %} of {{total}} result{{'s' if total != 1 else ''}} for</div>
|
||||||
<h4 class=" mb-0">{{query}}</h4>
|
<h4 class=" mb-0">{{query}}</h4>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue