From fcc2467bcbcbfd12837e96aa3c0f2e6e3b0089a3 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Mon, 24 Mar 2025 07:41:17 +0100 Subject: [PATCH] chore: minor optimizations and code cleanup --- auth_app/views.py | 2 +- join/settings.py | 54 +++++++++++++++++------------------------ task_app/serializers.py | 4 +-- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/auth_app/views.py b/auth_app/views.py index 95d71f0..444287b 100644 --- a/auth_app/views.py +++ b/auth_app/views.py @@ -29,7 +29,7 @@ class LoginView(APIView): def _create_token_response(self, user): token, created = Token.objects.get_or_create(user=user) - return Response({'token': token.key}, status=status.HTTP_200_OK) + return Response({'token': token.key, 'user_id' : user.id}, status=status.HTTP_200_OK) class LogoutView(APIView): authentication_classes = [authentication.TokenAuthentication] diff --git a/join/settings.py b/join/settings.py index 8eebea3..70082e3 100644 --- a/join/settings.py +++ b/join/settings.py @@ -30,21 +30,13 @@ ALLOWED_HOSTS = [ '127.0.0.1', ] -CORS_ALLOWED_ORIGINS = [ - 'http://localhost:4200', -] - +# CORS settings +CORS_ALLOWED_ORIGINS = ['http://localhost:4200'] CORS_ALLOW_HEADERS = [ - 'content-type', - 'accept', - 'authorization', - 'x-csrftoken', - 'sentry-trace', - 'baggage', + 'content-type', 'accept', 'authorization', 'x-csrftoken', 'sentry-trace', 'baggage', ] -# Application definition - +# Application config AUTH_USER_MODEL = 'user_app.User' INSTALLED_APPS = [ @@ -76,15 +68,6 @@ MIDDLEWARE = [ ROOT_URLCONF = 'join.urls' -REST_FRAMEWORK = { - 'DEFAULT_RENDERER_CLASSES': ( - 'djangorestframework_camel_case.render.CamelCaseJSONRenderer', - ), - 'DEFAULT_PARSER_CLASSES': ( - 'djangorestframework_camel_case.parser.CamelCaseJSONParser', - ), -} - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -103,7 +86,8 @@ TEMPLATES = [ WSGI_APPLICATION = 'join.wsgi.application' -# Redis +# Caching (Redis) + CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', @@ -167,19 +151,25 @@ STATIC_URL = 'static/' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -# Auth +# Authentication -AUTH_USER_MODEL = 'user_app.User' AUTH_EMAIL_VERIFICATION = True -# Rest Framework -REST_FRAMEWORK = { - 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'rest_framework.authentication.TokenAuthentication', - ], -} - AUTHENTICATION_BACKENDS = ( 'auth_app.custom_backend.EmailBackend', 'django.contrib.auth.backends.ModelBackend', -) \ No newline at end of file +) + +# REST Framework config + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework.authentication.TokenAuthentication', + ], + 'DEFAULT_RENDERER_CLASSES': ( + 'djangorestframework_camel_case.render.CamelCaseJSONRenderer', + ), + 'DEFAULT_PARSER_CLASSES': ( + 'djangorestframework_camel_case.parser.CamelCaseJSONParser', + ), +} \ No newline at end of file diff --git a/task_app/serializers.py b/task_app/serializers.py index b78974d..850945f 100644 --- a/task_app/serializers.py +++ b/task_app/serializers.py @@ -11,14 +11,14 @@ class SubTaskSerializer(serializers.ModelSerializer): class AssignedTaskSerializer(serializers.ModelSerializer): class Meta: model = AssignedTask - fields = ['id', 'user_id'] + fields = ['user_id'] class TaskSerializer(serializers.ModelSerializer): assignees = serializers.SerializerMethodField() subtasks = SubTaskSerializer(many=True, read_only=True) def get_assignees(self, obj): - return obj.assigned_tasks.all().values('id', 'user_id') + return obj.assigned_tasks.all().values('user_id') class Meta: model = Task