Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcen committed Jan 17, 2024
1 parent fce76fe commit f7a3842
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 88 deletions.
4 changes: 2 additions & 2 deletions django/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion django/myproject/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_asgi_application()
134 changes: 70 additions & 64 deletions django/myproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,108 +13,112 @@
from pathlib import Path

import environ

env = environ.Env(
# set casting, default value
DEBUG=(bool, False),
TIME_ZONE=(str, 'UTC')
TIME_ZONE=(str, "UTC"),
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# reading .env file
environ.Env.read_env(str(BASE_DIR.parent / '.env'))
environ.Env.read_env(str(BASE_DIR.parent / ".env"))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# Raises django's ImproperlyConfigured exception if SECRET_KEY not in
# os.environ
SECRET_KEY = env('SECRET_KEY')
SECRET_KEY = env("SECRET_KEY")

# False if not in os.environ
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env('DEBUG')
DEBUG = env("DEBUG")

ALLOWED_HOSTS = ['localhost'] + env('ALLOWED_HOSTS').split(',')
CSRF_TRUSTED_ORIGINS = env('CSRF_TRUSTED_ORIGINS').split(',')
ALLOWED_HOSTS = ["localhost"] + env("ALLOWED_HOSTS").split(",")
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS").split(",")


# Application definition

INSTALLED_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",
# Add gis module for geospatial projects
#'django.contrib.gis',
# Include this to build REST APIs
'rest_framework',
"rest_framework",
# Include this to build on top of Boostrap 5
'django_bootstrap5',
"django_bootstrap5",
# Include this to add history to models
'simple_history',
"simple_history",
# Include extras to make working with Django's CLI etc easier
'django_extensions',
"django_extensions",
# Uncomment the below line and replace 'myapp' with the name of your app
#'myapp',
]

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",
# Include this to add history to models
'simple_history.middleware.HistoryRequestMiddleware',
"simple_history.middleware.HistoryRequestMiddleware",
]

ROOT_URLCONF = 'myproject.urls'
ROOT_URLCONF = "myproject.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 = 'myproject.wsgi.application'
WSGI_APPLICATION = "myproject.wsgi.application"


# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASES = {
'default': {
"default": {
# Use sqlite by default
'ENGINE': env("DB_ENGINE", default='django.db.backends.sqlite3'),
"ENGINE": env("DB_ENGINE", default="django.db.backends.sqlite3"),
# Use spatialite for spatial projects
#'ENGINE': env("DB_ENGINE", default='django.contrib.gis.db.backends.spatialite'),
# Use regular Postgres in production
#'ENGINE': env("DB_ENGINE", default='django.db.backends.postgresql_psycopg2'),
# Use PostGIS in production for spatial projects
#'ENGINE': env("DB_ENGINE", default='django.contrib.gis.db.backends.postgis'),
'NAME': env("POSTGRES_DB", default=env("DB_NAME", default=str(BASE_DIR.parent / 'db/db.sqlite3'))),
'USER': env("POSTGRES_USER", default="nobody"),
'PASSWORD': env("POSTGRES_PASSWORD", default="insecure"),
'HOST': env("POSTGRES_HOST", default="localhost"),
'PORT': env("POSTGRES_PORT", default="5432"),
"NAME": env(
"POSTGRES_DB",
default=env("DB_NAME", default=str(BASE_DIR.parent / "db/db.sqlite3")),
),
"USER": env("POSTGRES_USER", default="nobody"),
"PASSWORD": env("POSTGRES_PASSWORD", default="insecure"),
"HOST": env("POSTGRES_HOST", default="localhost"),
"PORT": env("POSTGRES_PORT", default="5432"),
}
}

Expand All @@ -124,24 +128,24 @@

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",
},
]


# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = env("TIME_ZONE")

