diff --git a/cotisations/models.py b/cotisations/models.py index bcb0c744..a68d1c6f 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -195,8 +195,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 430b1f47..fbe37494 100644 --- a/users/models.py +++ b/users/models.py @@ -496,11 +496,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' @@ -675,6 +677,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') @@ -687,6 +690,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') @@ -707,6 +711,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') @@ -718,6 +723,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') diff --git a/users/urls.py b/users/urls.py index 397ce263..43054fe5 100644 --- a/users/urls.py +++ b/users/urls.py @@ -63,6 +63,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 5315c9bc..3a3a9911 100644 --- a/users/views.py +++ b/users/views.py @@ -38,6 +38,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 @@ -690,3 +695,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) +