Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff changes: single quotes, correct multi-line docstings, trailing c… #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ select = [
"TCH"

]
ignore = ["D100", "D103", "T201", "D104"]
ignore = ["D100", "D103", "T201", "D104", "COM819", "D212"]

fixable = ["ALL"]
unfixable = []

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = false

[tool.ruff.lint."flake8-quotes"]
inline-quotes = "single"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"settings*" = ["E501", "F405"]

23 changes: 12 additions & 11 deletions src/admin_user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

@admin.register(Administrator)
class AdministratorAdmin(UserAdmin):
"""Admin panel for the Admin model in the Django admin area.
"""
Admin panel for the Admin model in the Django admin area.

Changes made:
- 'USERNAME_FIELD from the User model is used for creating a user.'
Expand All @@ -16,19 +17,19 @@ class AdministratorAdmin(UserAdmin):

add_fieldsets = (
(None, {
"fields": (
'fields': (
Administrator.USERNAME_FIELD,
*Administrator.REQUIRED_FIELDS,
"password1",
"password2",
"is_staff",
"is_superuser",
'password1',
'password2',
'is_staff',
'is_superuser',
),
}),
)

list_display = ("username", "email")
search_fields = ("username", "email")
list_filter = ("is_staff",)
list_display_links = ("username",)
search_help_text = "Поиск по почте или имени пользователя."
list_display = ('username', 'email',)
search_fields = ('username', 'email',)
list_filter = ('is_staff',)
list_display_links = ('username',)
search_help_text = 'Поиск по почте или имени пользователя.'
4 changes: 2 additions & 2 deletions src/admin_user/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class AdminUserConfig(AppConfig):
"""Django config for admin_user app."""

default_auto_field = "django.db.models.BigAutoField"
name = "admin_user"
default_auto_field = 'django.db.models.BigAutoField'
name = 'admin_user'
21 changes: 11 additions & 10 deletions src/admin_user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
class Administrator(AbstractUser):
"""Custom Administrator model."""

first_name = models.CharField("Имя", max_length=DEFAULT_NAME_LENGTH)
last_name = models.CharField("Фамилия", max_length=DEFAULT_NAME_LENGTH)
phone = PhoneNumberField("Номер телефона", help_text="Формат +7XXXXXXXXXX")
USERNAME_FIELD = "email"
REQUIRED_FIELDS = ("username", "first_name", "last_name", "phone")
first_name = models.CharField('Имя', max_length=DEFAULT_NAME_LENGTH)
last_name = models.CharField('Фамилия', max_length=DEFAULT_NAME_LENGTH)
phone = PhoneNumberField('Номер телефона', help_text='Формат +7XXXXXXXXXX')
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ('username', 'first_name', 'last_name', 'phone')

email = models.EmailField(
"E-mail адрес",
'E-mail адрес',
max_length=EMAIL_LENGTH,
unique=True,
)

class Meta:
"""Set verbose name and verbose name plural.
"""
Set verbose name and verbose name plural.

Defaults to ordering by id.
"""

ordering = ("id",)
verbose_name = "Администратор"
verbose_name_plural = "Администраторы"
ordering = ('id',)
verbose_name = 'Администратор'
verbose_name_plural = 'Администраторы'

def __str__(self) -> str:
"""Return a string representation of User object."""
Expand Down
12 changes: 6 additions & 6 deletions src/bot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
class BotConfig(AppConfig):
"""Configuration class for the bot application."""

default_auto_field = "django.db.models.BigAutoField"
name = "bot"
default_auto_field = 'django.db.models.BigAutoField'
name = 'bot'

def stop_bot(self, **kwargs):
"""Stop application."""
Expand All @@ -15,14 +15,14 @@ def stop_bot(self, **kwargs):
def ready(self) -> None:
"""Perform actions when the application is ready."""
import os

# TODO: временное решение, необходимо продумать улучшение.
if os.environ.get("DJANGO_MIGRATE", False):
if os.environ.get("RUN_MAIN", None) != "true":
if os.environ.get('DJANGO_MIGRATE', False):
if os.environ.get('RUN_MAIN', None) != 'true':
from bot.bot_interface import Bot

self.bot = Bot()

asgi_shutdown.connect(self.stop_bot)

self.bot.start()
self.bot.start()
6 changes: 3 additions & 3 deletions src/bot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=(
"Привет, я бот онлайн школы GoodStart.\n\n"
"Здесь ты найдёшь лучших преподавателей."
'Привет, я бот онлайн школы GoodStart.\n\n'
'Здесь ты найдёшь лучших преподавателей.'
),
)

Expand All @@ -23,5 +23,5 @@ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE):
)


start_handler = CommandHandler("start", start)
start_handler = CommandHandler('start', start)
echo_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), echo)
4 changes: 2 additions & 2 deletions src/core/asgi_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.core.asgi import get_asgi_application

os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"core.config.settings_dev",
'DJANGO_SETTINGS_MODULE',
'core.config.settings_dev',
) # настройки для разработки

application = get_asgi_application()
4 changes: 2 additions & 2 deletions src/core/asgi_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.core.asgi import get_asgi_application

os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"core.config.settings_prod",
'DJANGO_SETTINGS_MODULE',
'core.config.settings_prod',
) # настройки для сервера

application = get_asgi_application()
88 changes: 44 additions & 44 deletions src/core/config/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,93 @@
BASE_DIR = Path(__file__).resolve().parent.parent.parent
ROOT_DIR = BASE_DIR.parent

environ.Env.read_env(os.path.join(ROOT_DIR, ".env"))
environ.Env.read_env(os.path.join(ROOT_DIR, '.env'))

STATIC_ROOT = os.path.join(ROOT_DIR, "static/")
STATIC_ROOT = os.path.join(ROOT_DIR, 'static/')

DEFAULT = "some_default_key"
DEFAULT = 'some_default_key'

SECRET_KEY = env.str("SECRET_KEY", default=DEFAULT)
SECRET_KEY = env.str('SECRET_KEY', default=DEFAULT)

TELEGRAM_TOKEN = env("TELEGRAM_TOKEN")
TELEGRAM_TOKEN = env('TELEGRAM_TOKEN')

ALLOWED_HOSTS = ["*"]
ALLOWED_HOSTS = ['*']

DEFAULT_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

LOCAL_APPS = [
"bot.apps.BotConfig",
"potential_user.apps.PotentialUserConfig",
"admin_user.apps.AdminUserConfig",
"schooling.apps.SchoolingConfig",
'bot.apps.BotConfig',
'potential_user.apps.PotentialUserConfig',
'admin_user.apps.AdminUserConfig',
'schooling.apps.SchoolingConfig',
]

EXTERNAL_APPS = ["phonenumber_field",]
EXTERNAL_APPS = ['phonenumber_field',]

INSTALLED_APPS = DEFAULT_APPS + EXTERNAL_APPS + LOCAL_APPS

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = "core.urls"
ROOT_URLCONF = 'core.urls'

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = "core.wsgi.application"
WSGI_APPLICATION = 'core.wsgi.application'

AUTH_USER_MODEL = "admin_user.Administrator"
AUTH_USER_MODEL = 'admin_user.Administrator'

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

LANGUAGE_CODE = "ru-RU"
LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = "UTC"
TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

STATIC_URL = "static/"
STATIC_URL = 'static/'

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
18 changes: 9 additions & 9 deletions src/core/config/settings_for_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
DEBUG = True

DATABASES = {
"default": {
"ENGINE": env.str(
"POSTGRES_ENGINE",
default="django.db.backends.postgresql",
'default': {
'ENGINE': env.str(
'POSTGRES_ENGINE',
default='django.db.backends.postgresql',
),
"NAME": env.str("POSTGRES_NAME", default="postgres"),
"USER": env.str("POSTGRES_USER", default="postgres"),
"PASSWORD": env.str("POSTGRES_PASSWORD", default="postgres"),
"HOST": env.str("POSTGRES_HOST", default="localhost"),
"PORT": env.str("POSTGRES_PORT", default="5432"),
'NAME': env.str('POSTGRES_NAME', default='postgres'),
'USER': env.str('POSTGRES_USER', default='postgres'),
'PASSWORD': env.str('POSTGRES_PASSWORD', default='postgres'),
'HOST': env.str('POSTGRES_HOST', default='localhost'),
'PORT': env.str('POSTGRES_PORT', default='5432'),
},
}
18 changes: 9 additions & 9 deletions src/core/config/settings_for_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
DEBUG = False

DATABASES = {
"default": {
"ENGINE": env.str(
"POSTGRES_ENGINE",
default="django.db.backends.postgresql",
'default': {
'ENGINE': env.str(
'POSTGRES_ENGINE',
default='django.db.backends.postgresql',
),
"NAME": env.str("POSTGRES_NAME", default="postgres"),
"USER": env.str("POSTGRES_USER", default="postgres"),
"PASSWORD": env.str("POSTGRES_PASSWORD", default="postgres"),
"HOST": env.str("POSTGRES_HOST", default="localhost"),
"PORT": env.str("POSTGRES_PORT", default="5432"),
'NAME': env.str('POSTGRES_NAME', default='postgres'),
'USER': env.str('POSTGRES_USER', default='postgres'),
'PASSWORD': env.str('POSTGRES_PASSWORD', default='postgres'),
'HOST': env.str('POSTGRES_HOST', default='localhost'),
'PORT': env.str('POSTGRES_PORT', default='5432'),
},
}
6 changes: 3 additions & 3 deletions src/core/config/settings_for_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
DEBUG = False

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
},
}
2 changes: 1 addition & 1 deletion src/core/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def inner(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
error_message = f"Произошла ошибка: {e}"
error_message = f'Произошла ошибка: {e}'
print(error_message)
raise e

Expand Down
Loading
Loading