parent
4923bfb680
commit
bfde0d7ff3
|
@ -183,6 +183,8 @@ def approve_emoji(v, name):
|
|||
|
||||
|
||||
cache.delete("emojis")
|
||||
if emoji.kind == "Marsey":
|
||||
cache.delete("marseys")
|
||||
|
||||
purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp")
|
||||
|
||||
|
@ -491,6 +493,8 @@ def update_emoji(v):
|
|||
g.db.add(ma)
|
||||
|
||||
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")
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import os
|
|||
from shutil import copyfile
|
||||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.sql.expression import nullslast
|
||||
from files.helpers.media import *
|
||||
|
||||
import files.helpers.stats as statshelper
|
||||
|
@ -42,44 +41,36 @@ def reddit_post(subreddit, v, path):
|
|||
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/all")
|
||||
@limiter.limit(DEFAULT_RATELIMIT)
|
||||
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
||||
@auth_required
|
||||
def marseys(v:User):
|
||||
if SITE_NAME != 'rDrama' or not FEATURES['MARSEYS']:
|
||||
|
||||
if SITE_NAME != 'rDrama':
|
||||
abort(404)
|
||||
|
||||
marseys = g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id==None)
|
||||
|
||||
total = marseys.count()
|
||||
|
||||
sort = request.values.get("sort", "usage")
|
||||
if sort == "author":
|
||||
marseys = marseys.order_by(User.username, Emoji.count.desc())
|
||||
elif sort == "name":
|
||||
marseys = marseys.order_by(Emoji.name, Emoji.count.desc())
|
||||
elif sort == "added_on":
|
||||
marseys = marseys.order_by(nullslast(Emoji.created_utc.desc()), Emoji.count.desc())
|
||||
elif sort == "usage":
|
||||
marseys = marseys.order_by(Emoji.count.desc(), User.username)
|
||||
|
||||
page = get_page()
|
||||
|
||||
if request.path != "/marseys/all":
|
||||
marseys = marseys.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE)
|
||||
|
||||
marseys = marseys.all()
|
||||
|
||||
marseys = get_marseys(g.db)
|
||||
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True)
|
||||
original = os.listdir("/asset_submissions/emojis/original")
|
||||
for marsey, user in marseys:
|
||||
for marsey in marseys:
|
||||
marsey.user = authors.get(marsey.author_id)
|
||||
for x in IMAGE_FORMATS:
|
||||
if f'{marsey.name}.{x}' in original:
|
||||
marsey.og = f'{marsey.name}.{x}'
|
||||
break
|
||||
return render_template("marseys.html", v=v, marseys=marseys)
|
||||
|
||||
return render_template("marseys.html", v=v, marseys=marseys, page=page, total=total, sort=sort)
|
||||
|
||||
|
||||
@cache.cached(key_prefix="emojis")
|
||||
|
|
|
@ -5,25 +5,28 @@
|
|||
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th class="disable-sort-click" {% if sort=="name" %}disabled{% endif %}><a href="?sort=name">Name</a></th>
|
||||
<th class="disable-sort-click">Marsey</th>
|
||||
<th class="disable-sort-click" {% if sort=="usage" %}disabled{% endif %}><a href="/marseys">Usage</a></th>
|
||||
<th>#</th>
|
||||
<th>Name</th>
|
||||
<th>Marsey</th>
|
||||
<th>Usage</th>
|
||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||
<th class="disable-sort-click" {% if sort=="author" %}disabled{% endif %}><a href="?sort=author">Author</a></th>
|
||||
<th>Author</th>
|
||||
{% endif %}
|
||||
<th class="disable-sort-click" {% if sort=="added_on" %}disabled{% endif %}><a href="?sort=added_on">Added on</a></th>
|
||||
<th>Added on</th>
|
||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||
<th class="disable-sort-click">Original File</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="marseys-table">
|
||||
{% for marsey, user in marseys %}
|
||||
{% for marsey in marseys %}
|
||||
<tr>
|
||||
<td>{{loop.index}}</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>{{marsey.count}}</td>
|
||||
{% if FEATURES['ASSET_SUBMISSIONS'] %}
|
||||
{% set user = marsey.user %}
|
||||
<td>{% include "user_in_table.html" %}</td>
|
||||
{% endif %}
|
||||
<td data-sort-key="{{marsey.created_utc or 0}}" {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td>
|
||||
|
@ -40,9 +43,3 @@
|
|||
</table>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block pagenav %}
|
||||
{% if request.path != "/marseys/all" %}
|
||||
{% include "pagination.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue