From 097a4404beee7e8df8a91fe8092e7383c0da8504 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 29 Jul 2021 02:11:37 +0200 Subject: [PATCH] fdfd --- drama/classes/user.py | 3 +-- drama/routes/users.py | 21 ++++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/drama/classes/user.py b/drama/classes/user.py index 5364fd4d2..6b3f1e6c4 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -422,8 +422,7 @@ class User(Base, Stndrd, Age_times): def has_follower(self, user): - return g.db.query(Follow).filter_by( - target_id=self.id, user_id=user.id).first() + return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).first() @property diff --git a/drama/routes/users.py b/drama/routes/users.py index 0bc79784f..6a0535c17 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -431,18 +431,15 @@ def follow_user(username, v): target = get_user(username) - if target.id==v.id: - return jsonify({"error": "You can't follow yourself!"}), 400 + if target.id==v.id: return jsonify({"error": "You can't follow yourself!"}), 400 # check for existing follow - if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): - abort(409) - - new_follow = Follow(user_id=v.id, - target_id=target.id) + if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): abort(409) + new_follow = Follow(user_id=v.id, target_id=target.id) g.db.add(new_follow) - target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id) + + target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count() g.db.add(target) existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first() @@ -457,14 +454,12 @@ def unfollow_user(username, v): target = get_user(username) # check for existing follow - follow = g.db.query(Follow).filter_by( - user_id=v.id, target_id=target.id).first() + follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first() - if not follow: - abort(409) + if not follow: abort(409) g.db.delete(follow) - target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id) + target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count() g.db.add(target) existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()