From d2c497d90406f2958d6d0af8f873362752a4721e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Fri, 15 Sep 2017 00:27:12 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Les=20envois=20de=20mails=20pour=20le=20ser?= =?UTF-8?q?vice=20mailing=20sont=20s=C3=A9rializ=C3=A9=20et=20passe=20par?= =?UTF-8?q?=20all=5Fhas=5Faccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/serializers.py | 31 +++++++++++++++++++++++++++++++ users/views.py | 11 +++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 users/serializers.py diff --git a/users/serializers.py b/users/serializers.py new file mode 100644 index 00000000..8f4c050d --- /dev/null +++ b/users/serializers.py @@ -0,0 +1,31 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#Maël Kervella + +from rest_framework import serializers +from users.models import User + +class MailSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ('email',) diff --git a/users/views.py b/users/views.py index 0b760ad8..f454e11c 100644 --- a/users/views.py +++ b/users/views.py @@ -43,7 +43,8 @@ from rest_framework.renderers import JSONRenderer from reversion.models import Version from reversion import revisions as reversion -from users.models import User, Right, Ban, Whitelist, School, ListRight, Request, ServiceUser +from users.serializers import MailSerializer +from users.models import User, Right, Ban, Whitelist, School, ListRight, Request, ServiceUser, all_has_access from users.forms import DelRightForm, BanForm, WhitelistForm, DelSchoolForm, DelListRightForm, NewListRightForm from users.forms import EditInfoForm, InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm, EditServiceUserForm, ServiceUserForm, ListRightForm from cotisations.models import Facture @@ -704,9 +705,7 @@ class JSONResponse(HttpResponse): @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) + mails = all_has_access() + seria = MailSerializer(mails, many=True) + return JSONResponse(seria.data) From 90188a38b38f9a84e4fbe7a7fe5555cc3f7c6deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Fri, 15 Sep 2017 00:44:50 +0000 Subject: [PATCH 2/2] Evite les doublons dans la requete SQL --- users/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/views.py b/users/views.py index f454e11c..53fb2ee9 100644 --- a/users/views.py +++ b/users/views.py @@ -705,7 +705,7 @@ class JSONResponse(HttpResponse): @login_required @permission_required('serveur') def mailing(request): - mails = all_has_access() + mails = all_has_access().values('email').distinct() seria = MailSerializer(mails, many=True) return JSONResponse(seria.data)