Skip to content

Commit

Permalink
People: CLI import command extended for organisation fields Improved …
Browse files Browse the repository at this point in the history
…error output for incorrect header fields

TYPE: Feature
LINK: ogc-1736
  • Loading branch information
Tschuppi81 authored Jul 12, 2024
1 parent 47267ee commit 4fdef5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/onegov/people/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import click
import re
import transaction
Expand Down Expand Up @@ -71,6 +73,8 @@ def _clear(request: 'CoreRequest', app: 'Framework') -> None:
('Beruf', 'profession'),
('Politische Partei', 'political_party'),
('Fraktion', 'parliamentary_group'),
('Organisation', 'organisation'),
('Unterorganisation', 'sub_organisation'),
('Webseite', 'website'),
('Webseite 2', 'website_2'),
('Standort Adresse', 'location_address'),
Expand All @@ -91,7 +95,7 @@ def export_xlsx(filename: str) -> 'Callable[[CoreRequest, Framework], None]':
Example:
onegov-people --select '/org/govikon' export people.xlsx
onegov-people --select '/onegov_org/govikon' export people.xlsx
"""

Expand Down Expand Up @@ -127,7 +131,7 @@ def import_xlsx(file: IO[bytes]) -> 'Callable[[CoreRequest, Framework], None]':
Example:
onegov-people --select '/org/govikon' import people.xlsx
onegov-people --select '/onegov_org/govikon' import people.xlsx
"""

Expand All @@ -148,7 +152,13 @@ def _import(request: 'CoreRequest', app: 'Framework') -> None:
for index, row in enumerate(sheet.rows):
values = tuple(cell.value for cell in row)
if not index:
assert values == tuple(EXPORT_FIELDS.keys())
if values != tuple(EXPORT_FIELDS.keys()):
click.echo('Error in column headers')
click.echo('\nExpected - Current')
for exp, cur in zip(tuple(EXPORT_FIELDS.keys()), values):
color = 'green' if exp == cur else 'red'
click.secho(f'{exp} - {cur}', fg=color)
sys.exit('\nAborting import')
else:
session.add(
Person(**dict(zip(EXPORT_FIELDS.values(), values)))
Expand Down
6 changes: 6 additions & 0 deletions tests/onegov/people/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def test_cli(cfg_path, session_manager, temporary_directory):
profession='Former Major',
political_party='Republican Party',
parliamentary_group='Republicans',
organisation='Super Org',
sub_organisation='Sub Org',
website='https://foo.bar',
postal_address='Fakestreet 123',
postal_code_city='1234 Govikon',
Expand Down Expand Up @@ -106,6 +108,8 @@ def test_cli(cfg_path, session_manager, temporary_directory):
assert person.profession == 'Former Major'
assert person.political_party == 'Republican Party'
assert person.parliamentary_group == 'Republicans'
assert person.organisation == 'Super Org'
assert person.sub_organisation == 'Sub Org'
assert person.website == 'https://foo.bar'
assert person.postal_address == 'Fakestreet 123'
assert person.postal_code_city == '1234 Govikon'
Expand All @@ -125,6 +129,8 @@ def test_cli(cfg_path, session_manager, temporary_directory):
assert person.profession == 'Teacher'
assert person.political_party is None
assert person.parliamentary_group is None
assert person.organisation is None
assert person.sub_organisation is None
assert person.website is None
assert person.postal_address is None
assert person.picture_url is None
Expand Down

0 comments on commit 4fdef5e

Please sign in to comment.