Skip to content

Commit 410fd28

Browse files
committed
fix: formatted and lint the codebase
1 parent 31a7f8b commit 410fd28

File tree

10 files changed

+88
-95
lines changed

10 files changed

+88
-95
lines changed

app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"""Entry point for the WSGI server to serve the Django application."""
2+
13
import os
24

35
from django.core.wsgi import get_wsgi_application
46

5-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
7+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
68

7-
app = get_wsgi_application()
9+
app = get_wsgi_application()

backend/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Backend module for the application."""

backend/asgi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
ASGI config for backend project.
1+
"""ASGI config for backend project.
32
43
It exposes the ASGI callable as a module-level variable named ``application``.
54
@@ -11,6 +10,6 @@
1110

1211
from django.core.asgi import get_asgi_application
1312

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
13+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
1514

1615
application = get_asgi_application()

backend/constants.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
import os
2-
from backend.env import config
1+
"""Constants for the entire application."""
2+
33
from functools import lru_cache
44

5+
from backend.env import config
6+
57

68
def convert_to_list(value: str) -> list[str]:
7-
return [item.strip() for item in value.split(',')]
9+
"""Convert a comma-separated string to a list of strings."""
10+
return [item.strip() for item in value.split(",")]
811

9-
class Constants(object):
10-
DJANGO_DEBUG: bool = config("DJANGO_DEBUG",cast=bool)
12+
13+
class Constants:
14+
"""Constants for the application."""
15+
16+
DJANGO_DEBUG: bool = config("DJANGO_DEBUG", cast=bool)
1117
DJANGO_ALLOWED_HOSTS: list[str] = convert_to_list(
12-
value=config("DJANGO_ALLOWED_HOSTS", cast=str)
18+
value=config("DJANGO_ALLOWED_HOSTS", cast=str),
1319
)
1420
DJANGO_SECRET_KEY: str = config("DJANGO_SECRET_KEY", cast=str)
1521
USE_POSTGRES: bool = config("USE_POSTGRES", cast=bool, default=False)
1622
DATABASE_URL: str = config("DATABASE_URL", cast=str)
1723

18-
24+
1925
@lru_cache
2026
def get_constants() -> Constants:
27+
"""Get the constants for the application."""
2128
return Constants()

backend/db.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import sys
1+
"""Configuration for the database."""
2+
23
import dj_database_url
34
from django.conf import settings
45

56
from backend.constants import get_constants
67

78
constants = get_constants()
89

9-
BASE_DIR = getattr(settings, 'BASE_DIR')
10+
BASE_DIR = settings.BASE_DIR
1011

1112
DATABASES = {}
1213

1314
if constants.DJANGO_DEBUG:
1415
DATABASES = {
1516
"default": {
1617
"ENGINE": "django.db.backends.sqlite3",
17-
"NAME": BASE_DIR / "db.sqlite3",
18-
}
18+
"NAME": BASE_DIR / "db.sqlite3",
19+
},
1920
}
2021
else:
21-
DATABASES['default'] = dj_database_url.config()
22+
DATABASES["default"] = dj_database_url.config()

backend/env.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
"""Configure environment variables for the application."""
2+
13
import pathlib
24
from functools import lru_cache
3-
from decouple import Config, RepositoryEnv, config as config_default
4-
from django.conf import settings
5+
6+
from decouple import Config, RepositoryEnv
7+
from decouple import config as config_default
58

69
BASE_DIR = pathlib.Path(__file__).parent.parent
710

811
ENV_PATH = BASE_DIR / ".env"
912

10-
@lru_cache()
11-
def get_config():
13+
14+
@lru_cache
15+
def get_config() -> Config:
16+
"""Get the configuration from the .env file if it exists."""
1217
if ENV_PATH.exists():
1318
return Config(RepositoryEnv(ENV_PATH))
1419
return config_default
1520

16-
config = get_config()
21+
22+
config = get_config()

backend/settings.py

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
"""
2-
Django settings for backend project.
3-
4-
Generated by 'django-admin startproject' using Django 3.2.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/3.2/ref/settings/
11-
"""
1+
"""Django settings for backend project."""
122

133
from pathlib import Path
4+
145
from backend.constants import get_constants
156

167
constants = get_constants()
@@ -24,78 +15,78 @@
2415
ALLOWED_HOSTS = constants.DJANGO_ALLOWED_HOSTS
2516

2617
INSTALLED_APPS = [
27-
'django.contrib.admin',
28-
'django.contrib.auth',
29-
'django.contrib.contenttypes',
30-
'django.contrib.sessions',
31-
'django.contrib.messages',
32-
'django.contrib.staticfiles',
18+
"django.contrib.admin",
19+
"django.contrib.auth",
20+
"django.contrib.contenttypes",
21+
"django.contrib.sessions",
22+
"django.contrib.messages",
23+
"django.contrib.staticfiles",
3324
]
3425

3526
MIDDLEWARE = [
36-
'django.middleware.security.SecurityMiddleware',
37-
'whitenoise.middleware.WhiteNoiseMiddleware',
38-
'django.contrib.sessions.middleware.SessionMiddleware',
39-
'django.middleware.common.CommonMiddleware',
40-
'django.middleware.csrf.CsrfViewMiddleware',
41-
'django.contrib.auth.middleware.AuthenticationMiddleware',
42-
'django.contrib.messages.middleware.MessageMiddleware',
43-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
27+
"django.middleware.security.SecurityMiddleware",
28+
"whitenoise.middleware.WhiteNoiseMiddleware",
29+
"django.contrib.sessions.middleware.SessionMiddleware",
30+
"django.middleware.common.CommonMiddleware",
31+
"django.middleware.csrf.CsrfViewMiddleware",
32+
"django.contrib.auth.middleware.AuthenticationMiddleware",
33+
"django.contrib.messages.middleware.MessageMiddleware",
34+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
4435
]
4536

46-
ROOT_URLCONF = 'backend.urls'
37+
ROOT_URLCONF = "backend.urls"
4738

4839
TEMPLATES = [
4940
{
50-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
51-
'DIRS': [BASE_DIR / 'templates'],
52-
'APP_DIRS': True,
53-
'OPTIONS': {
54-
'context_processors': [
55-
'django.template.context_processors.debug',
56-
'django.template.context_processors.request',
57-
'django.contrib.auth.context_processors.auth',
58-
'django.contrib.messages.context_processors.messages',
41+
"BACKEND": "django.template.backends.django.DjangoTemplates",
42+
"DIRS": [BASE_DIR / "templates"],
43+
"APP_DIRS": True,
44+
"OPTIONS": {
45+
"context_processors": [
46+
"django.template.context_processors.debug",
47+
"django.template.context_processors.request",
48+
"django.contrib.auth.context_processors.auth",
49+
"django.contrib.messages.context_processors.messages",
5950
],
6051
},
6152
},
6253
]
6354

64-
WSGI_APPLICATION = 'backend.wsgi.application'
55+
WSGI_APPLICATION = "backend.wsgi.application"
6556

6657
AUTH_PASSWORD_VALIDATORS = [
6758
{
68-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
59+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
6960
},
7061
{
71-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
62+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
7263
},
7364
{
74-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
65+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
7566
},
7667
{
77-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
68+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
7869
},
7970
]
8071

8172

82-
LANGUAGE_CODE = 'en-us'
73+
LANGUAGE_CODE = "en-us"
8374

84-
TIME_ZONE = 'Asia/Kolkata'
75+
TIME_ZONE = "Asia/Kolkata"
8576

8677
USE_I18N = True
8778

8879
USE_L10N = True
8980

9081
USE_TZ = True
9182

92-
STATIC_URL = '/static/'
83+
STATIC_URL = "/static/"
9384

9485
STATICFILES_DIRS = [
95-
BASE_DIR / 'static',
86+
BASE_DIR / "static",
9687
]
97-
STATIC_ROOT = BASE_DIR / 'staticfiles_build' / 'static'
88+
STATIC_ROOT = BASE_DIR / "staticfiles_build" / "static"
9889

99-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
90+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
10091

101-
from backend.db import * # noqa: F401
92+
from backend.db import * # noqa: F403, E402

backend/urls.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
"""backend URL Configuration
1+
"""backend URL Configuration for the project."""
22

3-
The `urlpatterns` list routes URLs to views. For more information please see:
4-
https://docs.djangoproject.com/en/3.2/topics/http/urls/
5-
Examples:
6-
Function views
7-
1. Add an import: from my_app import views
8-
2. Add a URL to urlpatterns: path('', views.home, name='home')
9-
Class-based views
10-
1. Add an import: from other_app.views import Home
11-
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12-
Including another URLconf
13-
1. Import the include() function: from django.urls import include, path
14-
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15-
"""
163
from django.contrib import admin
174
from django.urls import path
18-
195
from django.views.generic import TemplateView
206

217
urlpatterns = [
22-
path('admin/', admin.site.urls),
23-
path('', TemplateView.as_view(template_name='index.html')),
24-
path('about/', TemplateView.as_view(template_name='about.html')),
8+
path("admin/", admin.site.urls),
9+
path("", TemplateView.as_view(template_name="index.html")),
10+
path("about/", TemplateView.as_view(template_name="about.html")),
2511
]

backend/wsgi.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
WSGI config for backend project.
1+
"""WSGI config for backend project.
32
43
It exposes the WSGI callable as a module-level variable named ``application``.
54
@@ -11,6 +10,6 @@
1110

1211
from django.core.wsgi import get_wsgi_application
1312

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
13+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
1514

16-
application = get_wsgi_application()
15+
application = get_wsgi_application()

manage.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#!/usr/bin/env python
22
"""Django's command-line utility for administrative tasks."""
3+
34
import os
45
import sys
56

67

7-
def main():
8+
def main() -> None:
89
"""Run administrative tasks."""
9-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
10+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
1011
try:
1112
from django.core.management import execute_from_command_line
1213
except ImportError as exc:
1314
raise ImportError(
1415
"Couldn't import Django. Are you sure it's installed and "
1516
"available on your PYTHONPATH environment variable? Did you "
16-
"forget to activate a virtual environment?"
17+
"forget to activate a virtual environment?",
1718
) from exc
1819
execute_from_command_line(sys.argv)
1920

2021

21-
if __name__ == '__main__':
22+
if __name__ == "__main__":
2223
main()

0 commit comments

Comments
 (0)