Commit 854e5e733344d9b8e3bd2a47224f0c40df26f23a
1 parent
0e188a92
Exists in
master
and in
4 other branches
Feed statuses, sort agents
Showing
1 changed file
with
22 additions
and
7 deletions
Show diff stats
app/commands/commands.py
@@ -83,6 +83,7 @@ def feed_from_irap(csv_file_name): | @@ -83,6 +83,7 @@ def feed_from_irap(csv_file_name): | ||
83 | baps = [] | 83 | baps = [] |
84 | grades = [] | 84 | grades = [] |
85 | companies = [] | 85 | companies = [] |
86 | + statuses = [] | ||
86 | # thematics = [] | 87 | # thematics = [] |
87 | # typologies = [] | 88 | # typologies = [] |
88 | for r in rows: | 89 | for r in rows: |
@@ -93,14 +94,16 @@ def feed_from_irap(csv_file_name): | @@ -93,14 +94,16 @@ def feed_from_irap(csv_file_name): | ||
93 | baps.append(r[bap_key]) | 94 | baps.append(r[bap_key]) |
94 | grades.append(r[grade_key]) | 95 | grades.append(r[grade_key]) |
95 | companies.append(r[company_key]) | 96 | companies.append(r[company_key]) |
96 | - agents.append({ | 97 | + statuses.append(r[status_key]) |
98 | + agent_dict = { | ||
97 | 'firstname': r[firstname_key], | 99 | 'firstname': r[firstname_key], |
98 | 'secondname': r[secondname_key], | 100 | 'secondname': r[secondname_key], |
99 | 'status': r[status_key], | 101 | 'status': r[status_key], |
100 | 'virtual': r[virtual_key], | 102 | 'virtual': r[virtual_key], |
101 | 'company': r[company_key], | 103 | 'company': r[company_key], |
102 | 'bap': r[bap_key], | 104 | 'bap': r[bap_key], |
103 | - 'grade': r[grade_key]}) | 105 | + 'grade': r[grade_key]} |
106 | + agents.append(agent_dict) | ||
104 | 107 | ||
105 | # Now, uniq/sort the lists | 108 | # Now, uniq/sort the lists |
106 | # | 109 | # |
@@ -111,11 +114,16 @@ def feed_from_irap(csv_file_name): | @@ -111,11 +114,16 @@ def feed_from_irap(csv_file_name): | ||
111 | baps = sorted(set(baps)) | 114 | baps = sorted(set(baps)) |
112 | grades = sorted(set(grades)) | 115 | grades = sorted(set(grades)) |
113 | companies = sorted(set(companies)) | 116 | companies = sorted(set(companies)) |
117 | + statuses = sorted(set(statuses)) | ||
114 | 118 | ||
119 | + # as agents is a list of dicts, sorting is a bit tricky | ||
120 | + # | ||
121 | + # the first one liner will store the last agent's line only | ||
122 | + # then we alpha sort on the name | ||
123 | + # on both, the discrimination is based on the name couple: (firstname, secondname) | ||
124 | + # | ||
115 | agents = list({(a['firstname'], a['secondname']): a for a in agents}.values()) | 125 | agents = list({(a['firstname'], a['secondname']): a for a in agents}.values()) |
116 | - print(agents) | ||
117 | - for a in agents: | ||
118 | - print(a) | 126 | + agents = sorted(agents, key=lambda a: (a['firstname'], a['secondname'])) |
119 | 127 | ||
120 | # Feed baps from column | 128 | # Feed baps from column |
121 | # | 129 | # |
@@ -138,6 +146,13 @@ def feed_from_irap(csv_file_name): | @@ -138,6 +146,13 @@ def feed_from_irap(csv_file_name): | ||
138 | db.session.add(n_c) | 146 | db.session.add(n_c) |
139 | db.session.commit() | 147 | db.session.commit() |
140 | 148 | ||
149 | + # Feed statuses from column | ||
150 | + # | ||
151 | + for s in statuses: | ||
152 | + n_s = AgentStatus(name=s) | ||
153 | + db.session.add(n_s) | ||
154 | + db.session.commit() | ||
155 | + | ||
141 | # Feed projects from column | 156 | # Feed projects from column |
142 | # | 157 | # |
143 | for p in projects: | 158 | for p in projects: |
@@ -165,7 +180,7 @@ def feed_from_irap(csv_file_name): | @@ -165,7 +180,7 @@ def feed_from_irap(csv_file_name): | ||
165 | db.session.add(Capacity(name="Agent")) | 180 | db.session.add(Capacity(name="Agent")) |
166 | db.session.commit() | 181 | db.session.commit() |
167 | 182 | ||
168 | - # Feed agents from column | 183 | + # Feed agents from columns |
169 | # | 184 | # |
170 | for a in agents: | 185 | for a in agents: |
171 | status = AgentStatus.query.filter(AgentStatus.name == a['status']).one_or_none() | 186 | status = AgentStatus.query.filter(AgentStatus.name == a['status']).one_or_none() |
@@ -184,7 +199,7 @@ def feed_from_irap(csv_file_name): | @@ -184,7 +199,7 @@ def feed_from_irap(csv_file_name): | ||
184 | n_a = Agent(firstname=a['firstname'], | 199 | n_a = Agent(firstname=a['firstname'], |
185 | secondname=a['secondname'], | 200 | secondname=a['secondname'], |
186 | status_id=status.id if status else None, | 201 | status_id=status.id if status else None, |
187 | - company_id=status.id if status else None, | 202 | + company_id=company.id if company else None, |
188 | bap_id=bap.id if bap else None, | 203 | bap_id=bap.id if bap else None, |
189 | grade_id=grade.id if bap else None, | 204 | grade_id=grade.id if bap else None, |
190 | virtual=virtual) | 205 | virtual=virtual) |