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
|
2022-12-11 23:44:34 +00:00
|
|
|
from sqlalchemy.types import VARCHAR, Boolean, Integer
|
|
|
|
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"
|
|
|
|
name = Column(VARCHAR(HOLE_NAME_COLUMN_LENGTH), primary_key=True)
|
|
|
|
sidebar = Column(VARCHAR(HOLE_SIDEBAR_COLUMN_LENGTH))
|
|
|
|
sidebar_html = Column(VARCHAR(HOLE_SIDEBAR_HTML_COLUMN_LENGTH))
|
2024-02-02 23:24:22 +00:00
|
|
|
sidebarurls = Column(MutableList.as_mutable(ARRAY(VARCHAR(HOLE_BANNER_URL_COLUMN_LENGTH))), default=MutableList([]))
|
|
|
|
bannerurls = Column(MutableList.as_mutable(ARRAY(VARCHAR(HOLE_BANNER_URL_COLUMN_LENGTH))), default=MutableList([]))
|
2023-10-07 17:55:50 +00:00
|
|
|
marseyurl = Column(VARCHAR(HOLE_MARSEY_URL_LENGTH))
|
2023-12-24 21:53:49 +00:00
|
|
|
css = deferred(Column(VARCHAR(CSS_LENGTH_LIMIT)))
|
2022-08-19 21:31:26 +00:00
|
|
|
stealth = Column(Boolean)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
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")
|
|
|
|
joins = 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
|
2022-11-11 15:00:56 +00:00
|
|
|
def join_num(self):
|
|
|
|
return self.joins.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)
|