Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
tkw1536 committed Oct 3, 2023
1 parent ba356c7 commit 3ecaf79
Show file tree
Hide file tree
Showing 92 changed files with 2,405 additions and 1,484 deletions.
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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


if __name__ == '__main__':
if __name__ == "__main__":
main()
21 changes: 18 additions & 3 deletions mddl_catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@

from .models import CodecCatalogItem


@admin.register(CodecCatalogItem)
class CodecAdmin(admin.ModelAdmin):
list_display = (
'slug', 'math_type', 'db_type', 'kind', 'implemented', 'mddl',
"slug",
"math_type",
"db_type",
"kind",
"implemented",
"mddl",
)

list_filter = (
'kind', 'implemented', 'mddl', 'math_type', 'db_type',
"kind",
"implemented",
"mddl",
"math_type",
"db_type",
)

search_fields = (
'slug', 'math_type', 'db_type', 'kind', 'description', 'comment',
"slug",
"math_type",
"db_type",
"kind",
"description",
"comment",
)
2 changes: 1 addition & 1 deletion mddl_catalog/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


class MddlCatalogConfig(AppConfig):
name = 'mddl_catalog'
name = "mddl_catalog"
34 changes: 27 additions & 7 deletions mddl_catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,40 @@
from django.db import models

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional


class CodecCatalogItem(models.Model):
slug: Optional[str] = models.SlugField(unique=True, null=True, blank=True, help_text="MDDL name")
slug: Optional[str] = models.SlugField(
unique=True, null=True, blank=True, help_text="MDDL name"
)

math_type: Optional[str] = models.TextField(null=True, blank=True, help_text="MMT Term representing mathtype")
db_type = models.TextField(null=True, blank=True, help_text="MMT Term representing dbtype")
math_type: Optional[str] = models.TextField(
null=True, blank=True, help_text="MMT Term representing mathtype"
)
db_type = models.TextField(
null=True, blank=True, help_text="MMT Term representing dbtype"
)

KIND_CHOICES = [(k, k) for k in ['Codec', 'Codec Operator', 'Import only', 'Export only']]
kind: Optional[str] = models.CharField(max_length=256, null=True, blank=True, choices=KIND_CHOICES, help_text="Kind of codec")
KIND_CHOICES = [
(k, k) for k in ["Codec", "Codec Operator", "Import only", "Export only"]
]
kind: Optional[str] = models.CharField(
max_length=256,
null=True,
blank=True,
choices=KIND_CHOICES,
help_text="Kind of codec",
)

description: Optional[str] = models.TextField(null=True, blank=True, help_text="Human readable description")
comment: Optional[str] = models.TextField(null=True, blank=True, help_text="Extra comment")
description: Optional[str] = models.TextField(
null=True, blank=True, help_text="Human readable description"
)
comment: Optional[str] = models.TextField(
null=True, blank=True, help_text="Extra comment"
)

implemented: bool = models.BooleanField(help_text="Implementation Status")
mddl: bool = models.BooleanField(help_text="Status in MDDL")
14 changes: 7 additions & 7 deletions mhd/docker_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

