diff --git a/app/commands/commands.py b/app/commands/commands.py index 1aee668..34f5198 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -83,6 +83,7 @@ def feed_from_irap(csv_file_name): baps = [] grades = [] companies = [] + statuses = [] # thematics = [] # typologies = [] for r in rows: @@ -93,14 +94,16 @@ def feed_from_irap(csv_file_name): baps.append(r[bap_key]) grades.append(r[grade_key]) companies.append(r[company_key]) - agents.append({ + statuses.append(r[status_key]) + agent_dict = { 'firstname': r[firstname_key], 'secondname': r[secondname_key], 'status': r[status_key], 'virtual': r[virtual_key], 'company': r[company_key], 'bap': r[bap_key], - 'grade': r[grade_key]}) + 'grade': r[grade_key]} + agents.append(agent_dict) # Now, uniq/sort the lists # @@ -111,11 +114,16 @@ def feed_from_irap(csv_file_name): baps = sorted(set(baps)) grades = sorted(set(grades)) companies = sorted(set(companies)) + statuses = sorted(set(statuses)) + # as agents is a list of dicts, sorting is a bit tricky + # + # the first one liner will store the last agent's line only + # then we alpha sort on the name + # on both, the discrimination is based on the name couple: (firstname, secondname) + # agents = list({(a['firstname'], a['secondname']): a for a in agents}.values()) - print(agents) - for a in agents: - print(a) + agents = sorted(agents, key=lambda a: (a['firstname'], a['secondname'])) # Feed baps from column # @@ -138,6 +146,13 @@ def feed_from_irap(csv_file_name): db.session.add(n_c) db.session.commit() + # Feed statuses from column + # + for s in statuses: + n_s = AgentStatus(name=s) + db.session.add(n_s) + db.session.commit() + # Feed projects from column # for p in projects: @@ -165,7 +180,7 @@ def feed_from_irap(csv_file_name): db.session.add(Capacity(name="Agent")) db.session.commit() - # Feed agents from column + # Feed agents from columns # for a in agents: status = AgentStatus.query.filter(AgentStatus.name == a['status']).one_or_none() @@ -184,7 +199,7 @@ def feed_from_irap(csv_file_name): n_a = Agent(firstname=a['firstname'], secondname=a['secondname'], status_id=status.id if status else None, - company_id=status.id if status else None, + company_id=company.id if company else None, bap_id=bap.id if bap else None, grade_id=grade.id if bap else None, virtual=virtual) -- libgit2 0.21.2