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 1/2] =?UTF-8?q?REST=20view=20pour=20obtenir=20les=20mails?= =?UTF-8?q?=20des=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) + From 483466e2d0e919cc0ef3846094e04da7f3eec7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Thu, 14 Sep 2017 18:03:28 +0000 Subject: [PATCH 2/2] Ajout de regen pour le service mailing --- cotisations/models.py | 2 ++ users/models.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/cotisations/models.py b/cotisations/models.py index 9778a2d1..71cad990 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -193,8 +193,10 @@ def cotisation_post_save(sender, **kwargs): regen('dns') regen('dhcp') regen('mac_ip_list') + regen('mailing') @receiver(post_delete, sender=Cotisation) def vente_post_delete(sender, **kwargs): cotisation = kwargs['instance'] regen('mac_ip_list') + regen('mailing') diff --git a/users/models.py b/users/models.py index 4107c3d0..38298863 100644 --- a/users/models.py +++ b/users/models.py @@ -463,11 +463,13 @@ def user_post_save(sender, **kwargs): if is_created: user.notif_inscription() user.ldap_sync(base=True, access_refresh=True, mac_refresh=False) + regen('mailing') @receiver(post_delete, sender=User) def user_post_delete(sender, **kwargs): user = kwargs['instance'] user.ldap_del() + regen('mailing') class ServiceUser(AbstractBaseUser): readonly = 'readonly' @@ -642,6 +644,7 @@ def ban_post_save(sender, **kwargs): is_created = kwargs['created'] user = ban.user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + regen('mailing') if is_created: ban.notif_ban() regen('dhcp') @@ -654,6 +657,7 @@ def ban_post_save(sender, **kwargs): def ban_post_delete(sender, **kwargs): user = kwargs['instance'].user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + regen('mailing') regen('dhcp') regen('mac_ip_list') @@ -674,6 +678,7 @@ def whitelist_post_save(sender, **kwargs): user = whitelist.user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) is_created = kwargs['created'] + regen('mailing') if is_created: regen('dhcp') regen('mac_ip_list') @@ -685,6 +690,7 @@ def whitelist_post_save(sender, **kwargs): def whitelist_post_delete(sender, **kwargs): user = kwargs['instance'].user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + regen('mailing') regen('dhcp') regen('mac_ip_list')