show owners of hats

master
Aevann1 2022-09-03 21:36:50 +02:00
parent b295af02f4
commit 865723470b
4 changed files with 30 additions and 6 deletions

View File

@ -29,4 +29,6 @@ class Hat(Base):
__tablename__ = "hats"
user_id = Column(Integer, ForeignKey('users.id'), primary_key=True)
hat_id = Column(Integer, ForeignKey('hat_defs.id'), primary_key=True)
hat_id = Column(Integer, ForeignKey('hat_defs.id'), primary_key=True)
owners = relationship("User", back_populates="owned_hats")

View File

@ -154,7 +154,7 @@ class User(Base):
referrals = relationship("User")
equipped_hat = relationship("HatDef", primaryjoin="User.equipped_hat_id==HatDef.id")
designed_hats = relationship("HatDef", primaryjoin="User.id==HatDef.author_id", back_populates="author")
owned_hats = relationship("Hat")
owned_hats = relationship("Hat", back_populates="owners")
def __init__(self, **kwargs):

View File

@ -95,4 +95,26 @@ def unequip_hat(v):
v.equipped_hat_id = None
g.db.add(v)
return {"message": "Hat unequipped!"}
return {"message": "Hat unequipped!"}
@app.get("/hat_owners/<hat_id>")
@auth_required
def hat_owners(v, hat_id):
try: hat_id = int(hat_id)
except: abort(400)
try: page = int(request.values.get("page", 1))
except: page = 1
users = [x[1] for x in g.db.query(Hat, User).join(Hat.owners).filter(Hat.hat_id == hat_id).offset(25 * (page - 1)).limit(26).all()]
next_exists = (len(users) > 25)
users = users[:25]
return render_template("admin/new_users.html",
v=v,
users=users,
next_exists=next_exists,
page=page,
)

View File

@ -27,10 +27,10 @@
<th scope="col">Description</th>
{% if SITE == 'rdrama.net' %}
<th scope="col">Author</th>
<th scope="col" onclick="sort_table(4)">Number Sold</th>
<th scope="col" onclick="sort_table(4)">Owners</th>
<th scope="col" onclick="sort_table(5)">Price</th>
{% else %}
<th scope="col" onclick="sort_table(3)">Number Sold</th>
<th scope="col" onclick="sort_table(3)">Owners</th>
<th scope="col" onclick="sort_table(4)">Price</th>
{% endif %}
<th scope="col">Actions</th>
@ -46,7 +46,7 @@
{% if SITE == 'rdrama.net' %}
<td><a style="color:#{{user.name_color}}" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.name_color}}"{% endif %}>{{user.username}}</span></a></td>
{% endif %}
<td>{{hat.number_sold}}</td>
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold}}</a></td>
<td>{{hat.price}}</td>
<td class="shop-table-actions">
{% if hat.id not in owned_hat_ids %}