CSV Export
parent
6b9467be56
commit
2a850ff4b1
Binary file not shown.
21
app/keep.py
21
app/keep.py
|
|
@ -1,4 +1,4 @@
|
|||
from flask import Blueprint, render_template, request, g, url_for, redirect
|
||||
from flask import Blueprint, render_template, request, g, url_for, redirect, Response
|
||||
from datetime import datetime
|
||||
import sqlite3
|
||||
|
||||
|
|
@ -76,3 +76,22 @@ def delete_keepalive(item_id):
|
|||
c.execute("DELETE FROM keepalive2 WHERE id = ?", (item_id,))
|
||||
conn.commit()
|
||||
return redirect(url_for('keep.dispkeepalive'))
|
||||
|
||||
|
||||
@keep.route('/download_csv')
|
||||
def download_csv():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT location, date, time FROM keepalive2 ORDER BY id DESC")
|
||||
rows = c.fetchall()
|
||||
conn.close()
|
||||
|
||||
output = "Location,Date,Time\n"
|
||||
for row in rows:
|
||||
output += f"{row[0]},{row[1]},{row[2]}\n"
|
||||
|
||||
return Response(
|
||||
output,
|
||||
mimetype='text/csv',
|
||||
headers={"Content-Disposition": "attachment;filename=keepalive.csv"}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="text-center mt-4">
|
||||
<a href="{{ url_for('keep.download_csv') }}" class="btn btn-primary">Download CSV</a>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<h1 class="offset-lg-3">No items to show.</h1>
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue