2022-12-12 01:03:22 +00:00
|
|
|
import random
|
2022-11-15 09:19:08 +00:00
|
|
|
import time
|
2022-12-11 23:44:34 +00:00
|
|
|
from typing import Optional
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
from sqlalchemy import Column
|
2022-12-11 23:44:34 +00:00
|
|
|
from sqlalchemy.ext.mutable import MutableList
|
2022-03-06 00:21:13 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
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
|
|
|
|
2022-11-15 16:05:42 +00:00
|
|
|
from .sub_relationship import *
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-02-05 21:09:17 +00:00
|
|
|
class Sub(Base):
|
|
|
|
__tablename__ = "subs"
|
2022-12-11 23:44:34 +00:00
|
|
|
name = Column(VARCHAR(SUB_NAME_COLUMN_LENGTH), primary_key=True)
|
|
|
|
sidebar = Column(VARCHAR(SUB_SIDEBAR_COLUMN_LENGTH))
|
|
|
|
sidebar_html = Column(VARCHAR(SUB_SIDEBAR_HTML_COLUMN_LENGTH))
|
|
|
|
sidebarurl = Column(VARCHAR(SUB_SIDEBAR_URL_COLUMN_LENGTH))
|
|
|
|
bannerurls = Column(MutableList.as_mutable(ARRAY(VARCHAR(SUB_BANNER_URL_COLUMN_LENGTH))), default=MutableList([]), nullable=False)
|
|
|
|
marseyurl = Column(VARCHAR(SUB_MARSEY_URL_LENGTH))
|
|
|
|
css = Column(VARCHAR(SUB_CSS_COLUMN_LENGTH))
|
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
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name")
|
|
|
|
followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name")
|
2022-11-11 15:00:56 +00:00
|
|
|
joins = relationship("SubJoin", lazy="dynamic", primaryjoin="SubJoin.sub==Sub.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
|
|
|
|
def sidebar_url(self):
|
2023-03-10 01:22:11 +00:00
|
|
|
if self.sidebarurl: return self.sidebarurl
|
2023-03-19 16:28:19 +00:00
|
|
|
return f'{SITE_FULL_IMAGES}/i/{SITE_NAME}/sidebar.webp?v=3009'
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2022-12-11 23:44:34 +00:00
|
|
|
def banner_urls(self):
|
2023-03-06 16:53:40 +00:00
|
|
|
return self.bannerurls
|
2022-12-11 23:44:34 +00:00
|
|
|
|
|
|
|
@lazy
|
2022-12-12 01:03:22 +00:00
|
|
|
def random_banner(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
if not self.banner_urls: return None
|
|
|
|
return random.choice(self.banner_urls)
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def has_banners(self) -> bool:
|
|
|
|
return bool(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-03-19 16:28:19 +00:00
|
|
|
return f'{SITE_FULL_IMAGES}/i/{SITE_NAME}/headericon.webp?v=3009'
|
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)
|