From 575a5080bd21a742da2fcf5ca78480e73da1dd29 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 27 Nov 2022 02:20:54 +0200 Subject: [PATCH] unpaywall profile views --- files/classes/user.py | 12 ------- files/helpers/const.py | 1 - files/routes/users.py | 21 ++++++++----- files/templates/errors/patron.html | 21 ------------- files/templates/userpage.html | 12 ++++--- files/templates/userpage/viewers.html | 24 -------------- files/templates/userpage/views.html | 45 +++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 70 deletions(-) delete mode 100644 files/templates/errors/patron.html delete mode 100644 files/templates/userpage/viewers.html create mode 100644 files/templates/userpage/views.html diff --git a/files/classes/user.py b/files/classes/user.py index 4d2289e68..468de4f69 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -141,7 +141,6 @@ class User(Base): subscriptions = relationship("Subscription", back_populates="user") following = relationship("Follow", primaryjoin="Follow.user_id==User.id", back_populates="user") followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", back_populates="target") - viewers = relationship("ViewerRelationship", primaryjoin="User.id == ViewerRelationship.user_id") blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id", back_populates="user") blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id", back_populates="target") authorizations = relationship("ClientAuth", back_populates="user") @@ -945,17 +944,6 @@ class User(Base): def can_create_hole(self): return self.admin_level >= PERMS['HOLE_CREATE'] - @property - @lazy - def viewers_recorded(self): - if SITE_NAME == 'WPD': # WPD gets profile views - return True - elif self.admin_level >= PERMS['VIEW_PROFILE_VIEWS']: # Admins get profile views - return True - elif self.patron: # Patrons get profile views as a perk - return True - return False - @property @lazy def patron_tooltip(self): diff --git a/files/helpers/const.py b/files/helpers/const.py index 05262a206..a3cb980d7 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -254,7 +254,6 @@ PERMS = { # Minimum admin_level to perform action. 'VIEW_CHUDRAMA': 1, 'VIEW_PRIVATE_PROFILES': 2, 'VIEW_ALTS': 2, - 'VIEW_PROFILE_VIEWS': 2, 'VIEW_ACTIVE_USERS': 2, 'VIEW_ALL_USERS': 2, 'VIEW_ALT_VOTES': 2, diff --git a/files/routes/users.py b/files/routes/users.py index c5eb28ec0..095d3f294 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -654,13 +654,20 @@ def following(username, v): .order_by(Follow.created_utc).all() return render_template("userpage/following.html", v=v, u=u, users=users) -@app.get("/views") +@app.get("/@/views") @auth_required -def visitors(v:User): - if not v.viewers_recorded: - return render_template("errors/patron.html", v=v) - viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True) - return render_template("userpage/viewers.html", v=v, viewers=viewers) +def visitors(username, v:User): + u = get_user(username, v=v, include_shadowbanned=False) + + try: page = int(request.values.get("page", 1)) + except: page = 1 + + views = g.db.query(ViewerRelationship).filter_by(user_id=u.id).order_by(ViewerRelationship.last_view_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).limit(PAGE_SIZE + 1).all() + + next_exists = (len(views) > PAGE_SIZE) + views = views[:PAGE_SIZE] + + return render_template("userpage/views.html", v=v, u=u, views=views, next_exists=next_exists, page=page) @cache.memoize(timeout=86400) def userpagelisting(user:User, site=None, v=None, page:int=1, sort="new", t="all"): @@ -682,7 +689,7 @@ def u_username(username, v=None): return redirect(SITE_FULL + request.full_path.replace(username, u.username)) is_following = v and u.has_follower(v) - if v and v.id not in (u.id, DAD_ID) and u.viewers_recorded: + if v and v.id != u.id: g.db.flush() view = g.db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none() diff --git a/files/templates/errors/patron.html b/files/templates/errors/patron.html deleted file mode 100644 index c6655a3f8..000000000 --- a/files/templates/errors/patron.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "default.html" %} -{% block pagetitle %}401 Not Authorized{% endblock %} -{% block pagetype %}error-401{% endblock %} -{% block content %} -
-
-
- :#marseymerchant: -
401 Not Authorized
-

This page is only available to {% if SITE_NAME == 'rDrama' %}paypigs{% else %}patrons{% endif %}:

- {% if FEATURES['MARSEYBUX'] and v.truescore -%} - {% if KOFI_LINK %} - {{KOFI_LINK}} - {% else %} - {{GUMROAD_LINK}} - {% endif %} - {%- endif %} -
-
-
-{% endblock %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 42ef0f00f..5c7299ddf 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -70,7 +70,9 @@ {% endif %} {% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%} - + {%- endif %}
@@ -188,7 +190,6 @@
{% if v and v.id == u.id %} Edit profile - Profile views {% endif %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} @@ -196,7 +197,7 @@ {% endif %}
-
+

User ID: {{u.id}}

Coins spent: {{u.coins_spent}}

True score: {{u.truescore}}

@@ -302,7 +303,9 @@ {% endif %} {% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%} - + {%- endif %}
@@ -385,7 +388,6 @@
{% if v and v.id == u.id %} Edit profile - Profile views {% endif %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} diff --git a/files/templates/userpage/viewers.html b/files/templates/userpage/viewers.html deleted file mode 100644 index 51d2cd242..000000000 --- a/files/templates/userpage/viewers.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "default.html" %} -{% block pagetitle %}Profile Viewers{% endblock %} -{% block content %} -
Users who viewed your profile
-
- - - - - - -{% for view in viewers %} - - - - -{% endfor %} -
NameLast visit
- {% with user=view.viewer %} - {% include "user_in_table.html" %} - {% endwith %} - {{view.last_view_string}}
- -{% endblock %} diff --git a/files/templates/userpage/views.html b/files/templates/userpage/views.html new file mode 100644 index 000000000..5b4aeeed5 --- /dev/null +++ b/files/templates/userpage/views.html @@ -0,0 +1,45 @@ +{% extends "default.html" %} +{% block pagetitle %}Profile Views{% endblock %} +{% block content %} +
Users who viewed @{{u.username}}'s profile
+
+ + + + + + +{% for view in views %} + + + + +{% endfor %} +
NameLast visit
+ {% with user=view.viewer %} + {% include "user_in_table.html" %} + {% endwith %} + {{view.last_view_string}}
+ +{% endblock %} + +{% block pagenav %} + +{% endblock %}