8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Add endpoints for mailing

This commit is contained in:
Maël Kervella 2018-06-10 15:12:42 +00:00 committed by Maël Kervella
parent 761fad578a
commit 0356947e4a
3 changed files with 40 additions and 2 deletions

View file

@ -577,3 +577,18 @@ class DNSZonesSerializer(serializers.ModelSerializer):
fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6', fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6',
'mx_records', 'txt_records', 'srv_records', 'a_records', 'mx_records', 'txt_records', 'srv_records', 'a_records',
'aaaa_records', 'cname_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')

View file

@ -94,5 +94,7 @@ urlpatterns = [
url(r'^', include(router.urls)), url(r'^', include(router.urls)),
url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()), url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()),
url(r'^dns/zones', views.DNSZonesView.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()) url(r'^token-auth', views.ObtainExpiringAuthToken.as_view())
] ]

View file

@ -31,7 +31,7 @@ from django.conf import settings
from rest_framework.authtoken.views import ObtainAuthToken from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.response import Response 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 cotisations.models as cotisations
import machines.models as machines import machines.models as machines
@ -39,9 +39,10 @@ import preferences.models as preferences
import topologie.models as topologie import topologie.models as topologie
import users.models as users 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 . import serializers
from .pagination import PageSizedPagination
# COTISATIONS APP # COTISATIONS APP
@ -345,6 +346,26 @@ class DNSZonesView(generics.ListAPIView):
serializer_class = serializers.DNSZonesSerializer 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 # Subclass the standard rest_framework.auth_token.views.ObtainAuthToken
# in order to renew the lease of the token and add expiration time # in order to renew the lease of the token and add expiration time
class ObtainExpiringAuthToken(ObtainAuthToken): class ObtainExpiringAuthToken(ObtainAuthToken):