2022-02-05 21:09:17 +00:00
|
|
|
from sqlalchemy import *
|
2022-03-06 00:21:13 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-02-05 21:09:17 +00:00
|
|
|
from files.__main__ import Base
|
2022-02-10 20:35:16 +00:00
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
from os import environ
|
2022-03-06 01:53:11 +00:00
|
|
|
from .sub_block import *
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-04-25 21:59:12 +00:00
|
|
|
SITE_NAME = environ.get("SITE_NAME", '').strip()
|
|
|
|
SITE = environ.get("DOMAIN", '').strip()
|
2022-02-11 23:32:14 +00:00
|
|
|
if SITE == "localhost": SITE_FULL = 'http://' + SITE
|
|
|
|
else: SITE_FULL = 'https://' + SITE
|
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-02-11 23:32:14 +00:00
|
|
|
css = Column(String)
|
2022-02-05 21:09:17 +00:00
|
|
|
|
2022-05-25 17:01:29 +00:00
|
|
|
blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name", viewonly=True)
|
2022-03-06 01:53:11 +00:00
|
|
|
|
2022-03-06 00:21:13 +00:00
|
|
|
|
2022-02-05 21:09:17 +00:00
|
|
|
def __repr__(self):
|
2022-02-10 20:35:16 +00:00
|
|
|
return f"<Sub(name={self.name})>"
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def sidebar_url(self):
|
2022-02-11 20:01:07 +00:00
|
|
|
if self.sidebarurl: return SITE_FULL + self.sidebarurl
|
2022-04-02 17:11:35 +00:00
|
|
|
return f'/assets/images/{SITE_NAME}/sidebar.webp?v=1041'
|
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-06-01 20:08:33 +00:00
|
|
|
return f'/assets/images/{SITE_NAME}/banner.webp?v=1048'
|
2022-03-06 00:21:13 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def subscription_num(self):
|
2022-03-06 01:53:11 +00:00
|
|
|
return self.subscriptions.count()
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def block_num(self):
|
2022-05-25 17:01:29 +00:00
|
|
|
return len(self.blocks)
|