mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Merge branch 'moamoak/mailing_API' into 'master'
Improve the API for multiple mailings See merge request federez/re2o!94
This commit is contained in:
commit
ab79b2c919
7 changed files with 130 additions and 10 deletions
|
@ -343,6 +343,7 @@ class ClubForm(FieldPermissionFormMixin, ModelForm):
|
||||||
self.fields['room'].label = 'Local'
|
self.fields['room'].label = 'Local'
|
||||||
self.fields['room'].empty_label = "Pas de chambre"
|
self.fields['room'].empty_label = "Pas de chambre"
|
||||||
self.fields['school'].empty_label = "Séléctionner un établissement"
|
self.fields['school'].empty_label = "Séléctionner un établissement"
|
||||||
|
self.fields['mailing'].label = 'Utiliser une mailing'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Club
|
model = Club
|
||||||
|
@ -355,6 +356,7 @@ class ClubForm(FieldPermissionFormMixin, ModelForm):
|
||||||
'room',
|
'room',
|
||||||
'telephone',
|
'telephone',
|
||||||
'shell',
|
'shell',
|
||||||
|
'mailing'
|
||||||
]
|
]
|
||||||
|
|
||||||
def clean_telephone(self):
|
def clean_telephone(self):
|
||||||
|
|
20
users/migrations/0069_club_mailing.py
Normal file
20
users/migrations/0069_club_mailing.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-03-07 15:34
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0068_auto_20180107_2245'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='club',
|
||||||
|
name='mailing',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -850,6 +850,9 @@ class Club(User):
|
||||||
to='users.Adherent',
|
to='users.Adherent',
|
||||||
related_name='club_members'
|
related_name='club_members'
|
||||||
)
|
)
|
||||||
|
mailing = models.BooleanField(
|
||||||
|
default = False
|
||||||
|
)
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
def can_create(user_request, *args, **kwargs):
|
||||||
"""Check if an user can create an user object.
|
"""Check if an user can create an user object.
|
||||||
|
|
|
@ -23,9 +23,16 @@
|
||||||
#Maël Kervella
|
#Maël Kervella
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from users.models import User
|
from users.models import Club, Adherent
|
||||||
|
|
||||||
|
class MailingSerializer(serializers.ModelSerializer):
|
||||||
|
name = serializers.CharField(source='pseudo')
|
||||||
|
|
||||||
class MailSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = Club
|
||||||
|
fields = ('name',)
|
||||||
|
|
||||||
|
class MailingMemberSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Adherent
|
||||||
fields = ('email',)
|
fields = ('email',)
|
||||||
|
|
|
@ -60,8 +60,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</p>
|
</p>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<tr>
|
<tr>
|
||||||
|
{% if users.is_class_club %}
|
||||||
|
<th>Mailing</th>
|
||||||
|
{% if users.club.mailing %}
|
||||||
|
<td>{{ users.pseudo }}(-admin)</td>
|
||||||
|
{% else %}
|
||||||
|
<td>Mailing désactivée</td>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
<th>Prénom</th>
|
<th>Prénom</th>
|
||||||
<td>{{ users.name }}</td>
|
<td>{{ users.name }}</td>
|
||||||
|
{% endif %}
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<td>{{ users.surname }}</td>
|
<td>{{ users.surname }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -102,5 +102,29 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
url(r'^index_clubs/$', views.index_clubs, name='index-clubs'),
|
url(r'^index_clubs/$', views.index_clubs, name='index-clubs'),
|
||||||
url(r'^rest/mailing/$', views.mailing, name='mailing'),
|
url(
|
||||||
|
r'^rest/ml/std/$',
|
||||||
|
views.ml_std_list,
|
||||||
|
name='ml-std-list'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r'^rest/ml/std/member/(?P<ml_name>\w+)/$',
|
||||||
|
views.ml_std_members,
|
||||||
|
name='ml-std-members'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r'^rest/ml/club/$',
|
||||||
|
views.ml_club_list,
|
||||||
|
name='ml-club-list'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r'^rest/ml/club/admin/(?P<ml_name>\w+)/$',
|
||||||
|
views.ml_club_admins,
|
||||||
|
name='ml-club-admins'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r'^rest/ml/club/member/(?P<ml_name>\w+)/$',
|
||||||
|
views.ml_club_members,
|
||||||
|
name='ml-club-members'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -52,7 +52,7 @@ 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
|
||||||
from users.serializers import MailSerializer
|
from users.serializers import MailingSerializer, MailingMemberSerializer
|
||||||
from users.models import (
|
from users.models import (
|
||||||
User,
|
User,
|
||||||
Ban,
|
Ban,
|
||||||
|
@ -843,9 +843,64 @@ class JSONResponse(HttpResponse):
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('machines.serveur')
|
@permission_required('machines.serveur')
|
||||||
def mailing(request):
|
def ml_std_list(request):
|
||||||
""" Fonction de serialisation des addresses mail de tous les users
|
""" API view sending all the available standard mailings"""
|
||||||
Pour generation de ml all users"""
|
return JSONResponse([
|
||||||
mails = all_has_access().values('email').distinct()
|
{'name': 'adherents'}
|
||||||
seria = MailSerializer(mails, many=True)
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('machines.serveur')
|
||||||
|
def ml_std_members(request, ml_name):
|
||||||
|
""" API view sending all the members for a standard mailing"""
|
||||||
|
# All with active connextion
|
||||||
|
if ml_name == 'adherents':
|
||||||
|
members = all_has_access().values('email').distinct()
|
||||||
|
# Unknown mailing
|
||||||
|
else:
|
||||||
|
messages.error(request, "Cette mailing n'existe pas")
|
||||||
|
return redirect(reverse('index'))
|
||||||
|
seria = MailingMemberSerializer(members, many=True)
|
||||||
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('machines.serveur')
|
||||||
|
def ml_club_list(request):
|
||||||
|
""" API view sending all the available club mailings"""
|
||||||
|
clubs = Club.objects.filter(mailing=True).values('pseudo')
|
||||||
|
seria = MailingSerializer(clubs, many=True)
|
||||||
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('machines.serveur')
|
||||||
|
def ml_club_admins(request, ml_name):
|
||||||
|
""" API view sending all the administrators for a specific club mailing"""
|
||||||
|
try:
|
||||||
|
club = Club.objects.get(mailing=True, pseudo=ml_name)
|
||||||
|
except Club.DoesNotExist:
|
||||||
|
messages.error(request, "Cette mailing n'existe pas")
|
||||||
|
return redirect(reverse('index'))
|
||||||
|
members = club.administrators.all().values('email').distinct()
|
||||||
|
seria = MailingMemberSerializer(members, many=True)
|
||||||
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('machines.serveur')
|
||||||
|
def ml_club_members(request, ml_name):
|
||||||
|
""" API view sending all the members for a specific club mailing"""
|
||||||
|
try:
|
||||||
|
club = Club.objects.get(mailing=True, pseudo=ml_name)
|
||||||
|
except Club.DoesNotExist:
|
||||||
|
messages.error(request, "Cette mailing n'existe pas")
|
||||||
|
return redirect(reverse('index'))
|
||||||
|
members = club.administrators.all().values('email').distinct() | club.members.all().values('email').distinct()
|
||||||
|
seria = MailingMemberSerializer(members, many=True)
|
||||||
return JSONResponse(seria.data)
|
return JSONResponse(seria.data)
|
||||||
|
|
Loading…
Reference in a new issue