From adf22b494aa94cabbf1bf3e5fa1f1510b26cc5ca Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 15 Nov 2022 08:05:42 -0800 Subject: [PATCH] sub relationship class (#456) * sub relationships * abstract = True * fix * fix spelling mistake --- files/classes/__init__.py | 4 +--- files/classes/sub.py | 3 +-- files/classes/sub_block.py | 19 --------------- files/classes/sub_join.py | 19 --------------- files/classes/sub_relationship.py | 39 +++++++++++++++++++++++++++++++ files/classes/sub_subscription.py | 19 --------------- files/classes/user.py | 4 +--- 7 files changed, 42 insertions(+), 65 deletions(-) delete mode 100644 files/classes/sub_block.py delete mode 100644 files/classes/sub_join.py create mode 100644 files/classes/sub_relationship.py delete mode 100644 files/classes/sub_subscription.py diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 00b624332..642fbb7a9 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -20,9 +20,7 @@ from .domains import * from .subscriptions import * from .mod_logs import * from .award import * -from .sub_block import * -from .sub_subscription import * -from .sub_join import * +from .sub_relationship import * from .saves import * from .views import * from .notifications import * diff --git a/files/classes/sub.py b/files/classes/sub.py index 2460e5f40..22c1a5c7c 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -8,8 +8,7 @@ from sqlalchemy.sql.sqltypes import * from files.classes import Base from files.helpers.lazy import lazy -from .sub_block import * -from .sub_subscription import * +from .sub_relationship import * SITE_NAME = environ.get("SITE_NAME", '').strip() SITE = environ.get("SITE", '').strip() diff --git a/files/classes/sub_block.py b/files/classes/sub_block.py deleted file mode 100644 index df6008828..000000000 --- a/files/classes/sub_block.py +++ /dev/null @@ -1,19 +0,0 @@ -import time - -from sqlalchemy import Column, ForeignKey -from sqlalchemy.sql.sqltypes import * - -from files.classes import Base - -class SubBlock(Base): - __tablename__ = "sub_blocks" - user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) - created_utc = Column(Integer) - - def __init__(self, *args, **kwargs): - if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) - super().__init__(*args, **kwargs) - - def __repr__(self): - return f"" diff --git a/files/classes/sub_join.py b/files/classes/sub_join.py deleted file mode 100644 index 5802cf212..000000000 --- a/files/classes/sub_join.py +++ /dev/null @@ -1,19 +0,0 @@ -import time - -from sqlalchemy import Column, ForeignKey -from sqlalchemy.sql.sqltypes import * - -from files.classes import Base - -class SubJoin(Base): - __tablename__ = "sub_joins" - user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) - created_utc = Column(Integer) - - def __init__(self, *args, **kwargs): - if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) - super().__init__(*args, **kwargs) - - def __repr__(self): - return f"" diff --git a/files/classes/sub_relationship.py b/files/classes/sub_relationship.py new file mode 100644 index 000000000..942cca845 --- /dev/null +++ b/files/classes/sub_relationship.py @@ -0,0 +1,39 @@ +import time + +from sqlalchemy import Column, ForeignKey +from sqlalchemy.orm import declared_attr +from sqlalchemy.sql.sqltypes import * + +from files.classes import Base + +class SubRelationship(Base): + __tablename__ = NotImplemented + __abstract__ = True + + @declared_attr + def user_id(self): + return Column(Integer, ForeignKey("users.id"), primary_key=True) + + @declared_attr + def sub(self): + return Column(String(20), ForeignKey("subs.name"), primary_key=True) + + @declared_attr + def created_utc(self): + return Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"<{self.__class__.__name__}(user_id={self.user_id}, sub={self.sub})>" + +class SubJoin(SubRelationship): + __tablename__ = "sub_joins" + +class SubBlock(SubRelationship): + __tablename__ = "sub_blocks" + +class SubSubscription(SubRelationship): + __tablename__ = "sub_subscriptions" diff --git a/files/classes/sub_subscription.py b/files/classes/sub_subscription.py deleted file mode 100644 index 001699193..000000000 --- a/files/classes/sub_subscription.py +++ /dev/null @@ -1,19 +0,0 @@ -import time - -from sqlalchemy import Column, ForeignKey -from sqlalchemy.sql.sqltypes import * - -from files.classes import Base - -class SubSubscription(Base): - __tablename__ = "sub_subscriptions" - user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) - created_utc = Column(Integer) - - def __init__(self, *args, **kwargs): - if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) - super().__init__(*args, **kwargs) - - def __repr__(self): - return f"" diff --git a/files/classes/user.py b/files/classes/user.py index c1f2dfd03..55f9aac70 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -27,10 +27,8 @@ from .mod import * from .mod_logs import * from .notifications import Notification from .saves import * -from .sub_block import * -from .sub_join import * +from .sub_relationship import * from .sub_logs import * -from .sub_subscription import * from .subscriptions import * from .userblock import *