forked from Netflix/dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
71 lines (47 loc) · 1.77 KB
/
models.py
File metadata and controls
71 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from datetime import datetime
from typing import List, Optional
from sqlalchemy import Column, DateTime, Integer, String, ForeignKey, event
from sqlalchemy.orm import relationship
from sqlalchemy_utils import JSONType, TSVectorType
from dispatch.database.core import Base
from dispatch.models import DispatchBase, Pagination
from .enums import ReportTypes
class Report(Base):
id = Column(Integer, primary_key=True)
created_at = Column(DateTime, default=datetime.utcnow)
details = Column(JSONType, nullable=True)
details_raw = Column(String, nullable=True)
type = Column(String, nullable=False, server_default=ReportTypes.tactical_report)
# relationships
incident_id = Column(Integer, ForeignKey("incident.id", ondelete="CASCADE", use_alter=True))
participant_id = Column(Integer, ForeignKey("participant.id"))
document = relationship("Document", uselist=False, backref="report")
# full text search capabilities
search_vector = Column(TSVectorType("details_raw"))
@staticmethod
def _details_raw(mapper, connection, target):
target.details_raw = " ".join(target.details.values())
@classmethod
def __declare_last__(cls):
event.listen(cls, "before_update", cls._details_raw)
# Pydantic models...
class ReportBase(DispatchBase):
details: Optional[dict] = None
type: ReportTypes
class ReportCreate(ReportBase):
pass
class ReportUpdate(ReportBase):
pass
class ReportRead(ReportBase):
id: int
created_at: Optional[datetime] = None
class ReportPagination(Pagination):
items: List[ReportRead] = []
class TacticalReportCreate(DispatchBase):
conditions: str
actions: str
needs: str
class ExecutiveReportCreate(DispatchBase):
current_status: str
overview: str
next_steps: str