diff --git a/api/serializers.py b/api/serializers.py index 6419d9d2..4b0cd4af 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -64,23 +64,4 @@ class NamespacedHMSerializer(serializers.HyperlinkedModelSerializer): -class ReminderUsersSerializer(UserSerializer): - """Serialize the data about a mailing member. - """ - - class Meta(UserSerializer.Meta): - fields = ("get_full_name", "get_mail") - - -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") - diff --git a/api/urls.py b/api/urls.py index 50681770..624b838b 100644 --- a/api/urls.py +++ b/api/urls.py @@ -28,25 +28,24 @@ can be generated automatically. """ from django.conf.urls import url, include +from importlib import import_module from . import views from .routers import AllViewsRouter -from cotisations.api.urls import urls_viewset as urls_viewset_cotisations -from cotisations.api.urls import urls_view as urls_view_cotisations -from machines.api.urls import urls_viewset as urls_viewset_machines -from machines.api.urls import urls_view as urls_view_machines -from preferences.api.urls import urls_viewset as urls_viewset_preferences -from preferences.api.urls import urls_view as urls_view_preferences -from topologie.api.urls import urls_viewset as urls_viewset_topologie -from topologie.api.urls import urls_view as urls_view_topologie -from users.api.urls import urls_viewset as urls_viewset_users -from users.api.urls import urls_view as urls_view_users - -urls_viewset = urls_viewset_cotisations + urls_viewset_machines + urls_viewset_preferences + urls_viewset_topologie + urls_viewset_users -urls_view = urls_view_cotisations + urls_view_machines + urls_view_preferences + urls_view_topologie + urls_view_users +from django.conf import settings router = AllViewsRouter() +urls_viewset = [] +urls_view = [] + +for app in settings.INSTALLED_APPS: + try: + module = import_module(".api.urls", package=app) + urls_viewset += getattr(module, "urls_viewset", []) + urls_view += getattr(module, "urls_view", []) + except ImportError: + continue for _url, viewset, name in urls_viewset: if name == None: @@ -57,8 +56,7 @@ for _url, viewset, name in urls_viewset: for _url, view in urls_view: router.register_view(_url, view) -# Reminder -router.register_view(r"reminder/get-users", views.ReminderView), + # TOKEN AUTHENTICATION router.register_view(r"token-auth", views.ObtainExpiringAuthToken) diff --git a/api/views.py b/api/views.py index d17622fc..5ec0db1d 100644 --- a/api/views.py +++ b/api/views.py @@ -48,13 +48,6 @@ from .permissions import ACLPermission -class ReminderView(generics.ListAPIView): - """Output for users to remind an end of their subscription. - """ - - queryset = preferences.Reminder.objects.all() - serializer_class = serializers.ReminderSerializer - class ObtainExpiringAuthToken(ObtainAuthToken): """Exposes a view to obtain a authentication token. diff --git a/cotisations/api/serializers.py b/cotisations/api/serializers.py index 138f5b93..d33c9f7e 100644 --- a/cotisations/api/serializers.py +++ b/cotisations/api/serializers.py @@ -22,7 +22,9 @@ from rest_framework import serializers import cotisations.models as cotisations +import preferences.models as preferences from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer +from users.api.serializers import UserSerializer class FactureSerializer(NamespacedHMSerializer): @@ -103,3 +105,23 @@ class CotisationSerializer(NamespacedHMSerializer): class Meta: model = cotisations.Cotisation fields = ("vente", "type_cotisation", "date_start", "date_end", "api_url") + + +class ReminderUsersSerializer(UserSerializer): + """Serialize the data about a mailing member. + """ + + class Meta(UserSerializer.Meta): + fields = ("get_full_name", "get_mail") + + +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") \ No newline at end of file diff --git a/cotisations/api/urls.py b/cotisations/api/urls.py index 574c3cd2..33834b26 100644 --- a/cotisations/api/urls.py +++ b/cotisations/api/urls.py @@ -31,5 +31,8 @@ urls_viewset = [ ] urls_view = [ - # (r"reminder/get-users", views.ReminderView), + (r"cotisations/reminder-get-users", views.ReminderView), + + # Deprecated + (r"reminder/get-users", views.ReminderView), ] \ No newline at end of file diff --git a/cotisations/api/views.py b/cotisations/api/views.py index b7f5d13b..246c64a9 100644 --- a/cotisations/api/views.py +++ b/cotisations/api/views.py @@ -23,6 +23,7 @@ from rest_framework import viewsets, generics from . import serializers import cotisations.models as cotisations +import preferences.models as preferences class FactureViewSet(viewsets.ReadOnlyModelViewSet): """Exposes list and details of `cotisations.models.Facture` objects. @@ -78,3 +79,11 @@ class CotisationViewSet(viewsets.ReadOnlyModelViewSet): queryset = cotisations.Cotisation.objects.all() serializer_class = serializers.CotisationSerializer + + +class ReminderView(generics.ListAPIView): + """Output for users to remind an end of their subscription. + """ + + queryset = preferences.Reminder.objects.all() + serializer_class = serializers.ReminderSerializer \ No newline at end of file