-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_data_creator.py
executable file
·175 lines (156 loc) · 5.34 KB
/
default_data_creator.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from farado.items.user import User
from farado.items.role import Role
from farado.items.rule import Rule
from farado.items.user_role import UserRole
from farado.items.project import Project
from farado.items.workflow import Workflow
from farado.items.state import State
from farado.items.edge import Edge
from farado.items.board import Board
from farado.items.board_column import BoardColumn
from farado.items.issue import Issue
from farado.items.issue_kind import IssueKind
from farado.items.field import Field
from farado.items.field_kind import FieldKind, ValueTypes
from farado.items.meta_item_manager import MetaItemManager
from farado.project_manager import ProjectManager
from farado.permission_manager import PermissionFlag
from farado.general_manager_holder import gm_holder
from farado.config import farado_config
def main():
data_creator = DefaultDataCreator()
data_creator.create_users()
data_creator.create_workflow()
data_creator.create_board()
data_creator.create_issues()
class DefaultDataCreator:
def __init__(self) -> None:
self.meta_item_manager = MetaItemManager(farado_config['database']['connection_string'])
self.project_manager = ProjectManager()
gm_holder.set_meta_item_manager(self.meta_item_manager)
gm_holder.set_project_manager(self.project_manager)
self.add_item = self.meta_item_manager.add_item
def create_users(self):
user = User(
'admin',
'John',
'Ivanovich',
'Smith',
'john.smith@ivanovich.com',
password="admin",
)
self.add_item(user)
role = Role('Administrator')
role.rules.append(Rule(
caption='Admin rule',
is_admin=True,
project_rights=PermissionFlag.deleter
))
self.add_item(role)
self.add_item(UserRole(user_id=user.id, role_id=role.id))
def create_workflow(self):
workflow = Workflow(caption="Standard workflow")
state_01 = State(caption="ToDo")
state_02 = State(caption="In Progress")
state_03 = State(caption="Testing")
state_04 = State(caption="Done")
workflow.states.append(state_01)
workflow.states.append(state_02)
workflow.states.append(state_03)
workflow.states.append(state_04)
self.add_item(workflow)
workflow.edges.append(Edge(state_01.id, state_02.id))
workflow.edges.append(Edge(state_02.id, state_03.id))
workflow.edges.append(Edge(state_03.id, state_04.id))
self.add_item(workflow)
self.default_state_id = state_01.id
self.state_id_02 = state_02.id
self.state_id_03 = state_03.id
self.state_id_04 = state_04.id
self.default_workflow_id = workflow.id
def create_board(self):
board = Board(
caption="Main board",
workflow_id=self.default_workflow_id)
board.board_columns.append(
BoardColumn(
state_id=self.default_state_id,
caption='ToDo (Opened)',
order=1
))
board.board_columns.append(
BoardColumn(
state_id=self.state_id_02,
caption='In Progress',
order=2
))
board.board_columns.append(
BoardColumn(
state_id=self.state_id_03,
caption='In Test',
order=3
))
board.board_columns.append(
BoardColumn(
state_id=self.state_id_04,
caption='Done',
order=4
))
self.add_item(board)
def create_issues(self):
issue_kind = IssueKind("Task")
issue_kind.workflow_id = self.default_workflow_id
issue_kind.default_state_id = self.default_state_id
issue_kind.field_kinds.append(
FieldKind(
"Developer",
ValueTypes.user_id,
"Issue developer"
)
)
issue_kind.field_kinds.append(
FieldKind(
"Field2",
ValueTypes.integer,
"Some integer value"
)
)
self.add_item(issue_kind)
# ====================== #
project = Project(
"Project caption 1",
"Project content 1"
)
issue1 = self.project_manager.create_issue(issue_kind.id)
issue1.caption = "Issue 1"
issue1.content = "Issue content 1"
project.issues.append(issue1)
self.add_item(project)
issue2 = self.project_manager.create_issue(issue_kind.id)
issue2.caption = "Issue 2"
issue2.content = "Issue content 2"
issue2.parent_id = issue1.id
project.issues.append(issue2)
self.add_item(project)
# ====================== #
project2 = Project(
"Project caption 2",
"Project content 2"
)
project2.issues.append(
Issue(
"Issue caption 21",
"Issue content 21"
)
)
project2.issues.append(
Issue(
"Issue caption 22",
"Issue content 22"
)
)
self.add_item(project2)
if __name__ == '__main__':
main()