mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 15:22:26 +01:00 
			
		
		
		
	Add API views for participation app
This commit is contained in:
		@@ -16,6 +16,10 @@ if "logs" in settings.INSTALLED_APPS:
 | 
				
			|||||||
    from logs.api.urls import register_logs_urls
 | 
					    from logs.api.urls import register_logs_urls
 | 
				
			||||||
    register_logs_urls(router, "logs")
 | 
					    register_logs_urls(router, "logs")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if "participation" in settings.INSTALLED_APPS:
 | 
				
			||||||
 | 
					    from participation.api.urls import register_participation_urls
 | 
				
			||||||
 | 
					    register_participation_urls(router, "participation")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app_name = 'api'
 | 
					app_name = 'api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Wire up our API using automatic URL routing.
 | 
					# Wire up our API using automatic URL routing.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								apps/participation/api/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								apps/participation/api/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
							
								
								
									
										56
									
								
								apps/participation/api/serializers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								apps/participation/api/serializers.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					# Copyright (C) 2020 by Animath
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from rest_framework import serializers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from ..models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NoteSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Note
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ParticipationSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Participation
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PassageSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Passage
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PoolSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Pool
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SolutionSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Solution
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SynthesisSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Synthesis
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TeamSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Team
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TournamentSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
					    teams = serializers.ListSerializer()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = Tournament
 | 
				
			||||||
 | 
					        fields = '__all__'
 | 
				
			||||||
							
								
								
									
										19
									
								
								apps/participation/api/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								apps/participation/api/urls.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					# Copyright (C) 2020 by Animath
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .views import NoteViewSet, ParticipationViewSet, PassageViewSet, PoolViewSet, \
 | 
				
			||||||
 | 
					    SolutionViewSet, SynthesisViewSet, TeamViewSet, TournamentViewSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def register_participation_urls(router, path):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Configure router for participation REST API.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    router.register(path + "/note", NoteViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/participation", ParticipationViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/passage", PassageViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/pool", PoolViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/solution", SolutionViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/synthesis", SynthesisViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/team", TeamViewSet)
 | 
				
			||||||
 | 
					    router.register(path + "/tournament", TournamentViewSet)
 | 
				
			||||||
							
								
								
									
										48
									
								
								apps/participation/api/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								apps/participation/api/views.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					# Copyright (C) 2020 by Animath
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from rest_framework.viewsets import ModelViewSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .serializers import NoteSerializer, ParticipationSerializer, PassageSerializer, PoolSerializer, \
 | 
				
			||||||
 | 
					    SolutionSerializer, SynthesisSerializer, TeamSerializer, TournamentSerializer
 | 
				
			||||||
 | 
					from ..models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NoteViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Note.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = NoteSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ParticipationViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Participation.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = ParticipationSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PassageViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Passage.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = PassageSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PoolViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Pool.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = PoolSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SolutionViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Solution.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = SolutionSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SynthesisViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Synthesis.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = SynthesisSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TeamViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Team.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = TeamSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TournamentViewSet(ModelViewSet):
 | 
				
			||||||
 | 
					    queryset = Tournament.objects.all()
 | 
				
			||||||
 | 
					    serializer_class = TournamentSerializer
 | 
				
			||||||
		Reference in New Issue
	
	Block a user