60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
import csv
|
|
|
|
from django.contrib.auth.decorators import permission_required
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
|
from django.http import HttpResponse
|
|
from django.views.generic import TemplateView
|
|
|
|
from bds.models import BDSProfile
|
|
|
|
|
|
class HomeView(PermissionRequiredMixin, TemplateView):
|
|
permission_required = "bds:is_team"
|
|
template_name = "bds/home.html"
|
|
|
|
|
|
home = HomeView.as_view()
|
|
|
|
|
|
@permission_required("bds:is_staff")
|
|
def members_emails(request):
|
|
members = BDSProfile.objects.filter(is_member=True)
|
|
response = HttpResponse(content_type="text/plain")
|
|
response.write(", ".join(members.values_list("user__email", flat=True)))
|
|
return response
|
|
|
|
|
|
@permission_required("bds:is_staff")
|
|
def members_csv(request):
|
|
response = HttpResponse(content_type="text/csv")
|
|
response["Content-Disposition"] = 'attachment; filename="members.csv"'
|
|
writer = csv.writer(response)
|
|
|
|
header = [
|
|
"nom",
|
|
"email",
|
|
"numéro de téléphone",
|
|
"occupation",
|
|
"département",
|
|
"date de naissance",
|
|
"Numéro ASPSL",
|
|
"Période de cotisation",
|
|
"Type de cotisation",
|
|
]
|
|
writer.writerow(header)
|
|
|
|
for profile in BDSProfile.objects.filter(is_member=True):
|
|
data = [
|
|
profile.user.get_full_name(),
|
|
profile.user.email,
|
|
profile.phone,
|
|
profile.occupation,
|
|
profile.departement,
|
|
profile.birthdate,
|
|
profile.ASPSL_number,
|
|
profile.cotisation_period,
|
|
profile.cotisation_type,
|
|
]
|
|
writer.writerow(map(lambda x: str(x) if x else "", data))
|
|
|
|
return response
|