class User(db.Model, Base): __tablename__ = "users" email = db.Column(db.Unicode(), unique=True) username = db.Column(db.Unicode(25), unique=True) avatar = db.Column(db.Unicode(), nullable=True) bio = db.Column(db.Unicode(100), nullable=True) supporter = db.Column(db.Boolean(), default=False) developer = db.Column(db.Boolean(), default=False) moderator = db.Column(db.Boolean(), default=False) editor = db.Column(db.Boolean(), default=False) joined_at = db.Column(db.DateTime, default=datetime.utcnow) email_verified = db.Column(db.Boolean(), default=False) password = db.Column(db.Binary()) last_pass_reset = db.Column(db.DateTime()) def to_dict(self): return { k: v for k, v in super().to_dict().items() if k not in DEFAULT_FILTERED } def to_self_dict(self): """ Converts the model to a dict, but keeps `email` in. Used for the `/users/@me` endpoint in particular. """ return { k: v for k, v in super().to_dict().items() if k not in COMMON_FILTERED }
class Mod(db.Model, Base): __tablename__ = "mod" title = db.Column(db.Unicode(64), unique=True) generalized_title = db.Column(db.Unicode(), unique=True, default=create_generalized_title, onupdate=create_generalized_title) icon = db.Column(db.Unicode()) banner = db.Column(db.Unicode()) tagline = db.Column(db.Unicode(100)) description = db.Column(db.Unicode(10000)) website = db.Column(db.Unicode()) is_private_beta = db.Column(db.Boolean(), default=False) category = db.Column(db.Enum(ModCategory), default=ModCategory.unassigned) nsfw = db.Column(db.Boolean(), default=False) theme_color = db.Column(db.Enum(ModColor)) released_at = db.Column(db.Date(), nullable=True) last_updated = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) status = db.Column(db.Enum(ModStatus)) # TODO: probably turn this into a table and have better metrics for determining DLs downloads = db.Column(db.BigInteger(), default=0) download_url = db.Column(db.Unicode(), nullable=True) verified = db.Column(db.Boolean(), default=False) def __init__(self, **kwargs): super().__init__(**kwargs) self._authors = [] self._owner = None @property def authors(self): return self._authors @authors.setter def authors(self, value: "User"): if hasattr(value, "role"): # TODO: try to figure this out in the loader query. if value.role.role == AuthorRole.owner: self._owner = value return self._authors.append(value) @property def owner(self): return self._owner def to_dict(self): return { **{ k: v for k, v in super().to_dict().items() if k not in ("generalized_title", ) }, "authors": self._authors, "owner": self._owner }
class User(db.Model, Base): __tablename__ = "user" email = db.Column(db.Unicode(), unique=True) username = db.Column(db.Unicode(25), unique=True) avatar = db.Column(db.Unicode(), nullable=True, default=create_default_avatar) bio = db.Column(db.Unicode(100), nullable=True) supporter = db.Column(db.Boolean(), default=False) developer = db.Column(db.Boolean(), default=False) moderator = db.Column(db.Boolean(), default=False) editor = db.Column(db.Boolean(), default=False) email_verified = db.Column(db.Boolean(), default=False) password = db.Column(db.Binary()) last_pass_reset = db.Column(db.DateTime()) def __init__(self, **kwargs): super().__init__(**kwargs) self._role = None self._role_name = None @property def role(self): return self._role @role.setter def role(self, value: ModAuthor): self._role = value self._role_name = value.role.name def to_dict(self): return { **{ k: v for k, v in super().to_dict().items() if k not in DEFAULT_FILTERED }, "role": self._role_name, # "__": self._role.to_dict() } def to_self_dict(self): """ Converts the model to a dict, but keeps `email` in. Used for the `/users/@me` endpoint in particular. """ return { k: v for k, v in super().to_dict().items() if k not in COMMON_FILTERED }
class EditorsChoice(db.Model, Base): __tablename__ = "editors_choice" mod_id = db.Column(None, db.ForeignKey("mods.id")) featured = db.Column(db.Boolean(), default=False) editors_notes = db.Column(db.Unicode(500), nullable=True) # 500 char limit as defined in spec author_id = db.Column(None, db.ForeignKey("users.id")) article_url = db.Column(db.Unicode(), nullable=True)
class Mod(db.Model, Base): __tablename__ = "mods" title = db.Column(db.Unicode(64), unique=True) icon = db.Column(db.Unicode(), nullable=True) tagline = db.Column(db.Unicode(100)) description = db.Column(db.Unicode(10000)) website = db.Column(db.Unicode()) category = db.Column(db.Enum(ModCategory), default=ModCategory.Unassigned) nsfw = db.Column(db.Boolean(), default=False) released_at = db.Column(db.Date(), nullable=True) last_updated = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) status = db.Column(db.Enum(ModStatus)) downloads = db.Column(db.BigInteger(), default=0) download_url = db.Column(db.Unicode(), nullable=True) verified = db.Column(db.Boolean(), default=False)