Skip to content

Commit

Permalink
Update sort tables input from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ximenesuk committed Mar 6, 2024
1 parent 653627f commit dd3baab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ResponseType(StrEnum):
)

sort_tables_form = Form(
default=False,
default='default',
title='Sort worksheets',
description=('Sort the worksheets into alphabetical order '
'or leave in the order found in the AGS file. '
Expand Down Expand Up @@ -240,7 +240,7 @@ def prepare_validation_response(request, data):
" sort worksheets in .xlsx file in alphabetical order."))
async def convert(background_tasks: BackgroundTasks,
files: List[UploadFile] = conversion_file,
sort_tables: bool = sort_tables_form,
sort_tables: str = sort_tables_form,
request: Request = None):
"""
Convert files between .ags and .xlsx format. Option to sort worksheets in .xlsx file in alphabetical order.
Expand All @@ -258,12 +258,11 @@ async def convert(background_tasks: BackgroundTasks,
:raises Exception: If the conversion fails or an unexpected error occurs.
"""

if sort_tables == 'default':
sort_tables = None
if not files[0].filename:
raise InvalidPayloadError(request)
RESULTS = 'results'
sorting_strategy = None
if sort_tables:
sorting_strategy = 'alphabetical'
tmp_dir = Path(tempfile.mkdtemp())
results_dir = tmp_dir / RESULTS
results_dir.mkdir()
Expand All @@ -274,7 +273,7 @@ async def convert(background_tasks: BackgroundTasks,
contents = await file.read()
local_file = tmp_dir / file.filename
local_file.write_bytes(contents)
converted, result = conversion.convert(local_file, results_dir, sorting_strategy=sorting_strategy)
converted, result = conversion.convert(local_file, results_dir, sorting_strategy=sort_tables)
log = validation.to_plain_text(result)
f.write(log)
f.write('\n' + '=' * 80 + '\n')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def test_convert_good_files(async_client, tmp_path):


@pytest.mark.asyncio
@pytest.mark.parametrize('sort_tables', [True, False, None])
@pytest.mark.parametrize('sort_tables', ['alphabetical', None])
async def test_convert_sort_tables(async_client, tmp_path, sort_tables):
# Arrange
fields = []
Expand Down

0 comments on commit dd3baab

Please sign in to comment.