2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
from os import environ
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
2022-03-06 00:21:13 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2022-02-10 20:35:16 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2022-11-20 22:16:49 +00:00
|
|
|
from files.helpers.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"
|
|
|
|
name = Column(String, primary_key=True)
|
|
|
|
sidebar = Column(String)
|
|
|
|
sidebar_html = Column(String)
|
2022-02-10 20:35:16 +00:00
|
|
|
sidebarurl = Column(String)
|
|
|
|
bannerurl = Column(String)
|
2022-08-24 22:22:44 +00:00
|
|
|
marseyurl = Column(String)
|
2022-02-11 23:32:14 +00:00
|
|
|
css = Column(String)
|
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):
|
2022-02-11 20:01:07 +00:00
|
|
|
if self.sidebarurl: return SITE_FULL + self.sidebarurl
|
2022-08-24 22:22:44 +00:00
|
|
|
return f'/i/{SITE_NAME}/sidebar.webp?v=3009'
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def banner_url(self):
|
2022-02-11 20:01:07 +00:00
|
|
|
if self.bannerurl: return SITE_FULL + self.bannerurl
|
2022-08-24 22:22:44 +00:00
|
|
|
return f'/i/{SITE_NAME}/banner.webp?v=3009'
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def marsey_url(self):
|
|
|
|
if self.marseyurl: return SITE_FULL + self.marseyurl
|
|
|
|
return f'/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)
|