From 5c117d641c667e1571dd615baeebef13a472487f Mon Sep 17 00:00:00 2001 From: Sam <78538841+spwoodcock@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:18:32 +0100 Subject: [PATCH] fix(backend): use latest pyxform syntax for xlsform conversion (fix xls ext usage) (#1789) * build: upgrade pyxform to latest 2.1.0 * fix(backend): use latest pyxform syntax for xlsform conversion (fix xls ext usage) --- src/backend/app/central/central_crud.py | 18 +++--------------- src/backend/pdm.lock | 18 +++++++++--------- src/backend/pyproject.toml | 2 +- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/backend/app/central/central_crud.py b/src/backend/app/central/central_crud.py index 39d9fb8994..7b7c3f6116 100644 --- a/src/backend/app/central/central_crud.py +++ b/src/backend/app/central/central_crud.py @@ -30,8 +30,7 @@ from fastapi import HTTPException from loguru import logger as log from osm_fieldwork.OdkCentral import OdkAppUser, OdkForm, OdkProject -from pyxform.builder import create_survey_element_from_dict -from pyxform.xls2json import parse_file_to_json +from pyxform.xls2xform import convert as xform_convert from sqlalchemy import text from sqlalchemy.orm import Session @@ -387,19 +386,8 @@ async def read_and_test_xform( ) from e else: try: - log.debug("Converting xlsform -> xform") - json_data = parse_file_to_json( - path=f"/dummy/path/with/file{file_ext}", - file_object=input_data, - ) - generated_xform = create_survey_element_from_dict(json_data) - # NOTE do not enable validate=True, as this requires Java to be installed - xform_bytesio = BytesIO( - generated_xform.to_xml( - validate=False, - pretty_print=False, - ).encode("utf-8") - ) + log.debug("Parsing XLSForm --> XML data") + xform_bytesio = BytesIO(xform_convert(input_data).xform.encode("utf-8")) except Exception as e: log.error(e) msg = f"XLSForm is invalid: {str(e)}" diff --git a/src/backend/pdm.lock b/src/backend/pdm.lock index 08536721c6..5fcce71d12 100644 --- a/src/backend/pdm.lock +++ b/src/backend/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "debug", "dev", "docs", "test", "monitoring"] strategy = ["cross_platform"] lock_version = "4.4.1" -content_hash = "sha256:59cb0981444a4053919d7682227b194b657ff2e806e8d5079ac9af25fe6c5e30" +content_hash = "sha256:dece6ce0db5c1445154361c5c4529b58d558fe30d21e450df8a375de26648ba0" [[package]] name = "aiohttp" @@ -1389,15 +1389,15 @@ files = [ [[package]] name = "openpyxl" -version = "3.1.2" +version = "3.1.3" requires_python = ">=3.6" summary = "A Python library to read/write Excel 2010 xlsx/xlsm files" dependencies = [ "et-xmlfile", ] files = [ - {file = "openpyxl-3.1.2-py2.py3-none-any.whl", hash = "sha256:f91456ead12ab3c6c2e9491cf33ba6d08357d802192379bb482f1033ade496f5"}, - {file = "openpyxl-3.1.2.tar.gz", hash = "sha256:a6f5977418eff3b2d5500d54d9db50c8277a368436f4e4f8ddb1be3422870184"}, + {file = "openpyxl-3.1.3-py2.py3-none-any.whl", hash = "sha256:25071b558db709de9e8782c3d3e058af3b23ffb2fc6f40c8f0c45a154eced2c3"}, + {file = "openpyxl-3.1.3.tar.gz", hash = "sha256:8dd482e5350125b2388070bb2477927be2e8ebc27df61178709bc8c8751da2f9"}, ] [[package]] @@ -2234,17 +2234,17 @@ files = [ [[package]] name = "pyxform" -version = "2.0.3" -requires_python = ">=3.7" +version = "2.1.0" +requires_python = ">=3.10" summary = "A Python package to create XForms for ODK Collect." dependencies = [ "defusedxml==0.7.1", - "openpyxl==3.1.2", + "openpyxl==3.1.3", "xlrd==2.0.1", ] files = [ - {file = "pyxform-2.0.3-py3-none-any.whl", hash = "sha256:eee2b130cc3d5d3aad7a9220a9941147d58a1e26e35835c778c4058b1f93734c"}, - {file = "pyxform-2.0.3.tar.gz", hash = "sha256:56ab1b3bd9da81c5c5d08a056eecbf926da9ab39a1f898e520af6c19d01e5e69"}, + {file = "pyxform-2.1.0-py3-none-any.whl", hash = "sha256:16c2eaafa4a68c9a757e316fa65fbf45f340820ab5d868dec9c57126d404492c"}, + {file = "pyxform-2.1.0.tar.gz", hash = "sha256:c71a11f58051a132a23b9e710501c6013f253e23a15dff82f481a419eb2b79d3"}, ] [[package]] diff --git a/src/backend/pyproject.toml b/src/backend/pyproject.toml index fe93499f28..aeca8c1689 100644 --- a/src/backend/pyproject.toml +++ b/src/backend/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "geoalchemy2==0.15.2", "geojson==3.1.0", "shapely==2.0.5", - "pyxform==2.0.3", + "pyxform==2.1.0", "loguru==0.7.2", "minio==7.2.7", "pyproj==3.6.1",