From 1596323e43dff78b5f68c634d8cbcb35bed861a1 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 13:44:27 +0545 Subject: [PATCH 1/9] create xform with two different geojson files fields --- src/backend/app/central/central_crud.py | 139 ++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/src/backend/app/central/central_crud.py b/src/backend/app/central/central_crud.py index 08d61fe0dc..452e098815 100644 --- a/src/backend/app/central/central_crud.py +++ b/src/backend/app/central/central_crud.py @@ -602,3 +602,142 @@ def convert_csv( csvin.finishGeoJson() return True + + +def create_odk_xform_for_janakpur( + project_id: int, + xform_id: str, + filespec: str, + odk_credentials: project_schemas.ODKCentral = None, + create_draft: bool = False, + upload_media=True, + convert_to_draft_when_publishing=True, +): + """Create an XForm on a remote ODK Central server.""" + title = os.path.basename(os.path.splitext(filespec)[0]) + # result = xform.createForm(project_id, title, filespec, True) + # Pass odk credentials of project in xform + + if not odk_credentials: + odk_credentials = project_schemas.ODKCentral( + odk_central_url=settings.ODK_CENTRAL_URL, + odk_central_user=settings.ODK_CENTRAL_USER, + odk_central_password=settings.ODK_CENTRAL_PASSWD, + ) + try: + xform = get_odk_form(odk_credentials) + except Exception as e: + log.error(e) + raise HTTPException( + status_code=500, detail={"message": "Connection failed to odk central"} + ) from e + + result = xform.createForm(project_id, xform_id, filespec, create_draft) + + if result != 200 and result != 409: + return result + data = f"/tmp/{title}.geojson" + + # This modifies an existing published XForm to be in draft mode. + # An XForm must be in draft mode to upload an attachment. + if upload_media: + + # Upload buildings file + building_file = f"/tmp/buildings_{title}.geojson" + + result = xform.uploadMedia( + project_id, title, building_file, convert_to_draft_when_publishing + ) + + # Upload roads file + road_file = f"/tmp/roads_{title}.geojson" + result = xform.uploadMedia( + project_id, title, road_file, convert_to_draft_when_publishing + ) + + result = xform.publishForm(project_id, title) + return result + + + +def generate_updated_xform_for_janakpur( + xlsform: str, + xform: str, + form_type: str, +): + """Update the version in an XForm so it's unique.""" + name = os.path.basename(xform).replace(".xml", "") + + print("Name in form = ", name) + + outfile = xform + if form_type != "xml": + try: + xls2xform_convert(xlsform_path=xlsform, xform_path=outfile, validate=False) + except Exception as e: + log.error(f"Couldn't convert {xlsform} to an XForm!", str(e)) + raise HTTPException(status_code=400, detail=str(e)) from e + + if os.path.getsize(outfile) <= 0: + log.warning(f"{outfile} is empty!") + raise HTTPException(status=400, detail=f"{outfile} is empty!") from None + + xls = open(outfile, "r") + data = xls.read() + xls.close() + else: + xls = open(xlsform, "r") + data = xls.read() + xls.close() + + tmp = name.split("_") + tmp[0] + tmp[1] + id = tmp[2].split(".")[0] + + buildings_extract = f"jr://file/buildings_{name}.geojson" + roads_extract = f"jr://file/roads_{name}.geojson" + + namespaces = { + "h": "http://www.w3.org/1999/xhtml", + "odk": "http://www.opendatakit.org/xforms", + "xforms": "http://www.w3.org/2002/xforms", + } + + import xml.etree.ElementTree as ET + + root = ET.fromstring(data) + head = root.find("h:head", namespaces) + model = head.find("xforms:model", namespaces) + instances = model.findall("xforms:instance", namespaces) + + index = 0 + for inst in instances: + try: + if "src" in inst.attrib: + print("SRC = Present") + if (inst.attrib["src"]) == "jr://file/buildings.geojson": #FIXME + print("INST attribs = ", inst.attrib["src"]) + inst.attrib["src"] = buildings_extract + + if (inst.attrib["src"]) == "jr://file/roads.geojson": #FIXME + inst.attrib["src"] = roads_extract + + # Looking for data tags + data_tags = inst.findall("xforms:data", namespaces) + if data_tags: + for dt in data_tags: + dt.attrib["id"] = id + except Exception: + continue + index += 1 + + # Save the modified XML + newxml = ET.tostring(root) + + # write the updated XML file + outxml = open(outfile, "w") + outxml.write(newxml.decode()) + outxml.close() + + return outfile From 0a82f00820c19693d94f3fe337ddf345d0d53361 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 13:46:33 +0545 Subject: [PATCH 2/9] api to generate qr codes and other media files for janakpur pilot project --- src/backend/app/projects/project_crud.py | 243 +++++++++++++++++++++ src/backend/app/projects/project_routes.py | 93 ++++++++ 2 files changed, 336 insertions(+) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 5c17882096..86d46908db 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -2356,3 +2356,246 @@ async def get_mbtiles_list(db: Session, project_id: int): async def convert_geojson_to_osm(geojson_file: str): """Convert a GeoJSON file to OSM format.""" return json2osm(geojson_file) + + +def generate_appuser_files_for_janakpur( + db: Session, + project_id: int, + form: str, + building_extracts_contents: str, + road_extracts_contents: str, + category: str, + form_type: str, + background_task_id: uuid.UUID, + ): + project_log = log.bind(task="create_project", project_id=project_id) + + project_log.info(f"Starting generate_appuser_files for project {project_id}") + + # Get the project table contents. + project = table( + "projects", + column("project_name_prefix"), + column("xform_title"), + column("id"), + column("odkid"), + column("odk_central_url"), + column("odk_central_user"), + column("odk_central_password"), + column("outline"), + ) + + where = f"id={project_id}" + sql = select( + project.c.project_name_prefix, + project.c.xform_title, + project.c.id, + project.c.odkid, + project.c.odk_central_url, + project.c.odk_central_user, + project.c.odk_central_password, + geoalchemy2.functions.ST_AsGeoJSON(project.c.outline).label("outline"), + ).where(text(where)) + result = db.execute(sql) + + # There should only be one match + if result.rowcount != 1: + log.warning(str(sql)) + if result.rowcount < 1: + raise HTTPException(status_code=400, detail="Project not found") + else: + raise HTTPException(status_code=400, detail="Multiple projects found") + + one = result.first() + + if one: + prefix = one.project_name_prefix + + # Get odk credentials from project. + odk_credentials = { + "odk_central_url": one.odk_central_url, + "odk_central_user": one.odk_central_user, + "odk_central_password": one.odk_central_password, + } + + odk_credentials = project_schemas.ODKCentral(**odk_credentials) + + xform_title = one.xform_title if one.xform_title else None + + if form: + xlsform = f"/tmp/custom_form.{form_type}" + contents = form + with open(xlsform, "wb") as f: + f.write(contents) + else: + xlsform = f"{xlsforms_path}/{xform_title}.xls" + + category = xform_title + + # FIXME: Need to figure out this step. + # Data Extracts + if building_extracts_contents is not None: + project_log.info("Uploading data extracts") + upload_custom_data_extracts(db, project_id, building_extracts_contents) + + if road_extracts_contents is not None: + project_log.info("Uploading roads data") + upload_custom_data_extracts(db, project_id, road_extracts_contents, "highways") + + # Generating QR Code, XForm and uploading OSM Extracts to the form. + # Creating app users and updating the role of that usegenerate_updated_xformr. + tasks_list = tasks_crud.get_task_lists(db, project_id) + + project_name = prefix + odk_id = one.odkid + project_obj = get_project(db, project_id) + + for task_id in tasks_list: + + # Generate taskFiles + name = f"{project_name}_{category}_{task_id}" + + appuser = central_crud.create_appuser(odk_id, name, odk_credentials) + + # If app user could not be created, raise an exception. + if not appuser: + project_log.error("Couldn't create appuser for project") + return False + + # prefix should be sent instead of name + project_log.info(f"Creating qr code for task_id {task_id}") + create_qr = create_qrcode( + db, + odk_id, + appuser.json()["token"], + project_name, + odk_credentials.odk_central_url, + ) + + task = tasks_crud.get_task(db, task_id) + task.qr_code_id = create_qr["qr_code_id"] + db.commit() + db.refresh(task) + + # This file will store xml contents of an xls form. + xform = f"/tmp/{name}.xml" + + print("XFORM = ", xform) + + buildings_extracts = f"/tmp/buildings_{name}.geojson" # This file will store osm extracts + roads_extracts = f"/tmp/roads_{name}.geojson" # This file will store osm extracts + + # xform_id_format + xform_id = f"{name}".split("_")[2] + + # Get the features for this task. + # Postgis query to filter task inside this task outline and of this project + # Update those features and set task_id + query = text( + f"""UPDATE features + SET task_id={task_id} + WHERE id IN ( + SELECT id + FROM features + WHERE project_id={project_id} + AND ST_IsValid(geometry) + AND ST_IsValid('{task.outline}'::Geometry) + AND ST_Contains('{task.outline}'::Geometry, ST_Centroid(geometry)) + )""" + ) + result = db.execute(query) + + # Get the geojson of those features for this task. + buildings_query = text( + f"""SELECT jsonb_build_object( + 'type', 'FeatureCollection', + 'features', jsonb_agg(feature) + ) + FROM ( + SELECT jsonb_build_object( + 'type', 'Feature', + 'id', id, + 'geometry', ST_AsGeoJSON(geometry)::jsonb, + 'properties', properties + ) AS feature + FROM features + WHERE project_id={project_id} and task_id={task_id} and category_title='buildings' + ) features;""" + ) + result = db.execute(buildings_query) + features = result.fetchone()[0] + + highway_query = text( + f"""SELECT jsonb_build_object( + 'type', 'FeatureCollection', + 'features', jsonb_agg(feature) + ) + FROM ( + SELECT jsonb_build_object( + 'type', 'Feature', + 'id', id, + 'geometry', ST_AsGeoJSON(geometry)::jsonb, + 'properties', properties + ) AS feature + FROM features + WHERE project_id={project_id} and task_id={task_id} and category_title='highways' + ) features;""" + ) + highway_result = db.execute(highway_query) + highway_features = highway_result.fetchone()[0] + + # upload_media = False if features["features"] is None else True + upload_media = True + + # Update outfile containing osm extracts with the new geojson contents containing title in the properties. + with open(buildings_extracts, "w") as jsonfile: + jsonfile.truncate(0) # clear the contents of the file + dump(features, jsonfile) + + # Update outfile containing osm extracts with the new geojson contents containing title in the properties. + with open(roads_extracts, "w") as jsonfile: + jsonfile.truncate(0) # clear the contents of the file + dump(highway_features, jsonfile) + + project_log.info(f"Generating xform for task {task_id}") + outfile = central_crud.generate_updated_xform_for_janakpur(xlsform, xform, form_type) + + # Create an odk xform + project_log.info(f"Uploading media in {task_id}") + result = central_crud.create_odk_xform_for_janakpur( + odk_id, task, outfile, odk_credentials, False, upload_media + ) + + project_log.info(f"Updating role for app user in task {task_id}") + # Update the user role for the created xform. + try: + # Pass odk credentials + if odk_credentials: + url = odk_credentials.odk_central_url + user = odk_credentials.odk_central_user + pw = odk_credentials.odk_central_password + + else: + log.debug("ODKCentral connection variables not set in function") + log.debug("Attempting extraction from environment variables") + url = settings.ODK_CENTRAL_URL + user = settings.ODK_CENTRAL_USER + pw = settings.ODK_CENTRAL_PASSWD + + odk_app = OdkAppUser(url, user, pw) + + odk_app.updateRole( + projectId=odk_id, xform=xform_id, actorId=appuser.json()["id"] + ) + + except Exception as e: + log.warning(str(e)) + + project_obj.extract_completed_count += 1 + db.commit() + db.refresh(project_obj) + + # Update background task status to COMPLETED + update_background_task_status_in_database( + db, background_task_id, 4 + ) # 4 is COMPLETED diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index 6ba0578d97..f9cd04353f 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -1056,3 +1056,96 @@ async def project_centroid( result = db.execute(query) result_dict_list = [{"id": row[0], "centroid": row[1]} for row in result.fetchall()] return result_dict_list + + + +@router.post("/{project_id}/generate_files_for_janakpur") +async def generate_files_janakpur( + background_tasks: BackgroundTasks, + project_id: int, + buildings_file: UploadFile, + roads_file: UploadFile, + form: UploadFile, + db: Session = Depends(database.get_db), + ): + """ + Generate required media files tasks in the project based on the provided params. + """ + log.debug(f"Generating media files tasks for project: {project_id}") + xform_title = None + + project = project_crud.get_project(db, project_id) + if not project: + raise HTTPException( + status_code=428, detail=f"Project with id {project_id} does not exist" + ) + + project.data_extract_type = "polygon" + db.commit() + + if form: + log.debug("Validating uploaded XLS file") + # Validating for .XLS File. + file_name = os.path.splitext(form.filename) + file_ext = file_name[1] + allowed_extensions = [".xls", ".xlsx", ".xml"] + if file_ext not in allowed_extensions: + raise HTTPException(status_code=400, detail="Provide a valid .xls file") + xform_title = file_name[0] + await form.seek(0) + contents = await form.read() + project.form_xls = contents + db.commit() + + if buildings_file: + log.debug("Validating uploaded buildings geojson file") + # Validating for .geojson File. + data_extracts_file_name = os.path.splitext(buildings_file.filename) + extracts_file_ext = data_extracts_file_name[1] + if extracts_file_ext != ".geojson": + raise HTTPException(status_code=400, detail="Provide a valid geojson file") + try: + buildings_extracts_contents = await buildings_file.read() + json.loads(buildings_extracts_contents) + except json.JSONDecodeError: + raise HTTPException(status_code=400, detail="Provide a valid geojson file") + + if roads_file: + log.debug("Validating uploaded roads geojson file") + # Validating for .geojson File. + road_extracts_file_name = os.path.splitext(roads_file.filename) + road_extracts_file_ext = road_extracts_file_name[1] + if road_extracts_file_ext != ".geojson": + raise HTTPException(status_code=400, detail="Provide a valid geojson file") + try: + road_extracts_contents = await roads_file.read() + json.loads(road_extracts_contents) + except json.JSONDecodeError: + raise HTTPException(status_code=400, detail="Provide a valid geojson file") + + # generate a unique task ID using uuid + background_task_id = uuid.uuid4() + + # insert task and task ID into database + log.debug( + f"Creating background task ID {background_task_id} " + f"for project ID: {project_id}" + ) + await project_crud.insert_background_task_into_database( + db, task_id=background_task_id, project_id=project_id + ) + + log.debug(f"Submitting {background_task_id} to background tasks stack") + background_tasks.add_task( + project_crud.generate_appuser_files_for_janakpur, + db, + project_id, + contents, + buildings_extracts_contents if buildings_file else None, + road_extracts_contents if roads_file else None, + xform_title, + file_ext[1:] if form else "xls", + background_task_id, + ) + + return {"Message": f"{project_id}", "task_id": f"{background_task_id}"} From b5ccdd74abf5864b40f9ad18a976124d517d3a6e Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 13:47:49 +0545 Subject: [PATCH 3/9] upload data extracts according to the category --- src/backend/app/projects/project_crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 86d46908db..27e1124121 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -1169,7 +1169,7 @@ def upload_custom_data_extracts( properties = flatten_dict(feature["properties"]) db_feature = db_models.DbFeatures( - project_id=project_id, geometry=wkb_element, properties=properties + project_id=project_id, geometry=wkb_element, properties=properties, category_title=category ) db.add(db_feature) db.commit() From 1ba589ae1e81ac687a3845e1f7c68246e51187d1 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 18:04:07 +0545 Subject: [PATCH 4/9] uploaded all the roads in the odk form --- src/backend/app/projects/project_crud.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 27e1124121..efb8dc71f1 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -404,16 +404,18 @@ def update_multi_polygon_project_boundary( 0 ] - def remove_z_dimension(coord): - """Helper to remove z dimension. + # def remove_z_dimension(coord): + # """Helper to remove z dimension. - To be used in lambda, to remove z dimension from - each coordinate in the feature's geometry. - """ - return coord.pop() if len(coord) == 3 else None + # To be used in lambda, to remove z dimension from + # each coordinate in the feature's geometry. + # """ + # print("COord = ", coord) + # print('length of coord = ',len(coord)) + # return coord.pop() if len(coord) == 3 else None - # Apply the lambda function to each coordinate in its geometry - list(map(remove_z_dimension, polygon["geometry"]["coordinates"][0])) + # # Apply the lambda function to each coordinate in its geometry + # list(map(remove_z_dimension, polygon["geometry"]["coordinates"][0])) db_task = db_models.DbTask( project_id=project_id, @@ -2538,7 +2540,7 @@ def generate_appuser_files_for_janakpur( 'properties', properties ) AS feature FROM features - WHERE project_id={project_id} and task_id={task_id} and category_title='highways' + WHERE project_id={project_id} ) features;""" ) highway_result = db.execute(highway_query) From f50a32cc1038c4cab988d5008aa10df4d445657a Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 18:07:09 +0545 Subject: [PATCH 5/9] fix: bbox and centroid issue in tasks geometry --- src/backend/app/db/postgis_utils.py | 4 ++-- src/backend/app/tasks/tasks_crud.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index b21cafd909..302a5c40e9 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -37,9 +37,9 @@ def geometry_to_geojson(geometry: Geometry, properties: str = {}, id: int = None "geometry": mapping(shape), "properties": properties, "id": id, - "bbox": shape.bounds, + # "bbox": shape.bounds, } - return Feature(**geojson) + def get_centroid(geometry: Geometry, properties: str = {}): diff --git a/src/backend/app/tasks/tasks_crud.py b/src/backend/app/tasks/tasks_crud.py index 9e3d369048..c0b4766f57 100644 --- a/src/backend/app/tasks/tasks_crud.py +++ b/src/backend/app/tasks/tasks_crud.py @@ -257,7 +257,7 @@ def convert_to_app_task(db_task: db_models.DbTask): app_task.outline_geojson = geometry_to_geojson( db_task.outline, properties, db_task.id ) - app_task.outline_centroid = get_centroid(db_task.outline) + # app_task.outline_centroid = get_centroid(db_task.outline) if db_task.lock_holder: app_task.locked_by_uid = db_task.lock_holder.id From 5eee14b5e998dd09aa1565fbde331152fcd575e7 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 18:13:08 +0545 Subject: [PATCH 6/9] returned Feature parsed geojson in geomtery_to_geojson --- src/backend/app/db/postgis_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index 302a5c40e9..42199f367d 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -39,6 +39,7 @@ def geometry_to_geojson(geometry: Geometry, properties: str = {}, id: int = None "id": id, # "bbox": shape.bounds, } + return Feature(**geojson) From 3167ebafc6778aeacce417b59e4bd6a25a75d9fb Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 18:13:27 +0545 Subject: [PATCH 7/9] commented centroid in TaskBase schema --- src/backend/app/tasks/tasks_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/app/tasks/tasks_schemas.py b/src/backend/app/tasks/tasks_schemas.py index 34923cb092..dbe99833d7 100644 --- a/src/backend/app/tasks/tasks_schemas.py +++ b/src/backend/app/tasks/tasks_schemas.py @@ -63,7 +63,7 @@ class TaskBase(BaseModel): project_task_index: int project_task_name: str outline_geojson: Feature - outline_centroid: Feature + # outline_centroid: Feature # initial_feature_count: int task_status: TaskStatus locked_by_uid: int = None From 8bb54765908bb6cfa69940b79e89e7da6608230c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:37:25 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/backend/app/db/postgis_utils.py | 1 - src/backend/app/projects/project_crud.py | 34 +++++++++++++++--------- src/backend/app/tasks/tasks_crud.py | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index 42199f367d..a147a0e765 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -42,7 +42,6 @@ def geometry_to_geojson(geometry: Geometry, properties: str = {}, id: int = None return Feature(**geojson) - def get_centroid(geometry: Geometry, properties: str = {}): if geometry: shape = to_shape(geometry) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index a3058cee76..834092eece 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -2362,15 +2362,15 @@ async def convert_geojson_to_osm(geojson_file: str): def generate_appuser_files_for_janakpur( - db: Session, - project_id: int, - form: str, - building_extracts_contents: str, - road_extracts_contents: str, - category: str, - form_type: str, - background_task_id: uuid.UUID, - ): + db: Session, + project_id: int, + form: str, + building_extracts_contents: str, + road_extracts_contents: str, + category: str, + form_type: str, + background_task_id: uuid.UUID, +): project_log = log.bind(task="create_project", project_id=project_id) project_log.info(f"Starting generate_appuser_files for project {project_id}") @@ -2443,7 +2443,9 @@ def generate_appuser_files_for_janakpur( if road_extracts_contents is not None: project_log.info("Uploading roads data") - upload_custom_data_extracts(db, project_id, road_extracts_contents, "highways") + upload_custom_data_extracts( + db, project_id, road_extracts_contents, "highways" + ) # Generating QR Code, XForm and uploading OSM Extracts to the form. # Creating app users and updating the role of that usegenerate_updated_xformr. @@ -2482,8 +2484,12 @@ def generate_appuser_files_for_janakpur( # This file will store xml contents of an xls form. xform = f"/tmp/{name}.xml" - buildings_extracts = f"/tmp/buildings_{name}.geojson" # This file will store osm extracts - roads_extracts = f"/tmp/roads_{name}.geojson" # This file will store osm extracts + buildings_extracts = ( + f"/tmp/buildings_{name}.geojson" # This file will store osm extracts + ) + roads_extracts = ( + f"/tmp/roads_{name}.geojson" # This file will store osm extracts + ) # xform_id_format xform_id = f"{name}".split("_")[2] @@ -2558,7 +2564,9 @@ def generate_appuser_files_for_janakpur( dump(highway_features, jsonfile) project_log.info(f"Generating xform for task {task_id}") - outfile = central_crud.generate_updated_xform_for_janakpur(xlsform, xform, form_type) + outfile = central_crud.generate_updated_xform_for_janakpur( + xlsform, xform, form_type + ) # Create an odk xform project_log.info(f"Uploading media in {task_id}") diff --git a/src/backend/app/tasks/tasks_crud.py b/src/backend/app/tasks/tasks_crud.py index c0b4766f57..3bd1db2d36 100644 --- a/src/backend/app/tasks/tasks_crud.py +++ b/src/backend/app/tasks/tasks_crud.py @@ -32,7 +32,7 @@ from ..central import central_crud from ..db import db_models -from ..db.postgis_utils import geometry_to_geojson, get_centroid +from ..db.postgis_utils import geometry_to_geojson from ..models.enums import ( TaskStatus, get_action_for_status_change, From c537c7e677842ceea1ed7950b77836507eb20e0e Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 28 Sep 2023 19:02:35 +0545 Subject: [PATCH 9/9] fix: upload all the roads for janakpur project to the odk form --- src/backend/app/projects/project_crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index a3058cee76..694eb63a0e 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -2538,7 +2538,7 @@ def generate_appuser_files_for_janakpur( 'properties', properties ) AS feature FROM features - WHERE project_id={project_id} and task_id={task_id} and category_title='highways' + WHERE project_id={project_id} and category_title='highways' ) features;""" ) highway_result = db.execute(highway_query)