paginate /marseys
parent
b0f3c26283
commit
b53b0e6ac7
|
@ -183,8 +183,6 @@ def approve_emoji(v, name):
|
||||||
|
|
||||||
|
|
||||||
cache.delete("emojis")
|
cache.delete("emojis")
|
||||||
if emoji.kind == "Marsey":
|
|
||||||
cache.delete("marseys")
|
|
||||||
|
|
||||||
purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp")
|
purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp")
|
||||||
|
|
||||||
|
@ -493,8 +491,6 @@ def update_emoji(v):
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
cache.delete("emojis")
|
cache.delete("emojis")
|
||||||
if existing.kind == "Marsey":
|
|
||||||
cache.delete("marseys")
|
|
||||||
|
|
||||||
return render_template("admin/update_assets.html", v=v, msg=f"'{name}' updated successfully!", name=name, tags=tags, kind=kind, type="Emoji")
|
return render_template("admin/update_assets.html", v=v, msg=f"'{name}' updated successfully!", name=name, tags=tags, kind=kind, type="Emoji")
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func, nullslast
|
||||||
from files.helpers.media import *
|
from files.helpers.media import *
|
||||||
|
|
||||||
import files.helpers.stats as statshelper
|
import files.helpers.stats as statshelper
|
||||||
|
@ -41,35 +41,39 @@ def reddit_post(subreddit, v, path):
|
||||||
return redirect(f'https://{reddit}/{post_id}')
|
return redirect(f'https://{reddit}/{post_id}')
|
||||||
|
|
||||||
|
|
||||||
@cache.cached(key_prefix="marseys")
|
|
||||||
def get_marseys(db:scoped_session):
|
|
||||||
if not FEATURES['MARSEYS']: return []
|
|
||||||
marseys = []
|
|
||||||
for marsey, author in db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id == None).order_by(Emoji.count.desc()):
|
|
||||||
marsey.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None
|
|
||||||
marseys.append(marsey)
|
|
||||||
return marseys
|
|
||||||
|
|
||||||
@app.get("/marseys")
|
@app.get("/marseys")
|
||||||
@limiter.limit(DEFAULT_RATELIMIT)
|
@limiter.limit(DEFAULT_RATELIMIT)
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
||||||
@auth_required
|
@auth_required
|
||||||
def marseys(v:User):
|
def marseys(v:User):
|
||||||
|
if SITE_NAME != 'rDrama' or not FEATURES['MARSEYS']:
|
||||||
if SITE_NAME != 'rDrama':
|
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
marseys = get_marseys(g.db)
|
marseys = g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id==None)
|
||||||
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True)
|
|
||||||
|
next_exists = marseys.count()
|
||||||
|
|
||||||
|
sort = request.values.get("sort")
|
||||||
|
if sort == "author":
|
||||||
|
marseys = marseys.order_by(User.username, Emoji.count.desc())
|
||||||
|
elif sort == "added_on":
|
||||||
|
marseys = marseys.order_by(nullslast(Emoji.created_utc.desc()), User.username)
|
||||||
|
else: # implied sort == "usage"
|
||||||
|
marseys = marseys.order_by(Emoji.count.desc(), User.username)
|
||||||
|
|
||||||
|
try: page = max(int(request.values.get("page", 1)), 1)
|
||||||
|
except: page = 1
|
||||||
|
|
||||||
|
marseys = marseys.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
|
||||||
|
|
||||||
original = os.listdir("/asset_submissions/emojis/original")
|
original = os.listdir("/asset_submissions/emojis/original")
|
||||||
for marsey in marseys:
|
for marsey, user in marseys:
|
||||||
marsey.user = authors.get(marsey.author_id)
|
|
||||||
for x in IMAGE_FORMATS:
|
for x in IMAGE_FORMATS:
|
||||||
if f'{marsey.name}.{x}' in original:
|
if f'{marsey.name}.{x}' in original:
|
||||||
marsey.og = f'{marsey.name}.{x}'
|
marsey.og = f'{marsey.name}.{x}'
|
||||||
break
|
break
|
||||||
return render_template("marseys.html", v=v, marseys=marseys)
|
|
||||||
|
|
||||||
|
return render_template("marseys.html", v=v, marseys=marseys, page=page, next_exists=next_exists, sort=sort)
|
||||||
|
|
||||||
|
|
||||||
@cache.cached(key_prefix="emojis")
|
@cache.cached(key_prefix="emojis")
|
||||||
|
|
|
@ -5,28 +5,25 @@
|
||||||
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
|
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
|
||||||
<thead class="bg-primary text-white">
|
<thead class="bg-primary text-white">
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Marsey</th>
|
<th>Marsey</th>
|
||||||
<th>Usage</th>
|
<th class="disable-sort-click"><a href="/marseys" {% if sort=="usage" %}disabled{% endif %}>Usage</a></th>
|
||||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||||
<th>Author</th>
|
<th class="disable-sort-click"><a href="?sort=author" {% if sort=="author" %}disabled{% endif %}>Author</a></th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th>Added on</th>
|
<th class="disable-sort-click"><a href="?sort=added_on" {% if sort=="added_on" %}disabled{% endif %}>Added on</a></th>
|
||||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||||
<th>Original File</th>
|
<th>Original File</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="marseys-table">
|
<tbody id="marseys-table">
|
||||||
{% for marsey in marseys %}
|
{% for marsey, user in marseys %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{loop.index}}</td>
|
|
||||||
<td>{{marsey.name}}</td>
|
<td>{{marsey.name}}</td>
|
||||||
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
|
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
|
||||||
<td>{{marsey.count}}</td>
|
<td>{{marsey.count}}</td>
|
||||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||||
{% set user = marsey.user %}
|
|
||||||
<td>{% include "user_in_table.html" %}</td>
|
<td>{% include "user_in_table.html" %}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td data-sort-key="{{marsey.created_utc or 0}}" {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td>
|
<td data-sort-key="{{marsey.created_utc or 0}}" {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td>
|
||||||
|
@ -43,3 +40,7 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block pagenav %}
|
||||||
|
{% include "pagination.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue