8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-04 17:06:27 +00:00

Clear api generation

This commit is contained in:
chapeau 2020-04-21 12:00:52 +00:00 committed by Gabriel Detraz
parent bdfd15b853
commit 035f447fdd
6 changed files with 48 additions and 42 deletions

View file

@ -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")

View file

@ -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)

View file

@ -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.

View file

@ -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")

View file

@ -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),
]

View file

@ -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