1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 13:58:25 +02:00

Clone Corres2math platform

This commit is contained in:
Yohann D'ANELLO
2020-12-27 11:49:54 +01:00
parent 3d9bd88a41
commit 03eca29316
151 changed files with 10032 additions and 0 deletions

4
apps/api/__init__.py Normal file
View File

@ -0,0 +1,4 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
default_app_config = 'api.apps.APIConfig'

13
apps/api/apps.py Normal file
View File

@ -0,0 +1,13 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
class APIConfig(AppConfig):
"""
Manage the inscription through a JSON API.
"""
name = 'api'
verbose_name = _('API')

19
apps/api/serializers.py Normal file
View File

@ -0,0 +1,19 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.models import User
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
"""
Serialize a User object into JSON.
"""
class Meta:
model = User
exclude = (
'username',
'password',
'groups',
'user_permissions',
)

27
apps/api/tests.py Normal file
View File

@ -0,0 +1,27 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from unittest.case import skipIf
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
class TestAPIPages(TestCase):
def setUp(self):
self.user = User.objects.create_superuser(
username="admin",
password="apitest",
email="",
)
self.client.force_login(self.user)
def test_user_page(self):
response = self.client.get("/api/user/")
self.assertEqual(response.status_code, 200)
@skipIf("logs" not in settings.INSTALLED_APPS, reason="logs app is not used")
def test_logs_page(self):
response = self.client.get("/api/logs/")
self.assertEqual(response.status_code, 200)

26
apps/api/urls.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.conf import settings
from django.conf.urls import include, url
from rest_framework import routers
from .viewsets import UserViewSet
# Routers provide an easy way of automatically determining the URL conf.
# Register each app API router and user viewset
router = routers.DefaultRouter()
router.register('user', UserViewSet)
if "logs" in settings.INSTALLED_APPS:
from logs.api.urls import register_logs_urls
register_logs_urls(router, "logs")
app_name = 'api'
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
url('^', include(router.urls)),
url('^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

20
apps/api/viewsets.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.models import User
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
from rest_framework.viewsets import ModelViewSet
from .serializers import UserSerializer
class UserViewSet(ModelViewSet):
"""
Display list of users.
"""
queryset = User.objects.order_by("id").all()
serializer_class = UserSerializer
filter_backends = [DjangoFilterBackend, SearchFilter]
filterset_fields = ['id', 'first_name', 'last_name', 'email', 'is_superuser', 'is_staff', 'is_active', ]
search_fields = ['$first_name', '$last_name', ]