Expand All @@ -155,24 +159,26 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = str(BASE_DIR.parent / 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = str(BASE_DIR.parent / 'media')
STATIC_URL = "/static/"
STATIC_ROOT = str(BASE_DIR.parent / "static")
MEDIA_URL = "/media/"
MEDIA_ROOT = str(BASE_DIR.parent / "media")

# Default primary key field type
# https://docs.djangoproject.com/en/dev/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

EMAIL_BACKEND = env('EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')
EMAIL_HOST = env('EMAIL_HOST', default='mail')
EMAIL_PORT = env('EMAIL_PORT', default='587')
EMAIL_HOST_USER = env('EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD', default='')
EMAIL_USE_TLS = env('EMAIL_USE_TLS', default=False)
EMAIL_USE_SSL = env('EMAIL_USE_SSL', default=False)
EMAIL_TIMEOUT = env('EMAIL_TIMEOUT', default=None)
EMAIL_SSL_KEYFILE = env('EMAIL_SSL_KEYFILE', default=None)
EMAIL_SSL_CERTFILE = env('EMAIL_SSL_CERTFILE', default=None)
DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL', default='webmaster@localhost')
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

EMAIL_BACKEND = env(
"EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend"
)
EMAIL_HOST = env("EMAIL_HOST", default="mail")
EMAIL_PORT = env("EMAIL_PORT", default="587")
EMAIL_HOST_USER = env("EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD", default="")
EMAIL_USE_TLS = env("EMAIL_USE_TLS", default=False)
EMAIL_USE_SSL = env("EMAIL_USE_SSL", default=False)
EMAIL_TIMEOUT = env("EMAIL_TIMEOUT", default=None)
EMAIL_SSL_KEYFILE = env("EMAIL_SSL_KEYFILE", default=None)
EMAIL_SSL_CERTFILE = env("EMAIL_SSL_CERTFILE", default=None)
DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="webmaster@localhost")
27 changes: 14 additions & 13 deletions django/myproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,41 @@
# Use this for regular Django projects
from django.contrib import admin
from django.contrib.auth import views as auth_views

# Use this for geospatial projects
#from django.contrib.gis import admin
# from django.contrib.gis import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path(
'admin/password_reset/',
"admin/password_reset/",
auth_views.PasswordResetView.as_view(),
name='admin_password_reset',
name="admin_password_reset",
),
path(
'admin/password_reset/done/',
"admin/password_reset/done/",
auth_views.PasswordResetDoneView.as_view(),
name='password_reset_done',
name="password_reset_done",
),
path(
'reset/<uidb64>/<token>/',
"reset/<uidb64>/<token>/",
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm',
name="password_reset_confirm",
),
path(
'reset/done/',
"reset/done/",
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete',
name="password_reset_complete",
),
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
# Add this to set up authentication for REST framework
#path('api-auth/', include('rest_framework.urls')),
# path('api-auth/', include('rest_framework.urls')),
# To set up your first app to manage the homepage of this site,
# uncomment the below line, and replace 'myapp' with the name of your app.
#path('', include('myapp.urls')),
# path('', include('myapp.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static('docs/', document_root='/docs', show_indexes=True)
urlpatterns += static("docs/", document_root="/docs", show_indexes=True)
2 changes: 1 addition & 1 deletion django/myproject/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application()
13 changes: 6 additions & 7 deletions django/scripts/createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@


def run():
super_username = environ['SUPERUSER_USERNAME']
super_password = environ['SUPERUSER_PASSWORD']
super_email = environ['SUPERUSER_EMAIL']
super_username = environ["SUPERUSER_USERNAME"]
super_password = environ["SUPERUSER_PASSWORD"]
super_email = environ["SUPERUSER_EMAIL"]

User = get_user_model()
if (super_username != '' and super_password != '' and super_email != ''):
if super_username != "" and super_password != "" and super_email != "":
has_superuser = False
for u in User.objects.values():
if u['is_superuser']:
if u["is_superuser"]:
has_superuser = True
break
if not has_superuser:
print("Creating super user: " + super_username)
User.objects.create_superuser(
super_username, super_email, super_password)
User.objects.create_superuser(super_username, super_email, super_password)
else:
print("Super user already exists. Not creating another.")

0 comments on commit f7a3842

Please sign in to comment.