From 9cb8a60b8df824fd2b4b3651f8d813c2f35fe9cb Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:30:32 +0545 Subject: [PATCH] fix: add template data extract example (#1011) * 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 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/backend/app/projects/project_routes.py | 26 +++++++++++++++++++ src/backend/app/static/__init__.py | 23 ++++++++++++++++ .../app/static/template/template.geojson | 26 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/backend/app/static/__init__.py create mode 100644 src/backend/app/static/template/template.geojson diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index d4ced03ab2..bd652ff53b 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -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 + ) diff --git a/src/backend/app/static/__init__.py b/src/backend/app/static/__init__.py new file mode 100644 index 0000000000..b28277a6f6 --- /dev/null +++ b/src/backend/app/static/__init__.py @@ -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 . + + +"""Static files.""" + +import os + +data_path = os.path.dirname(os.path.abspath(__file__)) diff --git a/src/backend/app/static/template/template.geojson b/src/backend/app/static/template/template.geojson new file mode 100644 index 0000000000..58faad9eb8 --- /dev/null +++ b/src/backend/app/static/template/template.geojson @@ -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] + ] + ] + } + } + ] +}