Commit 3495b723 authored by berumuron's avatar berumuron
Browse files

add: Provide basic CSV export

parent cbd466e8
import csv
import io
from datetime import datetime
from flask import (
......@@ -9,6 +11,7 @@ from flask import (
render_template,
g,
abort,
make_response,
)
from .auth import login_required
......@@ -121,3 +124,33 @@ def delete(event_id):
flash("L’évènement a été correctement supprimé.", "success")
return redirect(url_for("events.index"))
@bp.route("/export")
def export():
if g.current_user is None:
events = Event.items(is_private=False)
else:
events = Event.items()
stringio = io.StringIO()
csv_writer = csv.DictWriter(
stringio,
fieldnames=["titre", "date", "date de fin", "privé", "projet", "description"],
)
csv_writer.writeheader()
for event in events:
csv_writer.writerow(
{
"titre": event.title,
"date": event.date,
"date de fin": event.date_end,
"privé": event.is_private,
"projet": event.project.name if event.project else "",
"description": event.description,
}
)
response = make_response(stringio.getvalue())
response.headers["Content-Disposition"] = "attachment; filename=export.csv"
response.headers["Content-type"] = "text/csv"
return response
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment