From c357a376ee1d73a72d1c5f01f765ea70ac4f60eb Mon Sep 17 00:00:00 2001 From: David Saidov Date: Sat, 15 Jun 2024 16:20:19 +0300 Subject: [PATCH] add django-cors-headers --- backend/backend/settings.py | 8 ++-- backend/users/models.py | 6 ++- poetry.lock | 81 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 1 + requirements.txt | 5 +++ 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 poetry.lock create mode 100644 requirements.txt diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 9a067b5..dc96d3a 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -33,6 +33,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'rest_framework', 'rest_framework.authtoken', 'drf_spectacular', @@ -48,6 +49,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -216,15 +218,15 @@ CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' +CORS_ALLOW_ALL_ORIGINS = True if os.getenv('CORS_ALLOW_ALL_ORIGINS', False) == 'True' else False CORS_ORIGIN_WHITELIST = [ 'http://localhost:3000', 'http://localhost:8080', 'http://127.0.0.1:8080', 'http://localhost:80', 'http://localhost', - 'http://31.129.98.70/', + 'http://31.129.98.70', ] - CSRF_TRUSTED_ORIGINS = [ 'http://localhost:3000', 'http://localhost:8080', @@ -232,7 +234,7 @@ 'http://127.0.0.1:8080', 'http://localhost', 'https://127.0.0.1', - 'http://31.129.98.70/', + 'http://31.129.98.70', ] # EMAIL BACKEND diff --git a/backend/users/models.py b/backend/users/models.py index ad49e60..7fdd7c0 100644 --- a/backend/users/models.py +++ b/backend/users/models.py @@ -1,3 +1,5 @@ +from decimal import Decimal + from django.contrib.auth.models import AbstractUser from django.core.exceptions import ValidationError from django.core.validators import (MinValueValidator, MaxValueValidator, @@ -180,8 +182,8 @@ class ChildrenGroup(models.Model): max_digits=4, decimal_places=2, validators=[ - MinValueValidator(1.0), - MaxValueValidator(99.0), + MinValueValidator(Decimal('1.00')), + MaxValueValidator(Decimal('99.00')), ], error_messages={ 'invalid': 'Средний возраст должен быть от 1 до 99' diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..cd678dd --- /dev/null +++ b/poetry.lock @@ -0,0 +1,81 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "asgiref" +version = "3.8.1" +description = "ASGI specs, helper code, and adapters" +optional = false +python-versions = ">=3.8" +files = [ + {file = "asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47"}, + {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, +] + +[package.extras] +tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] + +[[package]] +name = "django" +version = "5.0.6" +description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design." +optional = false +python-versions = ">=3.10" +files = [ + {file = "Django-5.0.6-py3-none-any.whl", hash = "sha256:8363ac062bb4ef7c3f12d078f6fa5d154031d129a15170a1066412af49d30905"}, + {file = "Django-5.0.6.tar.gz", hash = "sha256:ff1b61005004e476e0aeea47c7f79b85864c70124030e95146315396f1e7951f"}, +] + +[package.dependencies] +asgiref = ">=3.7.0,<4" +sqlparse = ">=0.3.1" +tzdata = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +argon2 = ["argon2-cffi (>=19.1.0)"] +bcrypt = ["bcrypt"] + +[[package]] +name = "django-cors-headers" +version = "4.3.1" +description = "django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS)." +optional = false +python-versions = ">=3.8" +files = [ + {file = "django-cors-headers-4.3.1.tar.gz", hash = "sha256:0bf65ef45e606aff1994d35503e6b677c0b26cafff6506f8fd7187f3be840207"}, + {file = "django_cors_headers-4.3.1-py3-none-any.whl", hash = "sha256:0b1fd19297e37417fc9f835d39e45c8c642938ddba1acce0c1753d3edef04f36"}, +] + +[package.dependencies] +asgiref = ">=3.6" +Django = ">=3.2" + +[[package]] +name = "sqlparse" +version = "0.5.0" +description = "A non-validating SQL parser." +optional = false +python-versions = ">=3.8" +files = [ + {file = "sqlparse-0.5.0-py3-none-any.whl", hash = "sha256:c204494cd97479d0e39f28c93d46c0b2d5959c7b9ab904762ea6c7af211c8663"}, + {file = "sqlparse-0.5.0.tar.gz", hash = "sha256:714d0a4932c059d16189f58ef5411ec2287a4360f17cdd0edd2d09d4c5087c93"}, +] + +[package.extras] +dev = ["build", "hatch"] +doc = ["sphinx"] + +[[package]] +name = "tzdata" +version = "2024.1" +description = "Provider of IANA time zone data" +optional = false +python-versions = ">=2" +files = [ + {file = "tzdata-2024.1-py2.py3-none-any.whl", hash = "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252"}, + {file = "tzdata-2024.1.tar.gz", hash = "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "4c23e07c3d71a0b4a1505f2f806cba4899ec6e54d37c5a23feb8175d42e063f1" diff --git a/pyproject.toml b/pyproject.toml index c4015ec..e900d81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.12" +django-cors-headers = "^4.3.1" [build-system] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6f1afa9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +asgiref==3.8.1 ; python_version >= "3.12" and python_version < "4.0" +django-cors-headers==4.3.1 ; python_version >= "3.12" and python_version < "4.0" +django==5.0.6 ; python_version >= "3.12" and python_version < "4.0" +sqlparse==0.5.0 ; python_version >= "3.12" and python_version < "4.0" +tzdata==2024.1 ; python_version >= "3.12" and python_version < "4.0" and sys_platform == "win32"