From 2410b83194c2b7c69f815b8beb168f3a55cf528e Mon Sep 17 00:00:00 2001 From: Kozin Artem Date: Tue, 26 Mar 2024 11:51:30 +0300 Subject: [PATCH 1/2] =?UTF-8?q?Revert=20"[~]=20Added=20flake8.=20R:=20Ther?= =?UTF-8?q?e=20was=20no=20check=20for=20unsupported=20imports.=20FB:=20?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 6 --- flake8 | 7 ---- poetry.lock | 51 +---------------------- pyproject.toml | 1 - src/backend/api/v1/general/views.py | 5 +-- src/backend/api/v1/profile/serializers.py | 4 +- src/backend/api/v1/profile/urls.py | 2 +- src/backend/api/v1/profile/views.py | 2 + src/backend/api/v1/users/serializers.py | 2 + src/backend/apps/profile/validators.py | 17 +++----- src/backend/apps/projects/constants.py | 5 +-- src/backend/apps/users/validators.py | 1 + src/backend/config/urls.py | 2 + 13 files changed, 19 insertions(+), 86 deletions(-) delete mode 100644 flake8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd1a044..162a48e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,12 +24,6 @@ repos: hooks: - id: isort - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - args: [--config=flake8, src/backend/] - - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: diff --git a/flake8 b/flake8 deleted file mode 100644 index 04fe4fc..0000000 --- a/flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -extend-ignore = E203 -exclude = - __pycache__, - **/migrations/*, - src/backend/config/settings/* -max-complexity = 10 diff --git a/poetry.lock b/poetry.lock index eb81f44..390fea2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -698,22 +698,6 @@ docs = ["furo (>=2023.9.10)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1 testing = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "diff-cover (>=8)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)", "pytest-timeout (>=2.2)"] typing = ["typing-extensions (>=4.8)"] -[[package]] -name = "flake8" -version = "7.0.0" -description = "the modular source code checker: pep8 pyflakes and co" -optional = false -python-versions = ">=3.8.1" -files = [ - {file = "flake8-7.0.0-py2.py3-none-any.whl", hash = "sha256:a6dfbb75e03252917f2473ea9653f7cd799c3064e54d4c8140044c5c065f53c3"}, - {file = "flake8-7.0.0.tar.gz", hash = "sha256:33f96621059e65eec474169085dc92bf26e7b2d47366b70be2f67ab80dc25132"}, -] - -[package.dependencies] -mccabe = ">=0.7.0,<0.8.0" -pycodestyle = ">=2.11.0,<2.12.0" -pyflakes = ">=3.2.0,<3.3.0" - [[package]] name = "gunicorn" version = "21.2.0" @@ -851,17 +835,6 @@ sqs = ["boto3 (>=1.26.143)", "pycurl (>=7.43.0.5)", "urllib3 (>=1.26.16)"] yaml = ["PyYAML (>=3.10)"] zookeeper = ["kazoo (>=2.8.0)"] -[[package]] -name = "mccabe" -version = "0.7.0" -description = "McCabe checker, plugin for flake8" -optional = false -python-versions = ">=3.6" -files = [ - {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, - {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, -] - [[package]] name = "mypy-extensions" version = "1.0.0" @@ -1138,17 +1111,6 @@ files = [ {file = "psycopg2_binary-2.9.9-cp39-cp39-win_amd64.whl", hash = "sha256:f7ae5d65ccfbebdfa761585228eb4d0df3a8b15cfb53bd953e713e09fbb12957"}, ] -[[package]] -name = "pycodestyle" -version = "2.11.1" -description = "Python style guide checker" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pycodestyle-2.11.1-py2.py3-none-any.whl", hash = "sha256:44fe31000b2d866f2e41841b18528a505fbd7fef9017b04eff4e2648a0fadc67"}, - {file = "pycodestyle-2.11.1.tar.gz", hash = "sha256:41ba0e7afc9752dfb53ced5489e89f8186be00e599e712660695b7a75ff2663f"}, -] - [[package]] name = "pycparser" version = "2.21" @@ -1160,17 +1122,6 @@ files = [ {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"}, ] -[[package]] -name = "pyflakes" -version = "3.2.0" -description = "passive checker of Python programs" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pyflakes-3.2.0-py2.py3-none-any.whl", hash = "sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a"}, - {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, -] - [[package]] name = "pyjwt" version = "2.8.0" @@ -1667,4 +1618,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12.1" -content-hash = "bcc991df17503de0c85c29cd798b9c693d8699c09d27ef622ef1d2f63752b336" +content-hash = "c1de01a3620a2ba1a1e0b3ccf0a5a8808caf9647b0d63dd1880052c6b121e4aa" diff --git a/pyproject.toml b/pyproject.toml index ed81bbf..9c7dff1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,6 @@ django-celery-beat = "^2.6.0" pre-commit = "^3.5.0" black = "^23.12.1" isort = "5.13.2" -flake8 = "^7.0.0" [build-system] requires = ["poetry-core"] diff --git a/src/backend/api/v1/general/views.py b/src/backend/api/v1/general/views.py index f398c66..9508fd5 100644 --- a/src/backend/api/v1/general/views.py +++ b/src/backend/api/v1/general/views.py @@ -30,10 +30,7 @@ class CounterApiView(generics.RetrieveAPIView): def get(self, request): with connection.cursor() as cursor: cursor.execute( - """ - SELECT count(*) from projects_project union all SELECT count(*) - from users_user - """ + "SELECT count(*) from projects_project union all SELECT count(*) from users_user " ) row = cursor.fetchall() return Response({"projects": row[0][0], "users": row[1][0]}) diff --git a/src/backend/api/v1/profile/serializers.py b/src/backend/api/v1/profile/serializers.py index 96be57a..16266f2 100644 --- a/src/backend/api/v1/profile/serializers.py +++ b/src/backend/api/v1/profile/serializers.py @@ -1,11 +1,11 @@ -from rest_framework import serializers +from rest_framework import generics, serializers from apps.profile.models import Profile, UserSkill, UserSpecialization from apps.projects.models import Skill, Specialist class ProfileSerializer(serializers.Serializer): - """Сериализатор на просмотр профиля с учетом выбора видимости контактов.""" + """Модель сериализатора на просмотр профиля с учетом выбора видимости контактов""" class Meta: model = Profile diff --git a/src/backend/api/v1/profile/urls.py b/src/backend/api/v1/profile/urls.py index 566fb21..0ae6bb0 100644 --- a/src/backend/api/v1/profile/urls.py +++ b/src/backend/api/v1/profile/urls.py @@ -1,4 +1,4 @@ -from django.urls import path +from django.urls import include, path from api.v1.profile.views import ProfileListAPIView, ProfileView diff --git a/src/backend/api/v1/profile/views.py b/src/backend/api/v1/profile/views.py index ef05776..09d086b 100644 --- a/src/backend/api/v1/profile/views.py +++ b/src/backend/api/v1/profile/views.py @@ -1,3 +1,4 @@ +from django.db.models import Q from rest_framework import generics from api.v1.profile.permissions import IsOwnerOrReadOnly @@ -6,6 +7,7 @@ ProfileUpdateSerializer, ) from apps.profile.models import Profile +from apps.projects.models import Project class ProfileView(generics.UpdateAPIView): diff --git a/src/backend/api/v1/users/serializers.py b/src/backend/api/v1/users/serializers.py index a868273..1f3333d 100644 --- a/src/backend/api/v1/users/serializers.py +++ b/src/backend/api/v1/users/serializers.py @@ -1,8 +1,10 @@ from django.contrib.auth import get_user_model from djoser.serializers import ( + SendEmailResetSerializer, UserCreatePasswordRetypeSerializer, UserSerializer, ) +from rest_framework import serializers from api.v1.users import constants diff --git a/src/backend/apps/profile/validators.py b/src/backend/apps/profile/validators.py index a372035..e7b5a30 100644 --- a/src/backend/apps/profile/validators.py +++ b/src/backend/apps/profile/validators.py @@ -1,14 +1,12 @@ from datetime import date from django.core.exceptions import ValidationError +from django.core.validators import RegexValidator from PIL import Image class BirthdayValidator: - """ - Валидатор, не позволяющий пользователю добавить будущую дату в качестве - своего дня рождения. - """ + """Валидатор, не позволяющий пользователю добавить будущую дату в качестве своего дня рождения""" def __init__(self, min_age=0): self.min_age = min_age @@ -21,27 +19,24 @@ def __call__(self, value): def validate_image_format(value): - """ - Валидатор, позволяющий добавить аватар только определенного формата .png, - .jpg или .jpeg. - """ + """Валидатор, позволяющий добавить аватар только определенного формата .png, .jpg или .jpeg""" valid_extensions = [".png", ".jpg", ".jpeg"] ext = value.name.lower().split(".")[-1] - if ext not in valid_extensions: + if not ext in valid_extensions: raise ValidationError( "Пожалуйста загрузите файл с расширением PNG или JPEG." ) def validate_image_size(value): - """Валидатор, не позволяющий загрузить картинку размером больше 10 MB.""" + """Валидатор, не позволяющий загрузить картинку размером больше 10 MB""" max_size = 10 * 1024 * 1024 # 10 MB if value.size > max_size: raise ValidationError("Файл не должен превышать размер 10 MB.") def validate_image_resolution(value): - """Валидатор, ограничивающий размер картинки.""" + """Валидатор, ограничивающий размер картинки""" min_width, min_height = 320, 240 max_width, max_height = 1920, 1080 diff --git a/src/backend/apps/projects/constants.py b/src/backend/apps/projects/constants.py index a1d3e15..a5c32c3 100644 --- a/src/backend/apps/projects/constants.py +++ b/src/backend/apps/projects/constants.py @@ -24,10 +24,7 @@ "символов." ) REGEX_DIRECTION_NAME = r"(^[A-Za-zА-Яа-яЁё]+)\Z" -REGEX_DIRECTION_NAME_ERROR_TEXT = ( - "Направление разработки может содержать: кириллические и латинские " - "символы." -) +REGEX_DIRECTION_NAME_ERROR_TEXT = "Направление разработки может содержать: кириллические и латинские символы." MAX_LENGTH_LINK = 256 MIN_LENGTH_LINK = 5 diff --git a/src/backend/apps/users/validators.py b/src/backend/apps/users/validators.py index 0ae0d38..6191123 100644 --- a/src/backend/apps/users/validators.py +++ b/src/backend/apps/users/validators.py @@ -1,3 +1,4 @@ +import re from typing import Any from django.core.exceptions import ValidationError diff --git a/src/backend/config/urls.py b/src/backend/config/urls.py index 41a4e3c..714cd31 100644 --- a/src/backend/config/urls.py +++ b/src/backend/config/urls.py @@ -1,3 +1,5 @@ +from typing import List + from django.contrib import admin from django.urls import include, path From 42a8bc4531294feaa8f3a16d2bb45fa8637a0789 Mon Sep 17 00:00:00 2001 From: Kozin Date: Tue, 26 Mar 2024 11:53:08 +0300 Subject: [PATCH 2/2] [*] Fix error no module named apps.project. R: Typo in the app name. FB: Fixed the name of the application in the project settings. --- src/backend/config/settings/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/config/settings/base.py b/src/backend/config/settings/base.py index 9c85dff..aa9d593 100644 --- a/src/backend/config/settings/base.py +++ b/src/backend/config/settings/base.py @@ -39,7 +39,7 @@ LOCAL_APPS: list = [ "apps.general", "apps.users", - "apps.project", + "apps.projects", "apps.profile", ]