# Passwords
DATABASES = {
'default': {
'ENGINE': os.environ.setdefault("DJANGO_DB_ENGINE", ""),
'NAME': os.environ.setdefault("DJANGO_DB_NAME", ""),
'USER': os.environ.setdefault("DJANGO_DB_USER", ""),
'PASSWORD': os.environ.setdefault("DJANGO_DB_PASSWORD", ""),
'HOST': os.environ.setdefault("DJANGO_DB_HOST", ""),
'PORT': os.environ.setdefault("DJANGO_DB_PORT", ""),
"default": {
"ENGINE": os.environ.setdefault("DJANGO_DB_ENGINE", ""),
"NAME": os.environ.setdefault("DJANGO_DB_NAME", ""),
"USER": os.environ.setdefault("DJANGO_DB_USER", ""),
"PASSWORD": os.environ.setdefault("DJANGO_DB_PASSWORD", ""),
"HOST": os.environ.setdefault("DJANGO_DB_HOST", ""),
"PORT": os.environ.setdefault("DJANGO_DB_PORT", ""),
}
}

Expand Down
4 changes: 3 additions & 1 deletion mhd/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging

import os


class RequireLogQueries(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return os.environ.get('MHD_LOG_QUERIES', '0') == '1'
return os.environ.get("MHD_LOG_QUERIES", "0") == "1"
162 changes: 78 additions & 84 deletions mhd/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@

try:
from psycopg2cffi import compat

compat.register()
except ImportError:
pass

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'o0_0r&@$9=!)#^78dao^f4rd^kxiw1db&navvk27q8hest#_fb'
SECRET_KEY = "o0_0r&@$9=!)#^78dao^f4rd^kxiw1db&navvk27q8hest#_fb"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -42,73 +43,73 @@
# Application definition

INSTALLED_APPS = [
'mhd_schema',
'mhd_data',
'mhd_provenance',
'mddl_catalog',
'rest_framework',
'mviews',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
"mhd_schema",
"mhd_data",
"mhd_provenance",
"mddl_catalog",
"rest_framework",
"mviews",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
]

USE_TEST_APP = True # set this to true to add the test app to installed apps

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'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',
"corsheaders.middleware.CorsMiddleware",
"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 = 'mhd.urls'
ROOT_URLCONF = "mhd.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 = 'mhd.wsgi.application'
WSGI_APPLICATION = "mhd.wsgi.application"


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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

# Django Rest Framework
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'mhd.utils.DefaultPaginator',
'PAGE_SIZE': 50,
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
"DEFAULT_PAGINATION_CLASS": "mhd.utils.DefaultPaginator",
"PAGE_SIZE": 50,
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticatedOrReadOnly",
],
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
"TEST_REQUEST_DEFAULT_FORMAT": "json",
}

# CORS
Expand All @@ -121,26 +122,26 @@

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/2.2/topics/i18n/

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

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -153,52 +154,45 @@
# https://docs.djangoproject.com/en/2.2/howto/static-files/

# we only have static files for the admin site
STATIC_URL = '/api/admin/static/'
STATIC_URL = "/api/admin/static/"

# buildpath used (only used in development)
WEBPACK_BUILD_PATH = os.path.join(BASE_DIR, 'frontend', 'build')
WEBPACK_BUILD_PATH = os.path.join(BASE_DIR, "frontend", "build")

# Log everything of info and above to STDOUT at all times
LOGGING = {
'version': 1,
'filters': {
'require_log_queries': {
'()': 'mhd.logging.RequireLogQueries'
}
},
'formatters': {
'default': {
'format': '[{levelname} - {asctime}] {name}: {message}',
'style': '{',
"version": 1,
"filters": {"require_log_queries": {"()": "mhd.logging.RequireLogQueries"}},
"formatters": {
"default": {
"format": "[{levelname} - {asctime}] {name}: {message}",
"style": "{",
},
'plain': {
'format': '{message}',
'style': '{',
"plain": {
"format": "{message}",
"style": "{",
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'default'
"handlers": {
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "default",
},
"debugconsole": {
"level": "DEBUG",
"filters": ["require_log_queries"],
"class": "logging.StreamHandler",
"formatter": "plain",
},
'debugconsole': {
'level': 'DEBUG',
'filters': ['require_log_queries'],
'class': 'logging.StreamHandler',
'formatter': 'plain'
}
},
'loggers': {
'mhd': {
'level': 'DEBUG',
'handlers': ['console']
"loggers": {
"mhd": {"level": "DEBUG", "handlers": ["console"]},
"django.db.backends": {
"level": "DEBUG",
"handlers": ["debugconsole"],
},
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['debugconsole'],
}
}
},
}

# try and import local_settings if they exist
Expand All @@ -209,4 +203,4 @@

# when set to true, enable the test app
if USE_TEST_APP:
INSTALLED_APPS.append('mhd_tests')
INSTALLED_APPS.append("mhd_tests")
Loading

0 comments on commit 3ecaf79

Please sign in to comment.