chore: minor optimizations and code cleanup
This commit is contained in:
parent
0ac3a5049c
commit
fcc2467bcb
3 changed files with 25 additions and 35 deletions
|
|
@ -29,7 +29,7 @@ class LoginView(APIView):
|
||||||
|
|
||||||
def _create_token_response(self, user):
|
def _create_token_response(self, user):
|
||||||
token, created = Token.objects.get_or_create(user=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):
|
class LogoutView(APIView):
|
||||||
authentication_classes = [authentication.TokenAuthentication]
|
authentication_classes = [authentication.TokenAuthentication]
|
||||||
|
|
|
||||||
|
|
@ -30,21 +30,13 @@ ALLOWED_HOSTS = [
|
||||||
'127.0.0.1',
|
'127.0.0.1',
|
||||||
]
|
]
|
||||||
|
|
||||||
CORS_ALLOWED_ORIGINS = [
|
# CORS settings
|
||||||
'http://localhost:4200',
|
CORS_ALLOWED_ORIGINS = ['http://localhost:4200']
|
||||||
]
|
|
||||||
|
|
||||||
CORS_ALLOW_HEADERS = [
|
CORS_ALLOW_HEADERS = [
|
||||||
'content-type',
|
'content-type', 'accept', 'authorization', 'x-csrftoken', 'sentry-trace', 'baggage',
|
||||||
'accept',
|
|
||||||
'authorization',
|
|
||||||
'x-csrftoken',
|
|
||||||
'sentry-trace',
|
|
||||||
'baggage',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Application definition
|
# Application config
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'user_app.User'
|
AUTH_USER_MODEL = 'user_app.User'
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
|
@ -76,15 +68,6 @@ MIDDLEWARE = [
|
||||||
|
|
||||||
ROOT_URLCONF = 'join.urls'
|
ROOT_URLCONF = 'join.urls'
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
|
||||||
'DEFAULT_RENDERER_CLASSES': (
|
|
||||||
'djangorestframework_camel_case.render.CamelCaseJSONRenderer',
|
|
||||||
),
|
|
||||||
'DEFAULT_PARSER_CLASSES': (
|
|
||||||
'djangorestframework_camel_case.parser.CamelCaseJSONParser',
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
|
@ -103,7 +86,8 @@ TEMPLATES = [
|
||||||
|
|
||||||
WSGI_APPLICATION = 'join.wsgi.application'
|
WSGI_APPLICATION = 'join.wsgi.application'
|
||||||
|
|
||||||
# Redis
|
# Caching (Redis)
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django_redis.cache.RedisCache',
|
'BACKEND': 'django_redis.cache.RedisCache',
|
||||||
|
|
@ -167,19 +151,25 @@ STATIC_URL = 'static/'
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
|
||||||
# Auth
|
# Authentication
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'user_app.User'
|
|
||||||
AUTH_EMAIL_VERIFICATION = True
|
AUTH_EMAIL_VERIFICATION = True
|
||||||
|
|
||||||
# Rest Framework
|
|
||||||
REST_FRAMEWORK = {
|
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
||||||
'rest_framework.authentication.TokenAuthentication',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
AUTHENTICATION_BACKENDS = (
|
AUTHENTICATION_BACKENDS = (
|
||||||
'auth_app.custom_backend.EmailBackend',
|
'auth_app.custom_backend.EmailBackend',
|
||||||
'django.contrib.auth.backends.ModelBackend',
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
@ -11,14 +11,14 @@ class SubTaskSerializer(serializers.ModelSerializer):
|
||||||
class AssignedTaskSerializer(serializers.ModelSerializer):
|
class AssignedTaskSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AssignedTask
|
model = AssignedTask
|
||||||
fields = ['id', 'user_id']
|
fields = ['user_id']
|
||||||
|
|
||||||
class TaskSerializer(serializers.ModelSerializer):
|
class TaskSerializer(serializers.ModelSerializer):
|
||||||
assignees = serializers.SerializerMethodField()
|
assignees = serializers.SerializerMethodField()
|
||||||
subtasks = SubTaskSerializer(many=True, read_only=True)
|
subtasks = SubTaskSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
def get_assignees(self, obj):
|
def get_assignees(self, obj):
|
||||||
return obj.assigned_tasks.all().values('id', 'user_id')
|
return obj.assigned_tasks.all().values('user_id')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Task
|
model = Task
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue