This repository was archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
143 lines (120 loc) · 4.88 KB
/
models.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# coding: utf-8
import os
from sqlalchemy import (Boolean, Column, Date, DateTime, ForeignKey, Integer,
Table, Text, create_engine, text)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
engine = create_engine(
os.getenv('DATABASE_URL', ('postgres://account_admin_user@localhost:5454'
'/account_admin')))
Base = declarative_base(engine)
metadata = Base.metadata
t_client_product_association = Table(
'client_product_association', metadata,
Column(
'product_type_id',
ForeignKey('product_type.product_type_id'),
primary_key=True,
nullable=False),
Column(
'client_organization_id',
ForeignKey('client_organization.client_organization_id'),
primary_key=True,
nullable=False))
class Client(Base):
__tablename__ = 'client_organization'
client_organization_id = Column(
Integer,
primary_key=True,
server_default=text("nextval("
"'client_organization_client_organization_id_seq'"
"::regclass)"))
client_organization_code = Column(Text)
client_organization_name = Column(Text, nullable=False)
assigned_account_name = Column(Text, nullable=False)
account_manager_id = Column(ForeignKey('person.person_id'))
secondary_manager_id = Column(ForeignKey('person.person_id'))
dfp_network_code = Column(Integer)
dfp_display_name = Column(Text)
notes = Column(Text)
oao_inbox_name = Column(Text)
oao_escalation_group_name = Column(Text)
oao_shared_folder = Column(Text, comment='Path to Google Drive folder')
oao_wiki_page = Column(Text, comment='Polaris URL')
contract_start_date = Column(Date)
contract_end_date = Column(Date)
active_client_flag = Column(Boolean, server_default=text("true"))
created_datetime = Column(DateTime, server_default=text("now()"))
modified_datetime = Column(DateTime)
created_by = Column(Text)
modified_by = Column(Text)
account_manager = relationship('Employee', foreign_keys=account_manager_id)
secondary_manager = relationship(
'Employee', foreign_keys=secondary_manager_id)
products = relationship(
'Product',
secondary=t_client_product_association,
backref='client_organization',
passive_deletes=True)
def __str__(self):
return '{0}: {1}({2})'.format(self.client_organization_name,
self.client_organization_code,
self.dfp_network_code)
class Product(Base):
__tablename__ = 'product_type'
product_type_id = Column(
Integer,
primary_key=True,
server_default=text(
"nextval('product_type_product_type_id_seq'::regclass)"))
product_type_code = Column(Text, nullable=False)
product_type_name = Column(Text, nullable=False)
product_type_description = Column(Text)
created_datetime = Column(DateTime, server_default=text("now()"))
modified_datetime = Column(DateTime)
created_by = Column(Text)
modified_by = Column(Text)
clients = relationship(
'Client',
secondary=t_client_product_association,
backref='product_type')
def __str__(self):
return self.product_type_name
class Employee(Base):
__tablename__ = 'person'
gsuite_id = Column('person_code', Text, nullable=False)
first_name = Column(Text, nullable=False)
last_name = Column(Text, nullable=False)
office_id = Column(ForeignKey('office.office_id'))
email = Column(Text, nullable=False)
created_datetime = Column(DateTime, server_default=text("now()"))
modified_datetime = Column(DateTime)
person_id = Column(
Integer,
primary_key=True,
server_default=text("nextval('person_person_id_seq'::regclass)"))
manager_person_id = Column(ForeignKey('person.person_id'))
account_manager_flag = Column(Boolean)
current_employee_flag = Column(Boolean, server_default=text("true"))
created_by = Column(Text)
modified_by = Column(Text)
office = relationship('Office', backref='employee')
manager = relationship(
'Employee', remote_side=[person_id], order_by='Employee.email')
def __str__(self):
return '{0} {1} ({2})'.format(self.first_name, self.last_name,
self.email)
__mapper_args__ = {"order_by": email}
class Office(Base):
__tablename__ = 'office'
office_id = Column(
Integer,
primary_key=True,
server_default=text("nextval('oao_office_office_id_seq'::regclass)"))
office_name = Column(Text, nullable=False)
created_datetime = Column(DateTime, server_default=text("now()"))
modified_datetime = Column(DateTime)
created_by = Column(Text)
modified_by = Column(Text)
def __str__(self):
return self.office_name