Export overview

This commit is contained in:
gw3000 2023-08-09 21:30:13 +02:00
parent caa16cc260
commit 0fcec94275
3 changed files with 26 additions and 28 deletions

View file

@ -73,6 +73,7 @@ INSTALLED_APPS = [
"aviary", "aviary",
"bird", "bird",
"costs", "costs",
"export",
"rescuer", "rescuer",
"sites", "sites",
] ]

View file

@ -1,7 +1,7 @@
import csv import csv
from costs.models import Costs
from bird.models import FallenBird from bird.models import FallenBird
from costs.models import Costs
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
@ -9,20 +9,14 @@ from django.shortcuts import render
@login_required(login_url="account_login") @login_required(login_url="account_login")
def site_exports(request): def site_exports(request):
return render( return render(request, "export/overview.html")
request,
"export/export_site.html",
)
@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", "id_bird__bird_identifier", "costs", "created", "comment", "user__username"
"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"] = "attachment, filename=fbf_costs.csv"
writer = csv.writer(response) writer = csv.writer(response)
@ -51,12 +45,14 @@ def export_birds(request):
"user__username", "user__username",
"status__description", "status__description",
"aviary__description", "aviary__description",
"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"] = "attachment, filename=fbf_birds.csv"
writer = csv.writer(response) writer = csv.writer(response)
writer.writerow(["Vogel", writer.writerow(
[
"Vogel",
"Patienten Alias", "Patienten Alias",
"Alter", "Alter",
"Geschlecht", "Geschlecht",
@ -70,8 +66,9 @@ def export_birds(request):
"Benutzer", "Benutzer",
"Status", "Status",
"Voliere", "Voliere",
"Übersandt" "Übersandt",
]) ]
)
for bird in birds: for bird in birds:
writer.writerow(bird) writer.writerow(bird)
return response return response