From 98dc4205bef1265e16570e8e008b7653a9eaaa5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 21 Apr 2018 22:36:10 +0000 Subject: [PATCH] API support for app cotisations --- api/serializers.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++ api/urls.py | 8 +++++ api/views.py | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index e274f942..9acacce1 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -23,6 +23,15 @@ Serializers for the API app """ from rest_framework import serializers + +from cotisations.models import ( + Facture, + Vente, + Article, + Banque, + Paiement, + Cotisation +) from users.models import ( User, Club, @@ -49,6 +58,73 @@ from machines.models import ( Ipv6List ) +# COTISATION APP + +class FactureSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Facture + fields = ('user', 'paiement', 'banque', 'cheque', 'date', 'valid', + 'control', 'prix_total', 'name', 'api_url') + extra_kwargs = { + 'user': {'view_name': 'api:user-detail'}, + 'paiement': {'view_name': 'api:paiement-detail'}, + 'banque': {'view_name': 'api:banque-detail'}, + 'api_url': {'view_name': 'api:facture-detail'} + } + + +class VenteSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Vente + fields = ('facture', 'number', 'name', 'prix', 'duration', + 'type_cotisation', 'prix_total', 'api_url') + extra_kwargs = { + 'facture': {'view_name': 'api:facture-detail'}, + 'api_url': {'view_name': 'api:vente-detail'} + } + + +class ArticleSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Article + fields = ('name', 'prix', 'duration', 'type_user', + 'type_cotisation', 'api_url') + extra_kwargs = { + 'api_url': {'view_name': 'api:article-detail'} + } + + +class BanqueSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Banque + fields = ('name', 'api_url') + extra_kwargs = { + 'api_url': {'view_name': 'api:banque-detail'} + } + + +class PaiementSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Paiement + fields = ('moyen', 'type_paiement', 'api_url') + extra_kwargs = { + 'api_url': {'view_name': 'api:paiement-detail'} + } + + +class CotisationSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Cotisation + fields = ('vente', 'type_cotisation', 'date_start', 'date_end', + 'api_url') + extra_kwargs = { + 'vente': {'view_name': 'api:vente-detail'}, + 'api_url': {'view_name': 'api:cotisation-detail'} + } + + +# USER APP + class UserSerializer(serializers.HyperlinkedModelSerializer): access = serializers.BooleanField(source='has_access') diff --git a/api/urls.py b/api/urls.py index 3379d083..3281d326 100644 --- a/api/urls.py +++ b/api/urls.py @@ -30,6 +30,14 @@ from rest_framework.routers import DefaultRouter from . import views router = DefaultRouter() +# COTISATION APP +router.register(r'factures', views.FactureViewSet) +router.register(r'ventes', views.VenteViewSet) +router.register(r'articles', views.ArticleViewSet) +router.register(r'banques', views.BanqueViewSet) +router.register(r'paiements', views.PaiementViewSet) +router.register(r'cotisations', views.CotisationViewSet) +# USER APP router.register(r'users', views.UserViewSet) router.register(r'clubs', views.ClubViewSet) router.register(r'adherents', views.AdherentViewSet) diff --git a/api/views.py b/api/views.py index f3e2a6c7..29531fb8 100644 --- a/api/views.py +++ b/api/views.py @@ -33,6 +33,15 @@ from rest_framework.authtoken.models import Token from rest_framework.response import Response from rest_framework import viewsets, status + +from cotisations.models import ( + Facture, + Vente, + Article, + Banque, + Paiement, + Cotisation +) from users.models import ( User, Club, @@ -60,6 +69,14 @@ from machines.models import ( ) from .serializers import ( + # COTISATION APP + FactureSerializer, + VenteSerializer, + ArticleSerializer, + BanqueSerializer, + PaiementSerializer, + CotisationSerializer, + # USER APP UserSerializer, ClubSerializer, AdherentSerializer, @@ -72,6 +89,42 @@ from .serializers import ( ) +# COTISATION APP + + +class FactureViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Facture.objects.all() + serializer_class = FactureSerializer + + +class VenteViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Vente.objects.all() + serializer_class = VenteSerializer + + +class ArticleViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Article.objects.all() + serializer_class = ArticleSerializer + + +class BanqueViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Banque.objects.all() + serializer_class = BanqueSerializer + + +class PaiementViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Paiement.objects.all() + serializer_class = PaiementSerializer + + +class CotisationViewSet(viewsets.ReadOnlyModelViewSet): + queryset = Cotisation.objects.all() + serializer_class = CotisationSerializer + + +# USER APP + + class UserViewSet(viewsets.ReadOnlyModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer