From 2776c35892b5f2c918c5cc2350e23dae95d4249a Mon Sep 17 00:00:00 2001 From: Olzhas Arystanov Date: Fri, 3 May 2024 21:13:24 +0500 Subject: [PATCH] Clean & lint --- app/envs/prod/gunicorn.conf.py | 3 - app/src/bittensor_panel/asgi.py | 3 - app/src/bittensor_panel/celery.py | 5 +- .../bittensor_panel/core/tests/settings.py | 1 - app/src/bittensor_panel/settings.py | 2 +- app/src/bittensor_panel/urls.py | 1 - app/src/bittensor_panel/users/apps.py | 4 +- .../users/migrations/0001_initial.py | 92 ++++++++++++++----- app/src/bittensor_panel/users/tests.py | 3 - app/src/bittensor_panel/users/views.py | 3 - bin/emailhelper.py | 7 +- 11 files changed, 80 insertions(+), 44 deletions(-) delete mode 100644 app/src/bittensor_panel/users/tests.py delete mode 100644 app/src/bittensor_panel/users/views.py diff --git a/app/envs/prod/gunicorn.conf.py b/app/envs/prod/gunicorn.conf.py index 4eed1cb..fdc70d5 100644 --- a/app/envs/prod/gunicorn.conf.py +++ b/app/envs/prod/gunicorn.conf.py @@ -4,6 +4,3 @@ bind = "0.0.0.0:8000" wsgi_app = "bittensor_panel.wsgi:application" access_logfile = "-" - - - diff --git a/app/src/bittensor_panel/asgi.py b/app/src/bittensor_panel/asgi.py index e869d08..96cbdd8 100644 --- a/app/src/bittensor_panel/asgi.py +++ b/app/src/bittensor_panel/asgi.py @@ -1,9 +1,6 @@ import os - from django.core.asgi import get_asgi_application - - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bittensor_panel.settings") application = get_asgi_application() diff --git a/app/src/bittensor_panel/celery.py b/app/src/bittensor_panel/celery.py index 204ec00..ff42512 100644 --- a/app/src/bittensor_panel/celery.py +++ b/app/src/bittensor_panel/celery.py @@ -1,8 +1,11 @@ import logging import os -from celery import Celeryfrom django.conf import settings +from celery import Celery +from celery.signals import setup_logging +from django.conf import settings from django_structlog.celery.steps import DjangoStructLogInitStep + from .settings import configure_structlog os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bittensor_panel.settings") diff --git a/app/src/bittensor_panel/core/tests/settings.py b/app/src/bittensor_panel/core/tests/settings.py index a105923..275c43a 100644 --- a/app/src/bittensor_panel/core/tests/settings.py +++ b/app/src/bittensor_panel/core/tests/settings.py @@ -3,4 +3,3 @@ os.environ["DEBUG_TOOLBAR"] = "False" from bittensor_panel.settings import * # noqa: E402,F403 - diff --git a/app/src/bittensor_panel/settings.py b/app/src/bittensor_panel/settings.py index 410f579..ec012aa 100644 --- a/app/src/bittensor_panel/settings.py +++ b/app/src/bittensor_panel/settings.py @@ -197,7 +197,7 @@ def wrapped(*args, **kwargs): SECURE_SSL_REDIRECT = False CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" -CONSTANCE_CONFIG = { +CONSTANCE_CONFIG: dict[str, tuple[str, str, str]] = { # "PARAMETER": (default-value, "Help text", type), } diff --git a/app/src/bittensor_panel/urls.py b/app/src/bittensor_panel/urls.py index 8fce2ae..6113a46 100644 --- a/app/src/bittensor_panel/urls.py +++ b/app/src/bittensor_panel/urls.py @@ -2,7 +2,6 @@ from django.contrib.admin.sites import site from django.urls import include, path - urlpatterns = [ path("admin/", site.urls), path("", include("django.contrib.auth.urls")), diff --git a/app/src/bittensor_panel/users/apps.py b/app/src/bittensor_panel/users/apps.py index 3014754..d3f38b4 100644 --- a/app/src/bittensor_panel/users/apps.py +++ b/app/src/bittensor_panel/users/apps.py @@ -2,5 +2,5 @@ class UsersConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'bittensor_panel.users' + default_auto_field = "django.db.models.BigAutoField" + name = "bittensor_panel.users" diff --git a/app/src/bittensor_panel/users/migrations/0001_initial.py b/app/src/bittensor_panel/users/migrations/0001_initial.py index 8e12873..40cf41b 100644 --- a/app/src/bittensor_panel/users/migrations/0001_initial.py +++ b/app/src/bittensor_panel/users/migrations/0001_initial.py @@ -2,43 +2,93 @@ import django.contrib.auth.models import django.contrib.auth.validators -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): - initial = True dependencies = [ - ('auth', '0012_alter_user_first_name_max_length'), + ("auth", "0012_alter_user_first_name_max_length"), ] operations = [ migrations.CreateModel( - name='User', + name="User", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('password', models.CharField(max_length=128, verbose_name='password')), - ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), - ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), - ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), - ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), - ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), - ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), - ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), - ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), - ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), - ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), - ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("password", models.CharField(max_length=128, verbose_name="password")), + ("last_login", models.DateTimeField(blank=True, null=True, verbose_name="last login")), + ( + "is_superuser", + models.BooleanField( + default=False, + help_text="Designates that this user has all permissions without explicitly assigning them.", + verbose_name="superuser status", + ), + ), + ( + "username", + models.CharField( + error_messages={"unique": "A user with that username already exists."}, + help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.", + max_length=150, + unique=True, + validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], + verbose_name="username", + ), + ), + ("first_name", models.CharField(blank=True, max_length=150, verbose_name="first name")), + ("last_name", models.CharField(blank=True, max_length=150, verbose_name="last name")), + ("email", models.EmailField(blank=True, max_length=254, verbose_name="email address")), + ( + "is_staff", + models.BooleanField( + default=False, + help_text="Designates whether the user can log into this admin site.", + verbose_name="staff status", + ), + ), + ( + "is_active", + models.BooleanField( + default=True, + help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", + verbose_name="active", + ), + ), + ("date_joined", models.DateTimeField(default=django.utils.timezone.now, verbose_name="date joined")), + ( + "groups", + models.ManyToManyField( + blank=True, + help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", + related_name="user_set", + related_query_name="user", + to="auth.group", + verbose_name="groups", + ), + ), + ( + "user_permissions", + models.ManyToManyField( + blank=True, + help_text="Specific permissions for this user.", + related_name="user_set", + related_query_name="user", + to="auth.permission", + verbose_name="user permissions", + ), + ), ], options={ - 'verbose_name': 'user', - 'verbose_name_plural': 'users', - 'abstract': False, + "verbose_name": "user", + "verbose_name_plural": "users", + "abstract": False, }, managers=[ - ('objects', django.contrib.auth.models.UserManager()), + ("objects", django.contrib.auth.models.UserManager()), ], ), ] diff --git a/app/src/bittensor_panel/users/tests.py b/app/src/bittensor_panel/users/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/app/src/bittensor_panel/users/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/app/src/bittensor_panel/users/views.py b/app/src/bittensor_panel/users/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/app/src/bittensor_panel/users/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/bin/emailhelper.py b/bin/emailhelper.py index 9bc8d43..4b85da2 100755 --- a/bin/emailhelper.py +++ b/bin/emailhelper.py @@ -30,10 +30,7 @@ def send(self, addr_from, addr_to, subject, message, files=tuple()): with open(file, "rb") as stream: part.set_payload(stream.read()) encoders.encode_base64(part) - part.add_header( - "Content-Disposition", - 'attachment; filename="%s"' % os.path.basename(file), - ) + part.add_header("Content-Disposition", f'attachment; filename="{os.path.basename(file)}"') msg.attach(part) s = smtplib.SMTP(self.server, self.port) @@ -86,7 +83,7 @@ def parse_arguments(): sys.exit(2) try: - email_creds = urlsplit("//%s" % email_creds) + email_creds = urlsplit(f"//{email_creds}") if not all([email_creds.username, email_creds.hostname, email_creds.port]): raise ValueError except ValueError: