2023-02-24 06:31:06 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from sqlalchemy.types import Integer
|
|
|
|
|
|
|
|
from files.classes import Base
|
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
from files.helpers.config.const import *
|
|
|
|
|
|
|
|
from .group_membership import *
|
|
|
|
|
|
|
|
class Group(Base):
|
|
|
|
__tablename__ = "groups"
|
|
|
|
name = Column(String, primary_key=True)
|
|
|
|
created_utc = Column(Integer)
|
2024-02-11 11:00:37 +00:00
|
|
|
owner_id = Column(Integer, ForeignKey("users.id"))
|
2024-02-13 13:00:58 +00:00
|
|
|
description = Column(String)
|
2024-02-15 18:48:36 +00:00
|
|
|
description_html = Column(String)
|
2023-02-24 06:31:06 +00:00
|
|
|
|
2024-01-12 13:52:23 +00:00
|
|
|
memberships = relationship("GroupMembership", primaryjoin="GroupMembership.group_name==Group.name", order_by="GroupMembership.approved_utc")
|
2024-10-16 23:00:39 +00:00
|
|
|
blacklists = relationship("GroupBlacklist", primaryjoin="GroupBlacklist.group_name==Group.name", order_by="GroupBlacklist.created_utc")
|
2024-02-11 11:00:37 +00:00
|
|
|
owner = relationship("User", primaryjoin="Group.owner_id==User.id")
|
2023-02-24 06:31:06 +00:00
|
|
|
|
|
|
|
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 self.name
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2023-02-24 19:29:07 +00:00
|
|
|
def membership_user_ids(self):
|
|
|
|
return [x.user_id for x in self.memberships]
|
2023-02-24 06:31:06 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def member_ids(self):
|
2024-08-14 16:10:33 +00:00
|
|
|
return {x.user_id for x in self.memberships if x.approved_utc}
|
2023-02-24 06:31:06 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def applied_ids(self):
|
|
|
|
return [x.user_id for x in self.memberships if not x.approved_utc]
|
2024-08-12 18:07:55 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def permalink(self):
|
|
|
|
return f"{SITE_FULL}/!{self.name}"
|