Skip to content

Commit

Permalink
Added json template
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Sep 2, 2024
1 parent bfd01c9 commit 8833230
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 41 deletions.
109 changes: 68 additions & 41 deletions controllers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,73 @@

baseDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def template():
if request.args.get("filetype","") == "xlsx":
filePath = os.path.join(baseDir, 'files', 'Template - Excel Workbook.xlsx')
return send_file(
filePath,
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
as_attachment=True,
download_name="Template - Excel Workbook.xlsx"
),200
elif request.args.get("filetype","") == "xls":
filePath = os.path.join(baseDir, 'files', 'Template - Excel.xls')
return send_file(
filePath,
mimetype="application/vnd.ms-excel",
as_attachment=True,
download_name="Template - Excel.xls"
),200

elif request.args.get("filetype","") == "csv":
filePath = os.path.join(baseDir, 'files', 'Template - CSV.csv')
return send_file(
filePath,
mimetype="text/csv",
as_attachment=True,
download_name="Template - CSV.csv"
),200

elif request.args.get("filetype","") == "ods":
filePath = os.path.join(baseDir, 'files', 'Template - ODS.ods')
return send_file(
filePath,
mimetype="application/vnd.oasis.opendocument.spreadsheet",
as_attachment=True,
download_name="Template - ODS.ods"
),200
if request.args.get("filetype", "") == "xlsx":
filePath = os.path.join(baseDir, "files", "Template - Excel Workbook.xlsx")
return (
send_file(
filePath,
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
as_attachment=True,
download_name="Template - Excel Workbook.xlsx",
),
200,
)
elif request.args.get("filetype", "") == "xls":
filePath = os.path.join(baseDir, "files", "Template - Excel.xls")
return (
send_file(
filePath,
mimetype="application/vnd.ms-excel",
as_attachment=True,
download_name="Template - Excel.xls",
),
200,
)

elif request.args.get("filetype", "") == "csv":
filePath = os.path.join(baseDir, "files", "Template - CSV.csv")
return (
send_file(
filePath,
mimetype="text/csv",
as_attachment=True,
download_name="Template - CSV.csv",
),
200,
)

elif request.args.get("filetype", "") == "ods":
filePath = os.path.join(baseDir, "files", "Template - ODS.ods")
return (
send_file(
filePath,
mimetype="application/vnd.oasis.opendocument.spreadsheet",
as_attachment=True,
download_name="Template - ODS.ods",
),
200,
)
elif request.args.get("filetype", "") == "json":
filePath = os.path.join(baseDir, "files", "Template - JSON.json")
return (
send_file(
filePath,
mimetype="application/json",
as_attachment=True,
download_name="Template - JSON.json",
),
200,
)
else:
filePath = os.path.join(baseDir, 'files', 'templates.zip')
return send_file(
filePath,
mimetype="application/zip",
as_attachment=True,
download_name="templates.zip"
),200
filePath = os.path.join(baseDir, "files", "templates.zip")
return (
send_file(
filePath,
mimetype="application/zip",
as_attachment=True,
download_name="templates.zip",
),
200,
)
20 changes: 20 additions & 0 deletions files/Template - JSON.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"First Name": "",
"Middle Name": "",
"Last Name": "",
"Phone Number 1": "",
"Phone Number 2": "",
"Email 1": "",
"Email 2": ""
},
{
"First Name": "",
"Middle Name": "",
"Last Name": "",
"Phone Number 1": "",
"Phone Number 2": "",
"Email 1": "",
"Email 2": ""
}
]

0 comments on commit 8833230

Please sign in to comment.