Skip to content

Commit

Permalink
fix: replace custom pyxform with multi-stage bytesio usage
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Mar 25, 2024
1 parent e1b871c commit c17594e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from loguru import logger as log
from osm_fieldwork.CSVDump import CSVDump
from osm_fieldwork.OdkCentral import OdkAppUser, OdkForm, OdkProject
from pyxform.xls2xform import xls2xform_convert
from pyxform.builder import create_survey_element_from_dict
from pyxform.xls2json import parse_file_to_json
from sqlalchemy import text
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -475,14 +476,17 @@ async def read_and_test_xform(
else:
try:
log.debug("Converting xlsform -> xform")
# NOTE do not enable validate=True, as this requires Java installed
xform_bytesio, warnings = xls2xform_convert(
xlsform_path=f"/tmp/form{file_ext}",
validate=False,
xlsform_object=input_data,
json_data = parse_file_to_json(
path="/dummy/path/with/file/ext.xls",
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,
).encode("utf-8")
)
if warnings:
log.warning(warnings)
except Exception as e:
log.error(e)
msg = f"XLSForm is invalid: {str(e)}"
Expand Down
2 changes: 1 addition & 1 deletion src/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"geoalchemy2==0.14.2",
"geojson==3.1.0",
"shapely==2.0.2",
"pyxform @ git+https://github.com/hotosm/pyxform@feat/xls2xform_convert_bytesio",
"pyxform==2.0.2",
"sentry-sdk==1.38.0",
"py-cpuinfo==9.0.0",
"loguru==0.7.2",
Expand Down

0 comments on commit c17594e

Please sign in to comment.