mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-24 00:28:45 +02:00
Restart the project in Django
This commit is contained in:
1
apps/api/__init__.py
Normal file
1
apps/api/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
default_app_config = 'api.apps.APIConfig'
|
10
apps/api/apps.py
Normal file
10
apps/api/apps.py
Normal file
@ -0,0 +1,10 @@
|
||||
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')
|
15
apps/api/serializers.py
Normal file
15
apps/api/serializers.py
Normal file
@ -0,0 +1,15 @@
|
||||
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',
|
||||
)
|
18
apps/api/urls.py
Normal file
18
apps/api/urls.py
Normal file
@ -0,0 +1,18 @@
|
||||
from django.conf.urls import url, include
|
||||
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)
|
||||
|
||||
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')),
|
||||
]
|
17
apps/api/viewsets.py
Normal file
17
apps/api/viewsets.py
Normal file
@ -0,0 +1,17 @@
|
||||
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.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', ]
|
Reference in New Issue
Block a user