Revert "fix hat ordering"

This reverts commit c196041f64.
pull/146/head
Aevann 2023-05-05 09:35:43 +03:00
parent c196041f64
commit 58a84e11fe
3 changed files with 7 additions and 8 deletions

View File

@ -8,8 +8,6 @@ from files.classes import Base
from files.helpers.lazy import lazy
from files.helpers.regex import censor_slurs
from flask import g
class HatDef(Base):
__tablename__ = "hat_defs"
@ -31,10 +29,9 @@ class HatDef(Base):
def __repr__(self):
return f"<{self.__class__.__name__}(id={self.id})>"
@property
@lazy
def number_sold(self):
return g.db.query(Hat).filter_by(hat_id=self.id).count()
def number_sold(self, db:scoped_session):
return db.query(Hat).filter_by(hat_id=self.id).count()
@lazy
def censored_description(self, v):

View File

@ -37,10 +37,12 @@ def hats(v:User):
hats = hats.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
elif sort == "owners":
hat_count = [x[0] for x in g.db.query(Hat.hat_id).group_by(Hat.hat_id).order_by(func.count(Hat.hat_id).desc()).all()]
if SITE == 'rdrama.net':
hats = sorted(hats.all(), key=lambda x: x[0].number_sold, reverse=True)
hats = sorted(hats.all(), key=lambda x: hat_count.index(x[0].id) if x[0].id in hat_count else 0)
else:
hats = sorted(hats.all(), key=lambda x: x.number_sold, reverse=True)
hats = sorted(hats.all(), key=lambda x: hat_count.index(x.id) if x.id in hat_count else 0)
firstrange = PAGE_SIZE * (page - 1)
secondrange = firstrange + PAGE_SIZE

View File

@ -76,7 +76,7 @@
{% if SITE == 'rdrama.net' %}
<td>{% include "user_in_table.html" %}</td>
{% endif %}
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold}}</a></td>
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold(g.db)}}</a></td>
<td>{{hat.price}}</td>
<td class="shop-table-actions" style="width:unset">
{% if hat.id not in owned_hat_ids and hat.is_purchasable %}