| Total Complexity | 4 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| 1 | from .model import * |
||
| 5 | class Announcement(Base): |
||
| 6 | __tablename__ = 'announcements' |
||
| 7 | |||
| 8 | id = Column(Integer, primary_key=True, nullable=False) |
||
| 9 | timestamp = Column(ArrowType, nullable=False, default=datetime.datetime.utcnow) |
||
| 10 | user_id = Column(Integer, ForeignKey("users.id"), nullable=False) # user that added the announcement |
||
| 11 | announcement = Column(Text) |
||
| 12 | enabled = Column(Boolean, default=True, nullable=False) |
||
| 13 | deleted = Column(Boolean, default=False, nullable=False) |
||
| 14 | |||
| 15 | def __init__(self, user, announcement): |
||
| 16 | self.user_id = user.id |
||
| 17 | self.announcement = announcement |
||
| 18 | |||
| 19 | @classmethod |
||
| 20 | def from_id(cls, id): |
||
| 21 | e = DBSession.query(cls).filter(cls.id == id).one() |
||
| 22 | return e |
||
| 23 | |||
| 24 | @classmethod |
||
| 25 | def all(cls): |
||
| 26 | e = DBSession.query(cls).filter(cls.deleted==False).all() |
||
| 27 | return e |
||
| 28 | |||
| 29 | @classmethod |
||
| 30 | def all_enabled(cls): |
||
| 31 | e = DBSession.query(cls)\ |
||
| 32 | .filter(cls.deleted==False)\ |
||
| 33 | .filter(cls.enabled==True)\ |
||
| 34 | .all() |
||
| 35 | return e |
||
| 36 |