BDS: members email export

This commit is contained in:
Martin Pépin 2020-05-08 23:16:48 +02:00
parent 3b98f35773
commit e025ae2d96
3 changed files with 18 additions and 2 deletions

View file

@ -8,7 +8,7 @@
<ul> <ul>
<li><a href="#todo">Chercher une personne</a></li> <li><a href="#todo">Chercher une personne</a></li>
<li><a href="#todo">Exporter une liste des membres</a></li> <li><a href="{% url 'bds:members_emails' %}">Emails des adhérent⋅e⋅s</a></li>
</ul> </ul>
</article> </article>
</section> </section>

View file

@ -3,4 +3,8 @@ from django.urls import path
from bds import views from bds import views
app_name = "bds" app_name = "bds"
urlpatterns = [path("", views.home, name="home")]
urlpatterns = [
path("", views.home, name="home"),
path("members/emails", views.members_emails, name="members_emails"),
]

View file

@ -1,6 +1,10 @@
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.http import HttpResponse
from django.views.generic import TemplateView from django.views.generic import TemplateView
from bds.models import BDSProfile
class HomeView(PermissionRequiredMixin, TemplateView): class HomeView(PermissionRequiredMixin, TemplateView):
permission_required = "bds:is_team" permission_required = "bds:is_team"
@ -8,3 +12,11 @@ class HomeView(PermissionRequiredMixin, TemplateView):
home = HomeView.as_view() 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