From 514fa47718e113ad3bfdd09fd043f9b7f6419402 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 27 Jul 2021 02:05:58 +0200 Subject: [PATCH] dffd --- drama/classes/comment.py | 90 +------------ drama/classes/mix_ins.py | 6 +- drama/classes/mod_logs.py | 2 +- drama/classes/submission.py | 78 +---------- drama/classes/user.py | 147 ++------------------- drama/helpers/markdown.py | 2 +- drama/routes/admin.py | 8 +- drama/routes/posts.py | 2 +- drama/routes/settings.py | 25 ++-- drama/routes/users.py | 4 +- drama/templates/comments.html | 4 +- drama/templates/header.html | 6 +- drama/templates/mobile_navigation_bar.html | 4 +- drama/templates/modlog.html | 2 +- drama/templates/settings_profile.html | 8 +- drama/templates/submission.html | 11 +- drama/templates/submission_banned.html | 2 +- drama/templates/submission_listing.html | 11 +- drama/templates/submit.html | 6 +- 19 files changed, 69 insertions(+), 349 deletions(-) diff --git a/drama/classes/comment.py b/drama/classes/comment.py index 9821a07de..8ccdf65d5 100644 --- a/drama/classes/comment.py +++ b/drama/classes/comment.py @@ -101,14 +101,11 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): @lazy def parent(self): - if not self.parent_submission: - return None + if not self.parent_submission: return None - if self.level == 1: - return self.post + if self.level == 1: return self.post - else: - return g.db.query(Comment).get(self.parent_comment_id) + else: return g.db.query(Comment).get(self.parent_comment_id) @property def replies(self): @@ -136,47 +133,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): if self.post: return f"{self.post.permalink}/{self.id}/" else: return f"/comment/{self.id}/" - def rendered_comment(self, v=None, render_replies=True, - standalone=False, level=1, **kwargs): - - kwargs["post_base36id"] = kwargs.get( - "post_base36id", self.post.base36id if self.post else None) - - if self.is_banned or self.deleted_utc > 0: - if v and v.admin_level > 1: - return render_template("single_comment.html", - v=v, - c=self, - render_replies=render_replies, - standalone=standalone, - level=level, - **kwargs) - - elif self.any_descendants_live: - return render_template("single_comment_removed.html", - c=self, - render_replies=render_replies, - standalone=standalone, - level=level, - **kwargs) - else: - return "" - - return render_template("single_comment.html", - v=v, - c=self, - render_replies=render_replies, - standalone=standalone, - level=level, - **kwargs) - - @property - def active_flags(self): - if self.is_approved: - return 0 - else: - return self.flag_count - @property def json_raw(self): data= { @@ -186,7 +142,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): 'author_name': self.author.username, 'body': self.body, 'body_html': self.body_html, - 'is_archived': self.is_archived, 'is_bot': self.is_bot, 'created_utc': self.created_utc, 'edited_utc': self.edited_utc or 0, @@ -318,10 +273,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): self.comment_aux.ban_reason = x g.db.add(self.comment_aux) - @property - def flag_count(self): - return len(self.flags) - #@property #def award_count(self): #return len(self.awards) @@ -341,41 +292,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing): return False - @property - def flagged_by(self): - return [x.user for x in self.flags] - - @property - def self_download_json(self): - - #This property should never be served to anyone but author and admin - if not self.is_banned and not self.is_banned: - return self.json_core - - data= { - "author": self.author.name, - "body": self.body, - "body_html": self.body_html, - "is_banned": bool(self.is_banned), - "deleted_utc": self.deleted_utc, - 'created_utc': self.created_utc, - 'id': self.base36id, - 'fullname': self.fullname, - 'permalink': self.permalink, - 'post_id': self.post.base36id, - 'level': self.level - } - if self.level>=2: - data['parent_comment_id']= base36encode(self.parent_comment_id) - - return data - - @property - def json_admin(self): - data= self.json_raw - - return data - @property @lazy def is_op(self): diff --git a/drama/classes/mix_ins.py b/drama/classes/mix_ins.py index 0e792f972..a4c7d0642 100644 --- a/drama/classes/mix_ins.py +++ b/drama/classes/mix_ins.py @@ -151,8 +151,7 @@ class Fuzzing: @property def upvotes_fuzzed(self): - if self.upvotes <= 10 or self.is_archived: - return self.upvotes + if self.upvotes <= 10: return self.upvotes lower = int(self.upvotes * 0.99) upper = int(self.upvotes * 1.01) + 1 @@ -161,8 +160,7 @@ class Fuzzing: @property def downvotes_fuzzed(self): - if self.downvotes <= 10 or self.is_archived: - return self.downvotes + if self.downvotes <= 10: return self.downvotes lower = int(self.downvotes * 0.99) upper = int(self.downvotes * 1.01) + 1 diff --git a/drama/classes/mod_logs.py b/drama/classes/mod_logs.py index 3050f7657..02c821d77 100644 --- a/drama/classes/mod_logs.py +++ b/drama/classes/mod_logs.py @@ -68,7 +68,7 @@ class ModAction(Base, Stndrd, Age_times): @property def target_link(self): if self.target_user: - return f'{self.target_user.username}' + return f'{self.target_user.username}' elif self.target_post: return f'{self.target_post.title}' elif self.target_comment: diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 6ffcc537f..cdc94590e 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -116,13 +116,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): def score_disputed(self): return (self.upvotes+1) * (self.downvotes+1) - @property - def is_repost(self): - return bool(self.repost_id) - - @property - def is_archived(self): - return false @property @lazy @@ -147,15 +140,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): return f"/post/{self.id}/{output}" - @property - def is_archived(self): - - now = int(time.time()) - - cutoff = now - (60 * 60 * 24 * 180) - - return self.created_utc < cutoff - def rendered_page(self, sort=None, comment=None, comment_info=None, v=None): # check for banned @@ -220,13 +204,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, []) - @property - def active_flags(self): - if self.is_approved: - return 0 - else: - return len(self.flags) - @property #@lazy def thumb_url(self): @@ -250,7 +227,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): 'is_bot': self.is_bot, 'thumb_url': self.thumb_url, 'domain': self.domain, - 'is_archived': self.is_archived, 'url': self.url, 'body': self.body, 'body_html': self.body_html, @@ -315,10 +291,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): def voted(self): return self._voted if "_voted" in self.__dict__ else 0 - @property - def user_title(self): - return self._title if "_title" in self.__dict__ else self.author.title - @property def title(self): return self.submission_aux.title @@ -428,14 +400,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): def is_blocking(self): return self.__dict__.get('_is_blocking', False) - @property - def flag_count(self): - return len(self.flags) - - @property - def report_count(self): - return len(self.reports) - #@property #def award_count(self): #return len(self.awards) @@ -444,52 +408,12 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): def embed_template(self): return f"site_embeds/{self.domain_obj.embed_template}.html" - @property - def flagged_by(self): - return [x.user for x in self.flags] - @property def is_image(self): if self.url: return self.url.endswith('jpg') or self.url.endswith('png') or self.url.endswith('.gif') or self.url.endswith('jpeg') or self.url.endswith('?maxwidth=9999') or self.url.endswith('?maxwidth=8888') else: return False - - @property - def self_download_json(self): - - #This property should never be served to anyone but author and admin - if not self.is_banned and self.deleted_utc == 0: - return self.json_core - - data= { - "title":self.title, - "author": self.author.username, - "url": self.url, - "body": self.body, - "body_html": self.body_html, - "is_banned": bool(self.is_banned), - "deleted_utc": self.deleted_utc, - 'created_utc': self.created_utc, - 'id': self.base36id, - 'fullname': self.fullname, - 'comment_count': self.comment_count, - 'permalink': self.permalink - } - - return data - - @property - def json_admin(self): - - data=self.json_raw - - return data - - @property - def is_exiled_for(self): - return self.__dict__.get('_is_exiled_for', None) - - + class SaveRelationship(Base, Stndrd): __tablename__="save_relationship" diff --git a/drama/classes/user.py b/drama/classes/user.py index b9b16fa27..b5ca9dee2 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -67,10 +67,6 @@ class User(Base, Stndrd, Age_times): "Notification", lazy="dynamic") - # unread_notifications_relationship=relationship( - # "Notification", - # primaryjoin="and_(Notification.user_id==User.id, Notification.read==False)") - referred_by = Column(Integer) is_banned = Column(Integer, default=None) unban_utc = Column(Integer, default=None) @@ -126,11 +122,6 @@ class User(Base, Stndrd, Age_times): return g.db.query(UserBlock).filter_by( user_id=self.id, target_id=target.id).first() - def is_blocked_by(self, user): - - return g.db.query(UserBlock).filter_by( - user_id=user.id, target_id=self.id).first() - def any_block_exists(self, other): return g.db.query(UserBlock).filter( @@ -243,22 +234,12 @@ class User(Base, Stndrd, Age_times): @property def banned_by(self): - if not self.is_banned: - return None - + if not self.is_banned: return None return g.db.query(User).filter_by(id=self.is_banned).first() def has_badge(self, badgedef_id): return self.badges.filter_by(badge_id=badgedef_id).first() - def vote_status_on_post(self, post): - - return post.voted - - def vote_status_on_comment(self, comment): - - return comment.voted - def hash_password(self, password): return generate_password_hash( password, method='pbkdf2:sha512', salt_length=8) @@ -284,18 +265,6 @@ class User(Base, Stndrd, Age_times): def url(self): return f"/@{self.username}" - @property - def permalink(self): - return self.url - - @property - def uid_permalink(self): - return f"/uid/{self.base36id}" - - @property - def original_link(self): - return f"/@{self.original_username}" - def __repr__(self): return f"" @@ -399,22 +368,6 @@ class User(Base, Stndrd, Age_times): return output - def alts_subquery(self): - return g.db.query(User.id).filter( - or_( - User.id.in_( - g.db.query(Alt.user1).filter( - Alt.user2 == self.id - ).subquery() - ), - User.id.in_( - g.db.query(Alt.user2).filter( - Alt.user1 == self.id - ).subquery() - ).subquery() - ) - ).subquery() - def alts_threaded(self, db): subq = db.query(Alt).filter( @@ -451,44 +404,11 @@ class User(Base, Stndrd, Age_times): return g.db.query(Follow).filter_by( target_id=self.id, user_id=user.id).first() - def set_profile(self, file): - - self.del_profile() - imageurl = upload_file(name=f"profile.gif", file=file, resize=(100, 100)) - if imageurl: - self.profileurl = imageurl - self.profile_upload_ip = request.remote_addr - self.profile_set_utc = int(time.time()) - self.profile_upload_region = request.headers.get("cf-ipcountry") - g.db.add(self) - - def set_banner(self, file): - - self.del_banner() - imageurl = upload_file(name=f"banner.gif", file=file) - if imageurl: - self.bannerurl = imageurl - self.banner_upload_ip = request.remote_addr - self.banner_set_utc = int(time.time()) - self.banner_upload_region = request.headers.get("cf-ipcountry") - g.db.add(self) - - def del_profile(self): - - self.profileurl = None - g.db.add(self) - - def del_banner(self): - - self.bannerurl = None - g.db.add(self) @property def banner_url(self): - if self.bannerurl: - return self.bannerurl - else: - return "/assets/images/default_bg.png" + if self.bannerurl: return self.bannerurl + else: return "/assets/images/default_bg.png" @cache.memoize(0) def defaultpicture(self): @@ -497,27 +417,13 @@ class User(Base, Stndrd, Age_times): @property def profile_url(self): - if self.profileurl: - return self.profileurl - else: - return self.defaultpicture() - - @property - def can_submit_image(self): - return self.dramacoins >= 0 - - @property - def can_upload_avatar(self): - return self.dramacoins >= 0 - - @property - def can_upload_banner(self): - return self.dramacoins >= 0 + if self.profileurl: return self.profileurl + else: return self.defaultpicture() @property def json_raw(self): data = {'username': self.username, - 'permalink': self.permalink, + 'url': self.url, 'is_banned': bool(self.is_banned), 'is_premium': self.has_premium_no_renew, 'created_utc': self.created_utc, @@ -538,7 +444,7 @@ class User(Base, Stndrd, Age_times): now = int(time.time()) if self.is_banned and (not self.unban_utc or now < self.unban_utc): return {'username': self.username, - 'permalink': self.permalink, + 'url': self.url, 'is_banned': True, 'is_permanent_ban': not bool(self.unban_utc), 'ban_reason': self.ban_reason, @@ -557,10 +463,6 @@ class User(Base, Stndrd, Age_times): return data - @property - def can_use_darkmode(self): - return True - def ban(self, admin=None, reason=None, days=0): if days > 0: @@ -568,26 +470,17 @@ class User(Base, Stndrd, Age_times): self.unban_utc = ban_time else: - if self.bannerurl: - self.del_banner() - if self.profileurl: - self.del_profile() - + self.bannerurl = None + self.profileurl = None delete_role(self, "linked") self.is_banned = admin.id if admin else 2317 - if reason: - self.ban_reason = reason + if reason: self.ban_reason = reason - try: - g.db.add(self) - except: - pass + g.db.add(self) def unban(self): - # Takes care of all functions needed for account reinstatement. - self.is_banned = 0 self.unban_utc = 0 @@ -694,24 +587,6 @@ class User(Base, Stndrd, Age_times): l = [i for i in l if i] return l - @property - def json_admin(self): - data = self.json_raw - - data['email'] = self.email - data['email_verified'] = self.is_activated - - return data - - @property - def can_upload_comment_image(self): - return self.dramacoins >= 0 and request.headers.get("cf-ipcountry") != "T1" - - @property - def can_change_name(self): - return True -# return self.name_changed_utc < int(time.time())-60*60*24*90 - class ViewerRelationship(Base): diff --git a/drama/helpers/markdown.py b/drama/helpers/markdown.py index 179546773..94014029f 100644 --- a/drama/helpers/markdown.py +++ b/drama/helpers/markdown.py @@ -96,7 +96,7 @@ class CustomRenderer(HTMLRenderer): if not user: return f"{space}@{target}" - return f'{space}@{user.username}' + return f'{space}@{user.username}' def render_sub_mention(self, token): space = token.target[0] diff --git a/drama/routes/admin.py b/drama/routes/admin.py index 484904c02..c1af7c697 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -172,7 +172,7 @@ def badge_grant_post(v): if user.has_badge(badge_id): g.db.query(Badge).filter_by(badge_id=badge_id, user_id=user.id,).delete() g.db.commit() - return redirect(user.permalink) + return redirect(user.url) new_badge = Badge(badge_id=badge_id, user_id=user.id, @@ -204,7 +204,7 @@ def badge_grant_post(v): elif badge_id in [24,28]: user.banawards = 3 g.db.add(user) - return redirect(user.permalink) + return redirect(user.url) @app.route("/admin/users", methods=["GET"]) @@ -969,7 +969,7 @@ def admin_nuke_user(v): ) g.db.add(ma) - return redirect(user.permalink) + return redirect(user.url) @app.route("/admin/unnuke_user", methods=["POST"]) @admin_level_required(4) @@ -999,7 +999,7 @@ def admin_nunuke_user(v): ) g.db.add(ma) - return redirect(user.permalink) + return redirect(user.url) @app.route("/api/user_stat_data", methods=['GET']) @admin_level_required(2) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index db2045e2e..cfbb1d982 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -867,7 +867,7 @@ def submit_post(v): # check for embeddable video domain = parsed_url.netloc - if request.files.get('file') and not v.can_submit_image: + if request.files.get('file') and not v.dramacoins >= 0: abort(403) diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 04495b729..699643d0b 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -324,36 +324,45 @@ def settings_log_out_others(v): @auth_required @validate_formkey def settings_images_profile(v): - if v.can_upload_avatar: + if v.dramacoins >= 0: if request.content_length > 16 * 1024 * 1024: g.db.rollback() abort(413) - v.set_profile(request.files["profile"]) + v.profileurl = None + imageurl = upload_file(name=f"profile.gif", file=request.files["profile"], resize=(100, 100)) + if imageurl: + v.profileurl = imageurl + g.db.add(v) + return render_template("settings_profile.html", v=v, msg="Profile picture successfully updated.") return render_template("settings_profile.html", v=v, - msg="Avatars require 300 reputation.") + msg="Avatars require +0 dramacoins.") @app.route("/settings/images/banner", methods=["POST"]) @auth_required @validate_formkey def settings_images_banner(v): - if v.can_upload_banner: + if v.dramacoins >= 0: if request.content_length > 16 * 1024 * 1024: g.db.rollback() abort(413) - v.set_banner(request.files["banner"]) + v.bannerurl = None + imageurl = upload_file(name=f"banner.gif", file=request.files["banner"]) + if imageurl: + v.bannerurl = imageurl + g.db.add(v) return render_template("settings_profile.html", v=v, msg="Banner successfully updated.") return render_template("settings_profile.html", v=v, - msg="Banners require 500 reputation.") + msg="Banners require +0 dramacoins.") @app.route("/settings/delete/profile", methods=["POST"]) @@ -361,8 +370,8 @@ def settings_images_banner(v): @validate_formkey def settings_delete_profile(v): - v.del_profile() - + v.profileurl = None + g.db.add(v) return render_template("settings_profile.html", v=v, msg="Profile picture successfully removed.") diff --git a/drama/routes/users.py b/drama/routes/users.py index dedfd30d0..820b0cdc9 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -25,7 +25,7 @@ def suicide(v, username): t = int(time.time()) if v.admin_level == 0 and t - v.suicide_utc < 86400: return "", 204 user = get_user(username) - suicide = f"Hi there,\n\nA [concerned dramatard]({v.permalink}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators at r/SuicideWatch keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow dramatards care about you and there are people who want to help." + suicide = f"Hi there,\n\nA [concerned dramatard]({v.url}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators at r/SuicideWatch keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow dramatards care about you and there are people who want to help." send_notification(1046, user, suicide) v.suicide_utc = t g.db.add(v) @@ -183,7 +183,7 @@ def api_is_available(name, v): def user_id(id): user = get_account(int(id)) - return redirect(user.permalink) + return redirect(user.url) # Allow Id of user to be queryied, and then redirect the bot to the # actual user api endpoint. diff --git a/drama/templates/comments.html b/drama/templates/comments.html index 1cf5d9e7d..08bd1f855 100644 --- a/drama/templates/comments.html +++ b/drama/templates/comments.html @@ -114,7 +114,7 @@ {% endif %} - {% if c.active_flags %} + {% if c.flags %}
Reported by:
    diff --git a/drama/templates/header.html b/drama/templates/header.html index 51b7c78f0..d07cc5634 100644 --- a/drama/templates/header.html +++ b/drama/templates/header.html @@ -79,7 +79,7 @@ {% if v %}