From 69a32753d0fa9e391e38fa0533dd6743909a6574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Sep 2017 18:44:09 +0000 Subject: [PATCH] =?UTF-8?q?REST=20view=20pour=20obtenir=20les=20mails=20de?= =?UTF-8?q?s=20adh=C3=A9rents=20ayant=20une=20connexion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/urls.py | 2 ++ users/views.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/users/urls.py b/users/urls.py index c869e226..033c7a4e 100644 --- a/users/urls.py +++ b/users/urls.py @@ -61,6 +61,8 @@ urlpatterns = [ url(r'^history/(?Plistright)/(?P[0-9]+)$', views.history, name='history'), url(r'^history/(?Pserviceuser)/(?P[0-9]+)$', views.history, name='history'), url(r'^$', views.index, name='index'), + url(r'^rest/mailing/$', views.mailing, name='mailing'), + ] diff --git a/users/views.py b/users/views.py index bd16ed00..0b760ad8 100644 --- a/users/views.py +++ b/users/views.py @@ -35,6 +35,11 @@ from django.core.mail import send_mail from django.utils import timezone from django.core.urlresolvers import reverse from django.db import transaction +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt + +from rest_framework.renderers import JSONRenderer + from reversion.models import Version from reversion import revisions as reversion @@ -687,3 +692,21 @@ def process_passwd(request, req): if u_form.is_valid(): return password_change_action(u_form, user, request, req=req) return form({'userform': u_form}, 'users/user.html', request) +""" Framework Rest """ + +class JSONResponse(HttpResponse): + def __init__(self, data, **kwargs): + content = JSONRenderer().render(data) + kwargs['content_type'] = 'application/json' + super(JSONResponse, self).__init__(content, **kwargs) + +@csrf_exempt +@login_required +@permission_required('serveur') +def mailing(request): + mails = set() + for u in User.objects.all() : + if u.has_access(): + mails.add( u.email ) + return JSONResponse(mails) +