parent
cc02b4126b
commit
b346ed954a
2 changed files with 19 additions and 7 deletions
|
@ -1,16 +1,21 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block header %}
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
|
||||
{% endblock header %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-lg-8 mb-3">
|
||||
<h3>Datenexport</h3>
|
||||
<h3>Datenexport <i class="fa-solid fa-file-csv"></i></h3>
|
||||
<p>
|
||||
Anbei finden Sie mehrere Möglichkeiten die Daten der Anwendung zu
|
||||
exportieren.
|
||||
</p>
|
||||
<ul>
|
||||
<li><a href="{% url 'export_birds' %}">alle Patienten</a></li>
|
||||
<li><a href="{% url 'export_costs' %}">alle Kosten</a></li>
|
||||
<li>alle Patienten: <a href="{% url 'export_birds' %}"><i class="fa-solid fa-file-export"></i></a></li>
|
||||
<li>alle Kosten: <a href="{% url 'export_costs' %}"><i class="fa-solid fa-file-export"></i></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import csv
|
||||
from datetime import date
|
||||
|
||||
from bird.models import FallenBird
|
||||
from costs.models import Costs
|
||||
|
@ -7,6 +8,9 @@ from django.http import HttpResponse
|
|||
from django.shortcuts import render
|
||||
|
||||
|
||||
today = date.today().strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
@login_required(login_url="account_login")
|
||||
def site_exports(request):
|
||||
return render(request, "export/overview.html")
|
||||
|
@ -15,10 +19,13 @@ def site_exports(request):
|
|||
@login_required(login_url="account_login")
|
||||
def export_costs(request):
|
||||
costs = Costs.objects.all().values_list(
|
||||
"id_bird__bird_identifier", "costs", "created", "comment", "user__username"
|
||||
)
|
||||
"id_bird__bird_identifier",
|
||||
"costs",
|
||||
"created",
|
||||
"comment",
|
||||
"user__username")
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = "attachment, filename=fbf_costs.csv"
|
||||
response["Content-Disposition"] = f"attachment, filename=fbf_costs_{today}.csv"
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(
|
||||
["Vogel", "Betrag in Euro", "Gebucht am", "Kommentar", "Gebucht von"]
|
||||
|
@ -48,7 +55,7 @@ def export_birds(request):
|
|||
"sent_to",
|
||||
)
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = "attachment, filename=fbf_birds.csv"
|
||||
response["Content-Disposition"] = f"attachment, filename=fbf_birds_{today}.csv"
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue