/subs
This commit is contained in:
parent
fdeff3f8d1
commit
01c5b316c1
4 changed files with 45 additions and 6 deletions
|
@ -1,7 +1,9 @@
|
|||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship
|
||||
from files.__main__ import Base
|
||||
from files.helpers.lazy import lazy
|
||||
from os import environ
|
||||
from .sub_subscription import *
|
||||
|
||||
SITE_NAME = environ.get("SITE_NAME", '').strip()
|
||||
SITE = environ.get("DOMAIN", '').strip()
|
||||
|
@ -18,6 +20,8 @@ class Sub(Base):
|
|||
bannerurl = Column(String)
|
||||
css = Column(String)
|
||||
|
||||
subscriptions = relationship("SubSubscription", lazy="dynamic", primaryjoin="SubSubscription.sub==Sub.name", viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Sub(name={self.name})>"
|
||||
|
||||
|
@ -31,4 +35,10 @@ class Sub(Base):
|
|||
@lazy
|
||||
def banner_url(self):
|
||||
if self.bannerurl: return SITE_FULL + self.bannerurl
|
||||
return f'{SITE_FULL}/static/assets/images/{SITE_NAME}/banner.webp?v=1042'
|
||||
return f'{SITE_FULL}/static/assets/images/{SITE_NAME}/banner.webp?v=1042'
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def subscription_num(self):
|
||||
print(self.subscriptions.count(), flush=True)
|
||||
return self.subscriptions.count()
|
|
@ -513,5 +513,5 @@ def sub_toggle(mode, v):
|
|||
@app.get("/subs")
|
||||
@auth_desired
|
||||
def subs(v):
|
||||
subs = g.db.query(Submission.sub, func.count(Submission.sub)).group_by(Submission.sub).order_by(func.count(Submission.sub).desc()).all()[:-1]
|
||||
subs = g.db.query(Sub, func.count(Submission.sub)).outerjoin(Sub, Sub.name == Submission.sub).group_by(Sub.name).order_by(func.count(Sub.name).desc()).all()[:-1]
|
||||
return render_template('sub/subs.html', v=v, subs=subs)
|
|
@ -1,24 +1,29 @@
|
|||
{% extends "default.html" %}
|
||||
{% block content %}
|
||||
<script src="/static/assets/js/sort_table.js?v=240"></script>
|
||||
|
||||
<pre>
|
||||
|
||||
|
||||
</pre>
|
||||
<h5>List of subs with at least 1 post</h5>
|
||||
<pre></pre>
|
||||
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
||||
<thead class="bg-primary text-white">
|
||||
<div class="overflow-x-auto">
|
||||
<table id="sortable_table" class="table table-striped mb-5">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Name</th>
|
||||
<th>Posts</th>
|
||||
<th role="button" onclick="sort_table(2)" >Posts</th>
|
||||
<th role="button" onclick="sort_table(3)" >Subscribers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for sub, count in subs %}
|
||||
<tr>
|
||||
<td>{{loop.index}}</td>
|
||||
<td><a href="/s/{{sub}}" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>{{sub}}</a></td>
|
||||
<td><a href="/s/{{sub.name}}" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>{{sub.name}}</a></td>
|
||||
<td>{{count}}</a>
|
||||
<td>{{sub.subscription_num}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
24
files/templates/sub/subscribers.html
Normal file
24
files/templates/sub/subscribers.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% extends "default.html" %}
|
||||
{% block content %}
|
||||
<pre>
|
||||
|
||||
|
||||
</pre>
|
||||
<h5>Users subscribed to /s/{{sub.name}}</h5>
|
||||
<pre></pre>
|
||||
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{loop.index}}</td>
|
||||
<td><a style="color:#{{user.namecolor}}" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue