diff --git a/files/classes/sub.py b/files/classes/sub.py index c3c1eb121..b3cf256e9 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -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"" @@ -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' \ No newline at end of file + 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() \ No newline at end of file diff --git a/files/routes/subs.py b/files/routes/subs.py index 201b42adb..0b3751bf0 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -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) \ No newline at end of file diff --git a/files/templates/sub/subs.html b/files/templates/sub/subs.html index 66e65aaa1..0d317544c 100644 --- a/files/templates/sub/subs.html +++ b/files/templates/sub/subs.html @@ -1,24 +1,29 @@ {% extends "default.html" %} {% block content %} + +
 
 	
 
List of subs with at least 1 post

-
- +
+
+ - + + {% for sub, count in subs %} - + {% endfor %}
# NamePostsPostsSubscribers
{{loop.index}}{{sub}}{{sub.name}} {{count}} + {{sub.subscription_num}}
diff --git a/files/templates/sub/subscribers.html b/files/templates/sub/subscribers.html new file mode 100644 index 000000000..1b93b32b8 --- /dev/null +++ b/files/templates/sub/subscribers.html @@ -0,0 +1,24 @@ +{% extends "default.html" %} +{% block content %} +
+
+	
+
+
Users subscribed to /s/{{sub.name}}
+

+
+ + + + + + +{% for user in users %} + + + + +{% endfor %} +
#Name
{{loop.index}}{{user.username}}
+ +{% endblock %} \ No newline at end of file