8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

REST view pour obtenir les mails des adhérents ayant une connexion

This commit is contained in:
Maël Kervella 2017-09-10 18:44:09 +00:00 committed by Pierre Cadart
parent 0be751ab0f
commit dfc7cd4283
2 changed files with 25 additions and 0 deletions

View file

@ -61,6 +61,8 @@ urlpatterns = [
url(r'^history/(?P<object>listright)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>listright)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>serviceuser)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>serviceuser)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
url(r'^rest/mailing/$', views.mailing, name='mailing'),
] ]

View file

@ -35,6 +35,11 @@ from django.core.mail import send_mail
from django.utils import timezone from django.utils import timezone
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import transaction 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.models import Version
from reversion import revisions as reversion from reversion import revisions as reversion
@ -687,3 +692,21 @@ def process_passwd(request, req):
if u_form.is_valid(): if u_form.is_valid():
return password_change_action(u_form, user, request, req=req) return password_change_action(u_form, user, request, req=req)
return form({'userform': u_form}, 'users/user.html', request) 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)