Commit 0356947e authored by Maël Kervella's avatar Maël Kervella Committed by Maël Kervella

Add endpoints for mailing

parent 761fad57
......@@ -577,3 +577,18 @@ class DNSZonesSerializer(serializers.ModelSerializer):
fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6',
'mx_records', 'txt_records', 'srv_records', 'a_records',
'aaaa_records', 'cname_records')
# Mailing
class MailingMemberSerializer(UserSerializer):
class Meta(UserSerializer.Meta):
fields = ('name', 'pseudo', 'email')
class MailingSerializer(ClubSerializer):
members = MailingMemberSerializer(many=True)
admins = MailingMemberSerializer(source='administrators', many=True)
class Meta(ClubSerializer.Meta):
fields = ('name', 'members', 'admins')
......@@ -94,5 +94,7 @@ urlpatterns = [
url(r'^', include(router.urls)),
url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()),
url(r'^dns/zones', views.DNSZonesView.as_view()),
url(r'^mailing/standard', views.StandardMailingView.as_view()),
url(r'^mailing/club', views.ClubMailingView.as_view()),
url(r'^token-auth', views.ObtainExpiringAuthToken.as_view())
......@@ -31,7 +31,7 @@ from django.conf import settings
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import viewsets, generics
from rest_framework import viewsets, generics, views
import cotisations.models as cotisations
import machines.models as machines
......@@ -39,9 +39,10 @@ import preferences.models as preferences
import topologie.models as topologie
import users.models as users
from re2o.utils import all_active_interfaces
from re2o.utils import all_active_interfaces, all_has_access
from . import serializers
from .pagination import PageSizedPagination
......@@ -345,6 +346,26 @@ class DNSZonesView(generics.ListAPIView):
serializer_class = serializers.DNSZonesSerializer
# Mailing views
class StandardMailingView(views.APIView):
pagination_class = PageSizedPagination
get_queryset = lambda self: all_has_access()
def get(self, request, format=None):
adherents_data = serializers.MailingMemberSerializer(self.get_queryset(), many=True).data
data = [{'name': 'adherents', 'members': adherents_data}]
paginator = self.pagination_class()
paginator.paginate_queryset(data, request)
return paginator.get_paginated_response(data)
class ClubMailingView(generics.ListAPIView):
queryset = users.Club.objects.all()
serializer_class = serializers.MailingSerializer
# Subclass the standard rest_framework.auth_token.views.ObtainAuthToken
# in order to renew the lease of the token and add expiration time
class ObtainExpiringAuthToken(ObtainAuthToken):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment