MarseyWorld/files/classes/group.py

44 lines
1.2 KiB
Python
Raw Normal View History

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)
owner_id = Column(Integer, ForeignKey("users.id"))
2024-02-13 13:00:58 +00:00
description = Column(String)
2023-02-24 06:31:06 +00:00
memberships = relationship("GroupMembership", primaryjoin="GroupMembership.group_name==Group.name", order_by="GroupMembership.approved_utc")
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):
2023-10-29 13:22:36 +00:00
return set(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]