Skip to content

Commit

Permalink
fix: add template data extract example (#1011)
Browse files Browse the repository at this point in the history
* feat: created an api to upload template files to s3

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* added templates in static folder

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: sujanadh <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 28, 2023
1 parent bc6b5cd commit 9cb8a60
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,3 +1273,29 @@ async def get_task_status(
message=task_message or None,
# progress=some_func_to_get_progress,
)


from ..static import data_path


@router.post("/templates")
async def get_template_file(
file_type: str = Query(
..., enum=["data_extracts", "form"], description="Choose file type"
)
):
"""Get template file.
Args: file_type: Type of template file.
returns: Requested file as a FileResponse.
"""
file_type_paths = {
"data_extracts": f"{data_path}/template/template.geojson",
"form": f"{data_path}/template/template.xls",
}
file_path = file_type_paths.get(file_type)
filename = file_path.split("/")[-1]
return FileResponse(
file_path, media_type="application/octet-stream", filename=filename
)
23 changes: 23 additions & 0 deletions src/backend/app/static/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team
#
# This file is part of FMTM.
#
# FMTM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FMTM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.


"""Static files."""

import os

data_path = os.path.dirname(os.path.abspath(__file__))
26 changes: 26 additions & 0 deletions src/backend/app/static/template/template.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "FeatureCollection",
"name": "sample_data_extract",
"crs": {
"type": "name",
"properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" }
},
"features": [
{
"type": "Feature",
"properties": { "id": 1, "title": null },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[85.927672852225669, 26.730898147144199],
[85.92779345357259, 26.731001012998917],
[85.927896319427305, 26.730859129061376],
[85.927779265178827, 26.730777545797284],
[85.927672852225669, 26.730898147144199]
]
]
}
}
]
}

0 comments on commit 9cb8a60

Please sign in to comment.