From 57d6a12aa43bdb3ff7efb361e71d737204d787ad Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Tue, 3 Jul 2018 18:34:10 +0200 Subject: [PATCH] serialization des rappel de fin de connexion --- api/serializers.py | 20 ++++++++++++++++++++ api/urls.py | 2 ++ api/views.py | 9 +++++++++ preferences/models.py | 11 +++++++++++ 4 files changed, 42 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index 09bfb3a4..55db9263 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -804,6 +804,26 @@ class DNSZonesSerializer(serializers.ModelSerializer): 'mx_records', 'txt_records', 'srv_records', 'a_records', 'aaaa_records', 'cname_records') +#REMINDER + + +class ReminderUsersSerializer(UserSerializer): + """Serialize the data about a mailing member. + """ + class Meta(UserSerializer.Meta): + fields = ('get_full_name', 'email') + + +class ReminderSerializer(serializers.ModelSerializer): + """ + Serialize the data about a reminder + """ + users_to_remind = ReminderUsersSerializer(many=True) + + class Meta: + model = preferences.Reminder + fields = ('days','message','users_to_remind') + # MAILING diff --git a/api/urls.py b/api/urls.py index b47a1a96..a707ab57 100644 --- a/api/urls.py +++ b/api/urls.py @@ -100,6 +100,8 @@ router.register_viewset(r'services/regen', views.ServiceRegenViewSet, base_name= router.register_view(r'dhcp/hostmacip', views.HostMacIpView), # Switches config router.register_view(r'switchs/ports-config', views.SwitchPortView), +# Reminder +router.register_view(r'reminder/get-users', views.ReminderView), # DNS router.register_view(r'dns/zones', views.DNSZonesView), # MAILING diff --git a/api/views.py b/api/views.py index ad32c561..ea384ad9 100644 --- a/api/views.py +++ b/api/views.py @@ -504,6 +504,15 @@ class SwitchPortView(generics.ListAPIView): queryset = topologie.Switch.objects.all().prefetch_related('ports__custom_profile') serializer_class = serializers.SwitchPortSerializer +# Rappel fin adhésion + +class ReminderView(generics.ListAPIView): + """Exposes the associations between hostname, mac address and IPv4 in + order to build the DHCP lease files. + """ + queryset = preferences.Reminder.objects.all() + serializer_class = serializers.ReminderSerializer + # DHCP diff --git a/preferences/models.py b/preferences/models.py index 9057412c..01abbc0d 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -26,6 +26,7 @@ Reglages généraux, machines, utilisateurs, mail, general pour l'application. from __future__ import unicode_literals from django.utils.functional import cached_property +from django.utils import timezone from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver @@ -36,8 +37,11 @@ import cotisations.models import machines.models from re2o.mixins import AclMixin + from .aes_field import AESEncryptedField +from datetime import timedelta + class PreferencesModel(models.Model): """ Base object for the Preferences objects @@ -283,6 +287,13 @@ class Reminder(AclMixin, models.Model): ("view_reminder", "Peut voir un objet reminder"), ) + def users_to_remind(self): + from re2o.utils import all_has_access + date = timezone.now().replace(minute=0,hour=0) + futur_date = date + timedelta(days=self.days) + users = all_has_access(futur_date).exclude(pk__in = all_has_access(futur_date + timedelta(days=1))) + return users + class GeneralOption(AclMixin, PreferencesModel): """Options générales : nombre de resultats par page, nom du site,