From 2ef8930ffed75a5d0c58245023a659f16ee7fb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Apr 2018 18:28:01 +0000 Subject: [PATCH] API support for app preferences --- api/serializers.py | 104 +++++++++++++++++++++++++++++++++++++++++++++ api/urls.py | 9 ++++ api/views.py | 84 +++++++++++++++++++++++++++++++----- 3 files changed, 186 insertions(+), 11 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index 90d00418..888891f0 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -53,6 +53,17 @@ from machines.models import ( OuverturePortList, OuverturePort ) +from preferences.models import ( + OptionalUser, + OptionalMachine, + OptionalTopologie, + GeneralOption, + AssoOption, + HomeOption, + MailMessageOption +) +# Avoid duplicate names +from preferences.models import Service as ServiceOption from users.models import ( User, Club, @@ -352,6 +363,99 @@ class OuverturePortSerializer(serializers.HyperlinkedModelSerializer): } +# PREFERENCES APP + + +# class OptionalUserSerializer(serializers.HyperlinkedModelSerializer): +# tel_mandatory = serializers.BooleanField(source='is_tel_mandatory') +# +# class Meta: +# model = OptionalUser +# fields = ('tel_mandatory', 'user_solde', 'solde_negatif', 'max_solde', +# 'min_online_payement', 'gpg_fingerprint', +# 'all_can_create_club', 'self_adhesion', 'shell_default', +# 'api_url') +# extra_kwargs = { +# 'shell_default': {'view_name': 'api:shell-detail'}, +# 'api_url': {'view_name': 'api:optionaluser-detail'} +# } +# +# +# class OptionalMachineSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = OptionalMachine +# fields = ('password_machine', 'max_lambdauser_interfaces', +# 'max_lambdauser_aliases', 'ipv6_mode', 'create_machine', +# 'ipv6', 'api_url') +# extra_kwargs = { +# 'api_url': {'view_name': 'api:optionalmachine-detail'} +# } +# +# +# class OptionalTopologieSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = OptionalTopologie +# fields = ('radius_general_policy', 'vlan_decision_ok', +# 'vlan_decision_no', 'api_url') +# extra_kwargs = { +# 'vlan_decision_ok': {'view_name': 'api:vlan-detail'}, +# 'vlan_decision_nok': {'view_name': 'api:vlan-detail'}, +# 'api_url': {'view_name': 'api:optionaltopologie-detail'} +# } +# +# +# class GeneralOptionSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = GeneralOption +# fields = ('general_message', 'search_display_page', +# 'pagination_number', 'pagination_large_number', +# 'req_expire_hrs', 'site_name', 'email_from', 'GTU_sum_up', +# 'GTU', 'api_url') +# extra_kwargs = { +# 'api_url': {'view_name': 'api:generaloption-detail'} +# } +# +# +# class ServiceOptionSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = ServiceOption +# fields = ('name', 'url', 'description', 'image', 'api_url') +# extra_kwargs = { +# 'api_url': {'view_name': 'api:serviceoption-detail'} +# } +# +# +# class AssoOptionSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = AssoOption +# fields = ('name', 'siret', 'adresse1', 'adresse2', 'contact', +# 'telephone', 'pseudo', 'utilisateur_asso', 'payement', +# 'payement_id', 'payement_pass', 'description', 'api_url') +# extra_kwargs = { +# 'utilisateur_asso': {'view_name': 'api:user-detail'}, +# 'api_url': {'view_name': 'api:assooption-detail'} +# } +# +# +# class HomeOptionSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = HomeOption +# fields = ('facebook_url', 'twitter_url', 'twitter_account_name', +# 'api_url') +# extra_kwargs = { +# 'api_url': {'view_name': 'api:homeoption-detail'} +# } +# +# +# class MailMessageOptionSerializer(serializers.HyperlinkedModelSerializer): +# class Meta: +# model = MailMessageOption +# fields = ('welcome_mail_fr', 'welcome_mail_en', 'api_url') +# extra_kwargs = { +# 'api_url': {'view_name': 'api:mailmessageoption-detail'} +# } + + # USERS APP diff --git a/api/urls.py b/api/urls.py index a712cacd..c2ba0c2a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -57,6 +57,15 @@ router.register(r'services', views.ServiceViewSet) router.register(r'servicelinks', views.ServiceLinkViewSet, 'servicelink') router.register(r'ouvertureportlists', views.OuverturePortListViewSet) router.register(r'ouvertureports', views.OuverturePortViewSet) +# PREFERENCES APP +#router.register(r'optionaluser', views.OptionalUserSerializer) +#router.register(r'optionalmachine', views.OptionalMachineSerializer) +#router.register(r'optionaltopologie', views.OptionalTopologieSerializer) +#router.register(r'generaloption', views.GeneralOptionSerializer) +#router.register(r'serviceoption', views.ServiceOptionSerializer) +#router.register(r'assooption', views.AssoOptionSerializer) +#router.register(r'homeoption', views.HomeOptionSerializer) +#router.register(r'mailmessageoption', views.MailMessageOptionSerializer) # USERS APP router.register(r'users', views.UserViewSet) router.register(r'clubs', views.ClubViewSet) diff --git a/api/views.py b/api/views.py index db119ce3..f970745c 100644 --- a/api/views.py +++ b/api/views.py @@ -42,17 +42,6 @@ from cotisations.models import ( Paiement, Cotisation ) -from users.models import ( - User, - Club, - Adherent, - ServiceUser, - School, - ListRight, - ListShell, - Ban, - Whitelist -) from machines.models import ( Machine, MachineType, @@ -74,6 +63,28 @@ from machines.models import ( OuverturePortList, OuverturePort ) +# from preferences.models import ( +# OptionalUser, +# OptionalMachine, +# OptionalTopologie, +# GeneralOption, +# AssoOption, +# HomeOption, +# MailMessageOption +# ) +# # Avoid duplicate names +# from preferences.models import Service as ServiceOption +from users.models import ( + User, + Club, + Adherent, + ServiceUser, + School, + ListRight, + ListShell, + Ban, + Whitelist +) from .serializers import ( # COTISATIONS APP @@ -103,6 +114,15 @@ from .serializers import ( ServiceLinkSerializer, OuverturePortListSerializer, OuverturePortSerializer, + # PREFERENCES APP + # OptionalUserSerializer, + # OptionalMachineSerializer, + # OptionalTopologieSerializer, + # GeneralOptionSerializer, + # ServiceOptionSerializer, + # AssoOptionSerializer, + # HomeOptionSerializer, + # MailMessageOptionSerializer, # USERS APP UserSerializer, ClubSerializer, @@ -247,6 +267,48 @@ class OuverturePortViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = OuverturePortSerializer +# PREFERENCES APP + +# class OptionalUserViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = OptionalUser.objects.all() +# serializer_class = OptionalUserSerializer +# +# +# class OptionalMachineViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = OptionalMachine.objects.all() +# serializer_class = OptionalMachineSerializer +# +# +# class OptionalTopologieViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = OptionalTopologie.objects.all() +# serializer_class = OptionalTopologieSerializer +# +# +# class GeneralOptionViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = GeneralOption.objects.all() +# serializer_class = GeneralOptionSerializer +# +# +# class ServiceOptionViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = ServiceOption.objects.all() +# serializer_class = ServiceOptionSerializer +# +# +# class AssoOptionViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = AssoOption.objects.all() +# serializer_class = AssoOptionSerializer +# +# +# class HomeOptionViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = HomeOption.objects.all() +# serializer_class = HomeOptionSerializer +# +# +# class MailMessageOptionViewSet(viewsets.ReadOnlyModelViewSet): +# queryset = MailMessageOption.objects.all() +# serializer_class = MailMessageOptionSerializer + + # USER APP