rDrama/files/classes/post.py

431 lines
12 KiB
Python
Raw Normal View History

2021-10-18 20:46:57 +00:00
import random
import time
from urllib.parse import urlparse
2023-01-02 04:23:44 +00:00
from flask import g
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from sqlalchemy import Column, FetchedValue, ForeignKey
from sqlalchemy.orm import deferred, relationship
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from sqlalchemy.sql.sqltypes import *
from files.classes import Base
from files.helpers.config.const import *
2023-09-29 00:26:19 +00:00
from files.helpers.config.awards import *
from files.helpers.slurs_and_profanities import *
2021-10-18 20:46:57 +00:00
from files.helpers.lazy import lazy
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.regex import *
from files.helpers.sorting_and_time import make_age_string
2024-02-12 07:14:19 +00:00
from files.helpers.bleach_body import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from .comment import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from .polls import *
2023-10-07 17:55:50 +00:00
from .hole import *
from .subscriptions import *
from .saves import SaveRelationship
2022-06-22 19:57:57 +00:00
2023-06-07 23:26:32 +00:00
class Post(Base):
__tablename__ = "posts"
2021-07-21 01:12:26 +00:00
2022-02-12 22:23:41 +00:00
id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey("users.id"))
edited_utc = Column(Integer, default=0)
created_utc = Column(Integer)
2021-10-06 22:38:15 +00:00
thumburl = Column(String)
2023-03-11 06:29:52 +00:00
posterurl = Column(String)
2021-07-21 01:12:26 +00:00
is_banned = Column(Boolean, default=False)
2022-06-25 00:11:00 +00:00
bannedfor = Column(String)
2022-11-05 02:12:17 +00:00
chuddedfor = Column(String)
2022-02-15 22:54:17 +00:00
ghost = Column(Boolean, default=False)
2024-02-06 22:04:43 +00:00
effortpost = Column(Boolean, default=False)
2021-07-21 01:12:26 +00:00
views = Column(Integer, default=0)
deleted_utc = Column(Integer, default=0)
distinguished = Column(Boolean, default=False)
2024-02-18 15:29:53 +00:00
pinned = Column(String)
pinned_utc = Column(Integer)
profile_pinned = Column(Boolean, default=False)
2022-07-01 23:11:48 +00:00
hole_pinned = Column(String)
2023-10-07 17:55:50 +00:00
hole = Column(String, ForeignKey("holes.name"))
2024-02-18 15:29:53 +00:00
draft = Column(Boolean, default=False)
comment_count = Column(Integer, default=0)
2022-02-13 02:45:09 +00:00
is_approved = Column(Integer, ForeignKey("users.id"))
2021-07-21 01:12:26 +00:00
is_bot = Column(Boolean, default=False)
upvotes = Column(Integer, default=1)
downvotes = Column(Integer, default=0)
2021-11-30 14:18:16 +00:00
realupvotes = Column(Integer, default=1)
2023-08-23 21:57:39 +00:00
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
2021-10-06 22:38:15 +00:00
title = Column(String)
title_html = Column(String)
url = Column(String)
2024-04-03 20:32:36 +00:00
body = Column(String, default='')
2021-11-06 17:30:39 +00:00
body_html = Column(String)
2021-12-05 20:22:57 +00:00
flair = Column(String)
2021-10-06 22:38:15 +00:00
ban_reason = Column(String)
2023-02-18 16:33:19 +00:00
embed = Column(String)
2022-02-27 22:49:34 +00:00
new = Column(Boolean)
2022-09-10 07:00:45 +00:00
notify = Column(Boolean)
2023-06-23 13:14:23 +00:00
chudded = Column(Boolean, default=False)
rainbowed = Column(Boolean, default=False)
queened = Column(Boolean, default=False)
sharpened = Column(Boolean, default=False)
ping_cost = Column(Integer, default=0)
2023-07-25 22:37:54 +00:00
bump_utc = Column(Integer)
2021-07-21 01:12:26 +00:00
2024-02-12 18:35:15 +00:00
if FEATURES['NSFW_MARKING']:
nsfw = Column(Boolean, default=False)
else:
nsfw = False
2024-02-19 19:43:33 +00:00
if SITE_NAME == 'WPD' and not IS_LOCALHOST:
2024-02-12 18:56:36 +00:00
cw = Column(Boolean, default=False)
2023-06-07 23:26:32 +00:00
author = relationship("User", primaryjoin="Post.author_id==User.id")
oauth_app = relationship("OauthApp")
2023-06-07 23:26:32 +00:00
approved_by = relationship("User", uselist=False, primaryjoin="Post.is_approved==User.id")
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="post")
2023-06-23 16:49:23 +00:00
reports = relationship("Report", order_by="Report.created_utc")
comments = relationship("Comment", primaryjoin="Comment.parent_post==Post.id", back_populates="post")
2023-10-07 17:55:50 +00:00
hole_obj = relationship("Hole", primaryjoin="foreign(Post.hole)==remote(Hole.name)")
2023-06-07 23:26:32 +00:00
options = relationship("PostOption", order_by="PostOption.id")
2024-03-07 22:52:55 +00:00
edits = relationship("PostEdit", order_by="PostEdit.id.desc()")
2021-07-21 01:12:26 +00:00
def __init__(self, *args, **kwargs):
2023-07-25 22:37:54 +00:00
if "created_utc" not in kwargs:
kwargs["created_utc"] = int(time.time())
2023-07-27 14:54:12 +00:00
kwargs["bump_utc"] = kwargs["created_utc"]
super().__init__(*args, **kwargs)
2021-07-21 01:12:26 +00:00
def __repr__(self):
return f"<{self.__class__.__name__}(id={self.id})>"
2021-08-06 12:22:29 +00:00
2022-01-06 20:30:08 +00:00
@property
2021-12-27 02:09:06 +00:00
@lazy
def controversial(self):
if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True
return False
2021-09-19 18:22:57 +00:00
2021-10-05 23:11:17 +00:00
@property
@lazy
def created_datetime(self):
2022-11-29 20:29:27 +00:00
return time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))
2021-10-05 23:11:17 +00:00
2021-09-19 18:22:57 +00:00
@property
@lazy
def age_string(self):
return make_age_string(self.created_utc)
2021-09-19 18:22:57 +00:00
@property
@lazy
def edited_string(self):
return make_age_string(self.edited_utc)
2021-09-19 18:22:57 +00:00
2022-02-05 17:51:42 +00:00
@property
@lazy
def score(self):
return self.upvotes - self.downvotes
2021-09-23 19:22:18 +00:00
2021-07-21 01:12:26 +00:00
@property
@lazy
def fullname(self):
return f"p_{self.id}"
2022-02-16 04:33:13 +00:00
2023-03-24 12:29:19 +00:00
@property
@lazy
def id_last_num(self):
return str(self.id)[-1]
2022-02-16 04:33:13 +00:00
@property
@lazy
2022-02-24 13:20:48 +00:00
def shortlink(self):
2022-02-17 07:12:38 +00:00
link = f"/post/{self.id}"
2023-10-07 17:55:50 +00:00
if self.hole: link = f"/h/{self.hole}{link}"
2022-02-16 04:33:13 +00:00
2023-10-07 17:55:50 +00:00
if self.hole and self.hole in {'chudrama', 'countryclub', 'highrollerclub'}:
2023-01-01 05:33:09 +00:00
output = '-'
else:
2023-03-12 10:19:10 +00:00
title = self.plaintitle(None).lower()
output = title_regex.sub('', title)
output = output.split()[:6]
output = '-'.join(output)
2023-01-01 05:33:09 +00:00
if not output: output = '-'
2021-07-21 01:12:26 +00:00
2022-02-04 18:35:39 +00:00
return f"{link}/{output}"
2022-02-04 03:06:49 +00:00
@property
@lazy
def permalink(self):
return SITE_FULL + self.shortlink
2021-07-21 01:12:26 +00:00
2024-02-19 19:43:33 +00:00
@property
@lazy
2024-02-20 00:00:21 +00:00
def textlink(self):
2024-03-02 17:02:05 +00:00
return f'<a href="{self.shortlink}">{self.title}</a>'
2024-02-19 19:43:33 +00:00
2021-07-21 01:12:26 +00:00
@property
@lazy
def domain(self):
2022-08-23 18:05:11 +00:00
if not self.url: return ''
2022-01-19 09:21:20 +00:00
if self.url.startswith('/'): return SITE
2022-02-25 18:16:11 +00:00
domain = urlparse(self.url).netloc
2021-07-27 21:58:35 +00:00
if domain.startswith("www."): domain = domain.split("www.")[1]
2021-07-21 01:12:26 +00:00
return domain.replace("old.reddit.com", "reddit.com")
2022-01-21 20:56:56 +00:00
@property
@lazy
def author_name(self):
2023-10-26 23:21:55 +00:00
if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻'
return self.author.switched.user_name
2022-01-21 20:56:56 +00:00
@property
@lazy
def author_name_punish_modal(self):
if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻'
return self.author.username
2021-12-28 14:52:57 +00:00
@property
@lazy
def is_youtube(self):
2023-02-18 16:33:19 +00:00
return self.domain == "youtube.com" and self.embed and self.embed.startswith('<lite-youtube')
2021-07-21 01:12:26 +00:00
@property
2021-08-01 04:27:10 +00:00
@lazy
2021-07-21 01:12:26 +00:00
def thumb_url(self):
2023-10-05 10:19:50 +00:00
if self.nsfw:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/nsfw.webp?x=8"
2023-03-19 16:28:19 +00:00
elif not self.url:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/{SITE_NAME}/default_text.webp?x=8"
2023-03-08 06:49:18 +00:00
elif self.thumburl:
if self.thumburl.startswith('/'): return SITE_FULL + self.thumburl
return self.thumburl
2023-03-19 16:28:19 +00:00
elif self.is_youtube or self.is_video:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/default_thumb_video.webp?x=8"
2023-03-19 16:28:19 +00:00
elif self.is_audio:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/default_thumb_audio.webp?x=8"
elif self.domain == SITE:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/{SITE_NAME}/site_preview.webp?x=8"
2023-03-19 16:28:19 +00:00
else:
2024-03-05 18:40:55 +00:00
return f"{SITE_FULL_IMAGES}/i/default_thumb_link.webp?x=8"
2021-07-21 01:12:26 +00:00
2023-03-11 06:29:52 +00:00
@property
@lazy
def poster_url(self):
if self.posterurl: return self.posterurl
if self.thumburl: return self.thumburl
return None
@property
2021-09-19 20:06:52 +00:00
@lazy
def json(self):
if self.is_banned:
return {'is_banned': True,
'deleted_utc': self.deleted_utc,
'ban_reason': self.ban_reason,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
2023-01-01 11:36:20 +00:00
if self.deleted_utc:
return {'is_banned': bool(self.is_banned),
'deleted_utc': True,
'id': self.id,
'title': self.title,
'permalink': self.permalink,
}
2023-06-23 16:49:23 +00:00
reports = {}
for r in self.reports:
reports[r.user.username] = r.reason
2021-07-28 03:55:47 +00:00
data = {
'author_id': '👻' if self.ghost else self.author_id,
'author_name': self.author_name,
2021-07-21 01:12:26 +00:00
'permalink': self.permalink,
2022-04-06 21:01:32 +00:00
'shortlink': self.shortlink,
2021-07-21 01:12:26 +00:00
'is_banned': bool(self.is_banned),
2021-07-25 21:59:20 +00:00
'deleted_utc': self.deleted_utc,
2021-07-21 01:12:26 +00:00
'created_utc': self.created_utc,
2021-07-29 05:31:57 +00:00
'id': self.id,
2021-07-21 01:12:26 +00:00
'title': self.title,
2023-10-05 10:19:50 +00:00
'is_nsfw': self.nsfw,
2021-07-21 01:12:26 +00:00
'is_bot': self.is_bot,
2022-01-28 21:42:09 +00:00
'thumb_url': self.thumb_url,
2021-07-21 01:12:26 +00:00
'domain': self.domain,
2023-10-07 17:55:50 +00:00
'hole': self.hole,
2022-01-28 21:42:09 +00:00
'url': self.realurl(None),
2021-07-21 01:12:26 +00:00
'body': self.body,
'body_html': self.body_html,
'edited_utc': self.edited_utc or 0,
'comment_count': self.comment_count,
2021-09-18 19:45:17 +00:00
'score': self.score,
'upvotes': self.upvotes,
'downvotes': self.downvotes,
2024-02-18 15:29:53 +00:00
'pinned': self.pinned,
'draft' : self.draft,
'distinguished': self.distinguished,
2021-08-08 22:24:22 +00:00
'voted': self.voted if hasattr(self, 'voted') else 0,
2023-06-23 16:49:23 +00:00
'reports': reports,
2021-07-21 01:12:26 +00:00
}
2021-07-28 03:55:47 +00:00
2021-07-21 01:12:26 +00:00
if "replies" in self.__dict__:
data["replies"] = [x.json for x in self.replies]
2021-07-21 01:12:26 +00:00
return data
2022-06-23 16:36:39 +00:00
@lazy
2022-06-27 02:14:53 +00:00
def award_count(self, kind, v):
2023-10-12 13:28:13 +00:00
if v and v.poor:
return 0
2023-03-04 17:59:34 +00:00
if self.distinguished and SITE_NAME == 'WPD':
2023-08-12 16:56:33 +00:00
return 0
2023-03-04 17:59:34 +00:00
num = len([x for x in self.awards if x.kind == kind])
2023-10-11 16:11:33 +00:00
2024-01-11 01:55:59 +00:00
if kind in {"shit", "fireflies", "tilt"}:
2023-10-11 16:11:33 +00:00
return num
2023-10-14 20:05:13 +00:00
if kind == "stalker":
return min(num, 25)
2023-10-11 16:11:33 +00:00
if kind in {"emoji", "emoji-hz"}:
return min(num, 20)
2023-10-14 20:05:13 +00:00
if kind in {"gingerbread", "pumpkin"}:
return min(num, 10)
2023-10-11 16:11:33 +00:00
return min(num, 4)
2021-07-27 23:16:41 +00:00
2021-09-19 20:06:52 +00:00
@lazy
2021-07-21 01:12:26 +00:00
def realurl(self, v):
url = self.url
if not url: return ''
url = normalize_urls_runtime(url, v)
2023-03-06 00:02:40 +00:00
if url.startswith('/'): return SITE_FULL + url
return url
2023-01-01 11:36:20 +00:00
2022-08-26 21:53:17 +00:00
@lazy
def total_bet_voted(self, v):
if "closed" in self.body.lower(): return True
if v:
for o in self.options:
2022-09-08 18:25:45 +00:00
if o.exclusive == 3: return True
2022-08-26 21:53:17 +00:00
if o.exclusive == 2 and o.voted(v): return True
return False
2022-11-11 19:02:57 +00:00
@lazy
def total_poll_voted(self, v):
if v:
if v.id == self.author_id:
return True
2022-11-11 19:02:57 +00:00
for o in self.options:
if o.voted(v): return True
return False
2022-06-23 16:36:39 +00:00
@lazy
def realbody(self, v):
2022-10-07 02:04:27 +00:00
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
2022-10-13 14:26:35 +00:00
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
2021-08-21 11:06:28 +00:00
2022-01-23 16:54:57 +00:00
body = self.body_html or ""
2022-01-06 01:25:04 +00:00
2023-03-12 17:36:35 +00:00
body = add_options(self, body, v)
2023-10-07 17:55:50 +00:00
if self.hole != 'chudrama':
body = censor_slurs_profanities(body, v)
2023-03-24 16:38:18 +00:00
body = normalize_urls_runtime(body, v)
2024-02-24 23:06:31 +00:00
if self.created_utc > 1706137534:
body = bleach_body_html(body, runtime=True) #to stop slur filters and poll options being used as a vector for html/js injection
2024-02-12 07:14:19 +00:00
2021-07-21 01:12:26 +00:00
return body
2022-06-23 16:36:39 +00:00
@lazy
2021-10-02 20:58:14 +00:00
def plainbody(self, v):
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
2022-10-13 14:26:35 +00:00
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
2021-10-02 20:58:14 +00:00
2022-01-06 01:25:04 +00:00
body = self.body
2022-01-06 01:24:03 +00:00
if not body: return ""
2023-10-07 17:55:50 +00:00
if self.hole != 'chudrama':
body = censor_slurs_profanities(body, v, True)
body = normalize_urls_runtime(body, v)
2021-10-02 20:58:14 +00:00
return body
2021-09-19 20:06:52 +00:00
@lazy
2021-07-21 01:12:26 +00:00
def realtitle(self, v):
title = self.title_html
2023-05-05 21:45:25 +00:00
2023-10-07 17:55:50 +00:00
if self.hole != 'chudrama':
title = censor_slurs_profanities(title, v)
2021-08-21 11:06:28 +00:00
2021-07-21 01:12:26 +00:00
return title
2021-10-02 20:58:14 +00:00
@lazy
def plaintitle(self, v):
title = self.title
2021-10-02 20:58:14 +00:00
2023-10-07 17:55:50 +00:00
if self.hole != 'chudrama':
title = censor_slurs_profanities(title, v, True)
2021-10-02 20:58:14 +00:00
return title
2021-12-18 03:13:46 +00:00
@property
@lazy
def is_video(self):
2023-05-15 09:27:24 +00:00
return self.url and any((str(self.url).lower().split('?')[0].endswith(f'.{x}') for x in VIDEO_FORMATS)) and is_safe_url(self.url)
2021-12-18 03:13:46 +00:00
2022-05-24 16:28:12 +00:00
@property
@lazy
def is_audio(self):
2023-05-15 09:27:24 +00:00
return self.url and any((str(self.url).lower().split('?')[0].endswith(f'.{x}') for x in AUDIO_FORMATS)) and is_safe_url(self.url)
2022-05-24 16:28:12 +00:00
2021-07-21 01:12:26 +00:00
@property
2021-09-19 18:25:40 +00:00
@lazy
2021-07-21 01:12:26 +00:00
def is_image(self):
2023-05-15 09:27:24 +00:00
return self.url and any((str(self.url).lower().split('?')[0].endswith(f'.{x}') for x in IMAGE_FORMATS)) and is_safe_url(self.url)
2021-07-31 13:41:00 +00:00
2021-07-27 00:16:30 +00:00
@lazy
2023-06-23 16:49:23 +00:00
def filtered_reports(self, v):
return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)]
2022-07-11 18:13:00 +00:00
@lazy
2023-06-23 16:49:23 +00:00
def active_reports(self, v):
return len(self.filtered_reports(v))
@property
@lazy
def num_subscribers(self):
2023-06-07 23:26:32 +00:00
return g.db.query(Subscription).filter_by(post_id=self.id).count()
@property
@lazy
def num_savers(self):
2023-06-07 23:26:32 +00:00
return g.db.query(SaveRelationship).filter_by(post_id=self.id).count()
2023-10-02 08:05:30 +00:00
@lazy
2023-10-03 06:19:46 +00:00
def award_classes(self, v, title=False):
2023-10-02 08:05:30 +00:00
return get_award_classes(self, v, title)
@lazy
2023-12-25 01:18:48 +00:00
def emoji_awards_emojis(self, v, kind, NSFW_EMOJIS):
return get_emoji_awards_emojis(self, v, kind, NSFW_EMOJIS)
@property
@lazy
2024-02-06 19:39:52 +00:00
def is_longpost(self):
2024-03-15 20:07:11 +00:00
return self.body and len(self.body) >= 2000
2024-02-14 12:49:29 +00:00
@lazy
def hole_changable(self, v):
if self.hole == 'chudrama':
return v.admin_level >= PERMS['POST_COMMENT_MODERATION']
else:
2024-02-16 12:36:45 +00:00
return v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v.mods_hole(self.hole)) or self.author_id == v.id