|
1 | 1 | import datetime |
| 2 | +from enum import Enum |
2 | 3 | from uuid import UUID |
3 | 4 |
|
4 | 5 | import sqlalchemy as sa |
5 | 6 | from sqlalchemy.dialects import postgresql as pg |
6 | 7 | from sqlalchemy.ext.hybrid import hybrid_property |
7 | 8 | from sqlalchemy.ext.mutable import MutableDict, MutableList |
| 9 | +from sqlalchemy.orm import Mapped, relationship |
8 | 10 |
|
9 | 11 | from h.db import Base, types |
10 | 12 | from h.models.group import Group |
11 | 13 | from h.util import markdown_render, uri |
12 | 14 | from h.util.user import split_user |
13 | 15 |
|
14 | 16 |
|
| 17 | +class ModerationStatus(Enum): |
| 18 | + APPROVED = "APPROVED" |
| 19 | + PENDING = "PENDING" |
| 20 | + DENIED = "DENIED" |
| 21 | + SPAM = "SPAM" |
| 22 | + |
| 23 | + |
15 | 24 | class Annotation(Base): |
16 | 25 | """Model class representing a single annotation.""" |
17 | 26 |
|
| 27 | + # Expose the ModerationStatus directly here |
| 28 | + ModerationStatus = ModerationStatus |
| 29 | + |
18 | 30 | __tablename__ = "annotation" |
19 | 31 | __table_args__ = ( |
20 | 32 | # Tags are stored in an array-type column, and indexed using a |
@@ -68,7 +80,7 @@ class Annotation(Base): |
68 | 80 | index=True, |
69 | 81 | ) |
70 | 82 |
|
71 | | - group = sa.orm.relationship( |
| 83 | + group = relationship( |
72 | 84 | Group, |
73 | 85 | primaryjoin=(Group.pubid == groupid), |
74 | 86 | foreign_keys=[groupid], |
@@ -138,11 +150,15 @@ class Annotation(Base): |
138 | 150 | uselist=True, |
139 | 151 | ) |
140 | 152 |
|
141 | | - mentions = sa.orm.relationship("Mention", back_populates="annotation") |
| 153 | + mentions = relationship("Mention", back_populates="annotation") |
142 | 154 |
|
143 | | - notifications = sa.orm.relationship( |
144 | | - "Notification", back_populates="source_annotation" |
145 | | - ) |
| 155 | + notifications = relationship("Notification", back_populates="source_annotation") |
| 156 | + |
| 157 | + moderation_status: Mapped[ModerationStatus | None] |
| 158 | + """Current moderation status of the annotation. |
| 159 | +
|
| 160 | + None means the annotation is either "approved" before this column was added or it's a private annotation. |
| 161 | + """ |
146 | 162 |
|
147 | 163 | @property |
148 | 164 | def uuid(self): |
|
0 commit comments