Browse Source

Move API related to users to users app

pull/1639/head
Hironsan 2 years ago
parent
commit
3ef7793e70
14 changed files with 40 additions and 25 deletions
  1. 2
      Pipfile
  2. 8
      backend/api/serializers.py
  3. 13
      backend/api/urls.py
  4. 1
      backend/app/settings.py
  5. 1
      backend/app/urls.py
  6. 0
      backend/users/__init__.py
  7. 0
      backend/users/admin.py
  8. 6
      backend/users/apps.py
  9. 0
      backend/users/migrations/__init__.py
  10. 0
      backend/users/models.py
  11. 9
      backend/users/serializers.py
  12. 2
      backend/users/tests.py
  13. 18
      backend/users/urls.py
  14. 5
      backend/users/views.py

2
Pipfile

@ -60,6 +60,6 @@ python_version = "3.8"
isort = "isort api -c --skip migrations"
flake8 = "flake8 --filename \"*.py\" --extend-exclude \"server,api/migrations,api/views/__init__.py,authentification,api/apps.py\""
wait_for_db = "python manage.py wait_for_db"
test = "python manage.py test api.tests roles.tests members.tests metrics.tests"
test = "python manage.py test api.tests roles.tests members.tests metrics.tests users.tests"
migrate = "python manage.py migrate"
collectstatic = "python manage.py collectstatic --noinput"

8
backend/api/serializers.py

@ -1,5 +1,4 @@
from auto_labeling_pipeline.models import RequestModelFactory
from django.contrib.auth import get_user_model
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_polymorphic.serializers import PolymorphicSerializer
@ -14,13 +13,6 @@ from .models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION, SEQ2SEQ,
TextClassificationProject, TextLabel)
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ('id', 'username', 'is_superuser', 'is_staff')
class LabelSerializer(serializers.ModelSerializer):
def validate(self, attrs):

13
backend/api/urls.py

@ -2,7 +2,7 @@ from django.urls import include, path
from .views import (annotation, auto_labeling, comment, example, example_state,
export_dataset, health, import_dataset, import_export,
label, project, tag, task, user)
label, project, tag, task)
from .views.tasks import category, relation, span, text
urlpatterns_project = [
@ -225,13 +225,7 @@ urlpatterns = [
view=health.Health.as_view(),
name='health'
),
path('auth/', include('dj_rest_auth.urls')),
path('fp/', include('django_drf_filepond.urls')),
path(
route='me',
view=user.Me.as_view(),
name='me'
),
path(
route='features',
view=import_export.Features.as_view(),
@ -242,11 +236,6 @@ urlpatterns = [
view=project.ProjectList.as_view(),
name='project_list'
),
path(
route='users',
view=user.Users.as_view(),
name='user_list'
),
path(
route='tasks/status/<task_id>',
view=task.TaskStatus.as_view(),

1
backend/app/settings.py

@ -55,6 +55,7 @@ INSTALLED_APPS = [
'roles.apps.RolesConfig',
'members.apps.MembersConfig',
'metrics.apps.MetricsConfig',
'users.apps.UsersConfig',
'rest_framework',
'rest_framework.authtoken',
'django_filters',

1
backend/app/urls.py

@ -42,6 +42,7 @@ urlpatterns += [
path('api-auth/', include('rest_framework.urls')),
path('v1/', include('api.urls')),
path('v1/', include('roles.urls')),
path('v1/', include('users.urls')),
path('v1/projects/<int:project_id>/', include('members.urls')),
path('v1/projects/<int:project_id>/metrics/', include('metrics.urls')),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),

0
backend/users/__init__.py

0
backend/users/admin.py

6
backend/users/apps.py

@ -0,0 +1,6 @@
from django.apps import AppConfig
class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'

0
backend/users/migrations/__init__.py

0
backend/users/models.py

9
backend/users/serializers.py

@ -0,0 +1,9 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ('id', 'username', 'is_superuser', 'is_staff')

backend/api/tests/api/test_user.py → backend/users/tests.py

@ -2,7 +2,7 @@ from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from .utils import make_user
from api.tests.api.utils import make_user
class TestUserAPI(APITestCase):

18
backend/users/urls.py

@ -0,0 +1,18 @@
from django.urls import include, path
from .views import Me, Users
urlpatterns = [
path(
route='me',
view=Me.as_view(),
name='me'
),
path(
route='users',
view=Users.as_view(),
name='user_list'
),
path('auth/', include('dj_rest_auth.urls')),
]

backend/api/views/user.py → backend/users/views.py

@ -1,13 +1,12 @@
from django.contrib.auth.models import User
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, generics
from rest_framework import generics, filters
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from members.permissions import IsProjectAdmin
from ..serializers import UserSerializer
from .serializers import UserSerializer
class Me(APIView):
Loading…
Cancel
Save