2022-12-12 01:03:22 +00:00
|
|
|
import random
|
2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
2022-12-11 23:44:34 +00:00
|
|
|
from sqlalchemy.ext.mutable import MutableList
|
2023-12-24 21:53:49 +00:00
|
|
|
from sqlalchemy.orm import relationship, deferred
|
2024-02-16 11:38:22 +00:00
|
|
|
from sqlalchemy.types import *
|
2022-12-11 23:44:34 +00:00
|
|
|
from sqlalchemy.dialects.postgresql import ARRAY
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
from files.classes import Base
|
2022-02-10 20:35:16 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
from .hole_relationship import *
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
class Hole(Base):
|
|
|
|
__tablename__ = "holes"
|
2024-02-16 11:38:22 +00:00
|
|
|
name = Column(String, primary_key=True)
|
|
|
|
sidebar = Column(String)
|
|
|
|
sidebar_html = Column(String)
|
|
|
|
sidebarurls = Column(MutableList.as_mutable(ARRAY(String)), default=MutableList([]))
|
|
|
|
bannerurls = Column(MutableList.as_mutable(ARRAY(String)), default=MutableList([]))
|
|
|
|
marseyurl = Column(String)
|
|
|
|
css = deferred(Column(String))
|
2024-02-15 20:09:34 +00:00
|
|
|
stealth = Column(Boolean, default=False)
|
2024-02-15 21:34:09 +00:00
|
|
|
public_use = Column(Boolean, default=False)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2024-02-18 22:13:50 +00:00
|
|
|
|
2024-02-19 19:43:33 +00:00
|
|
|
if SITE_NAME == 'WPD' and not IS_LOCALHOST:
|
2024-02-11 10:26:54 +00:00
|
|
|
snappy_quotes = None
|
|
|
|
else:
|
2024-02-16 11:38:22 +00:00
|
|
|
snappy_quotes = deferred(Column(String))
|
2022-02-05 21:09:17 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
blocks = relationship("HoleBlock", primaryjoin="HoleBlock.hole==Hole.name")
|
|
|
|
followers = relationship("HoleFollow", primaryjoin="HoleFollow.hole==Hole.name")
|
2024-02-15 22:02:43 +00:00
|
|
|
stealth_hole_unblocks = relationship("StealthHoleUnblock", lazy="dynamic", primaryjoin="StealthHoleUnblock.hole==Hole.name")
|
2022-03-06 00:21:13 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-02-05 21:09:17 +00:00
|
|
|
def __repr__(self):
|
2022-09-11 14:32:04 +00:00
|
|
|
return self.name
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2023-11-04 22:03:26 +00:00
|
|
|
def random_sidebar(self):
|
|
|
|
if not self.sidebarurls: return None
|
|
|
|
return random.choice(self.sidebarurls)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
@property
|
2022-12-11 23:44:34 +00:00
|
|
|
@lazy
|
2022-12-12 01:03:22 +00:00
|
|
|
def random_banner(self):
|
2023-11-04 21:50:23 +00:00
|
|
|
if not self.bannerurls: return None
|
|
|
|
return random.choice(self.bannerurls)
|
2022-08-24 22:22:44 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def marsey_url(self):
|
2023-03-10 01:22:11 +00:00
|
|
|
if self.marseyurl: return self.marseyurl
|
2023-12-22 20:14:21 +00:00
|
|
|
return f'{SITE_FULL_IMAGES}/i/{SITE_NAME}/headericon.webp?x=7'
|
2022-03-06 00:21:13 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2024-02-15 22:03:01 +00:00
|
|
|
def stealth_hole_unblock_num(self):
|
2024-02-15 20:14:28 +00:00
|
|
|
return self.stealth_hole_unblocks.count()
|
2022-03-06 01:53:11 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def block_num(self):
|
2022-06-10 10:06:34 +00:00
|
|
|
return len(self.blocks)
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def follow_num(self):
|
2022-09-29 05:43:29 +00:00
|
|
|
return len(self.followers)
|