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