From 3b62a837bbfcdf51524e171eea463790d47dda60 Mon Sep 17 00:00:00 2001 From: FPiety0521 Date: Sun, 2 Feb 2020 21:01:02 -0300 Subject: [PATCH] Add pyproject.toml and run black on backend folder --- Pipfile | 62 +++++++++ backend/common/context_processors.py | 8 +- backend/common/management/commands/celery.py | 4 +- .../commands/has_missing_migrations.py | 23 ++-- backend/common/models.py | 4 +- backend/common/utils/tests.py | 7 +- backend/exampleapp/apps.py | 2 +- backend/manage.py | 18 ++- backend/project_name/celery.py | 5 +- backend/project_name/celerybeat_schedule.py | 5 +- backend/project_name/settings/base.py | 116 +++++++--------- backend/project_name/settings/local_base.py | 57 +++----- backend/project_name/settings/production.py | 126 ++++++++---------- backend/project_name/settings/test.py | 21 ++- backend/project_name/urls.py | 7 +- backend/users/admin.py | 27 ++-- backend/users/apps.py | 2 +- backend/users/managers.py | 1 - backend/users/models.py | 14 +- pyproject.toml | 17 +++ 20 files changed, 275 insertions(+), 251 deletions(-) create mode 100644 Pipfile create mode 100644 pyproject.toml diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..d1ec7ef --- /dev/null +++ b/Pipfile @@ -0,0 +1,62 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +amqp = "==2.5.2" +backcall = "==0.1.0" +billiard = "==3.6.2.0" +brotlipy = "==0.7.0" +celery = {extras = ["redis"],version = "==4.4.0"} +certifi = "==2019.11.28" +cffi = "==1.13.2" +decorator = "==4.4.1" +defusedxml = "==0.6.0" +diff-match-patch = "==20181111" +dj-database-url = "==0.5.0" +django-import-export = "==2.0.1" +django-js-reverse = "==0.9.1" +django-log-request-id = "==1.4.1" +django-model-utils = "==4.0.0" +django-webpack-loader = "==0.6.0" +django = "==2.2.9" +et-xmlfile = "==1.0.1" +gunicorn = "==20.0.4" +ipython-genutils = "==0.2.0" +ipython = "==7.12.0" +jdcal = "==1.4.1" +jedi = "==0.16.0" +kombu = "==4.6.7" +markuppy = "==1.14" +odfpy = "==1.4.1" +openpyxl = "==3.0.3" +parso = "==0.6.0" +pexpect = "==4.8.0" +pickleshare = "==0.7.5" +prompt-toolkit = "==3.0.3" +psutil = "==5.6.7" +psycopg2 = "==2.8.4" +ptyprocess = "==0.6.0" +pycparser = "==2.19" +pygments = "==2.5.2" +python-decouple = "==3.3" +pytz = "==2019.3" +pyyaml = "==5.3" +redis = "==3.4.1" +sentry-sdk = "==0.14.1" +six = "==1.14.0" +sqlparse = "==0.3.0" +tablib = "==0.14.0" +traitlets = "==4.3.3" +urllib3 = "==1.25.8" +vine = "==1.3.0" +wcwidth = "==0.1.8" +whitenoise = "==5.0.1" +xlrd = "==1.2.0" +xlwt = "==1.3.0" + +[requires] +python_version = "3.8" diff --git a/backend/common/context_processors.py b/backend/common/context_processors.py index f709859..0a9d5d3 100644 --- a/backend/common/context_processors.py +++ b/backend/common/context_processors.py @@ -2,12 +2,8 @@ def sentry_dsn(request): - return { - 'SENTRY_DSN': settings.SENTRY_DSN - } + return {"SENTRY_DSN": settings.SENTRY_DSN} def commit_sha(request): - return { - 'COMMIT_SHA': settings.COMMIT_SHA - } + return {"COMMIT_SHA": settings.COMMIT_SHA} diff --git a/backend/common/management/commands/celery.py b/backend/common/management/commands/celery.py index 039bc20..35d4f16 100644 --- a/backend/common/management/commands/celery.py +++ b/backend/common/management/commands/celery.py @@ -13,7 +13,7 @@ def restart_celery(): for proc in psutil.process_iter(): if proc.username() != getpass.getuser(): # skip processes not owned by user continue - if proc.name() != 'celery': + if proc.name() != "celery": continue # SIGTERM should only be sent to parent process, never to children processes # see: https://github.com/celery/celery/issues/2700#issuecomment-259716123 @@ -28,5 +28,5 @@ def restart_celery(): class Command(BaseCommand): def handle(self, *args, **kwargs): - print('Starting celery worker with autoreload') + print("Starting celery worker with autoreload") run_with_reloader(restart_celery) diff --git a/backend/common/management/commands/has_missing_migrations.py b/backend/common/management/commands/has_missing_migrations.py index 3034ff7..1b9bf34 100644 --- a/backend/common/management/commands/has_missing_migrations.py +++ b/backend/common/management/commands/has_missing_migrations.py @@ -16,17 +16,19 @@ class Command(BaseCommand): (not necessaily applied though) Based on: https://gist.github.com/nealtodd/a8f87b0d95e73eb482c5 """ + help = "Detect if any apps have missing migration files" def add_arguments(self, parser): parser.add_argument( - '--ignore', - action='store', - nargs='+', - dest='ignore', + "--ignore", + action="store", + nargs="+", + dest="ignore", default=[], help="Comma separated list of apps to ignore missing migration files. " - "Useful for specifying third-party ones here.") + "Useful for specifying third-party ones here.", + ) def handle(self, *args, **options): changed = set() @@ -39,17 +41,16 @@ def handle(self, *args, **options): sys.exit("Unable to check migrations: cannot connect to database\n") autodetector = MigrationAutodetector( - executor.loader.project_state(), - ProjectState.from_apps(apps), + executor.loader.project_state(), ProjectState.from_apps(apps), ) changed.update(autodetector.changes(graph=executor.loader.graph).keys()) - changed -= set(options['ignore']) + changed -= set(options["ignore"]) if changed: sys.exit( - "Apps with model changes but no corresponding migration file: %(changed)s\n" % { - 'changed': list(changed) - }) + "Apps with model changes but no corresponding migration file: %(changed)s\n" + % {"changed": list(changed)} + ) else: sys.stdout.write("All migration files present\n") diff --git a/backend/common/models.py b/backend/common/models.py index 9424db7..f85488d 100644 --- a/backend/common/models.py +++ b/backend/common/models.py @@ -5,8 +5,8 @@ class IndexedTimeStampedModel(models.Model): - created = AutoCreatedField(_('created'), db_index=True) - modified = AutoLastModifiedField(_('modified'), db_index=True) + created = AutoCreatedField(_("created"), db_index=True) + modified = AutoLastModifiedField(_("modified"), db_index=True) class Meta: abstract = True diff --git a/backend/common/utils/tests.py b/backend/common/utils/tests.py index 35a8603..d2639cd 100644 --- a/backend/common/utils/tests.py +++ b/backend/common/utils/tests.py @@ -5,10 +5,9 @@ class TestCaseUtils(TestCase): - def setUp(self): - self._user_password = '123456' - self.user = mommy.prepare('users.User', email='user@email.com') + self._user_password = "123456" + self.user = mommy.prepare("users.User", email="user@email.com") self.user.set_password(self._user_password) self.user.save() @@ -53,14 +52,12 @@ def assertResponse404(self, response): class TestGetRequiresAuthenticatedUser: - def test_get_requires_authenticated_user(self): response = self.client.get(self.view_url) self.assertResponse403(response) class TestAuthGetRequestSuccess: - def test_auth_get_success(self): response = self.auth_client.get(self.view_url) self.assertResponse200(response) diff --git a/backend/exampleapp/apps.py b/backend/exampleapp/apps.py index 905116c..5cb1627 100644 --- a/backend/exampleapp/apps.py +++ b/backend/exampleapp/apps.py @@ -4,4 +4,4 @@ class ExampleappConfig(AppConfig): - name = 'exampleapp' + name = "exampleapp" diff --git a/backend/manage.py b/backend/manage.py index 6619455..40b97b3 100755 --- a/backend/manage.py +++ b/backend/manage.py @@ -7,18 +7,22 @@ if __name__ == "__main__": - settings_module = config('DJANGO_SETTINGS_MODULE', default=None) + settings_module = config("DJANGO_SETTINGS_MODULE", default=None) - if sys.argv[1] == 'test': + if sys.argv[1] == "test": if settings_module: - print("Ignoring config('DJANGO_SETTINGS_MODULE') because it's test. " - "Using '{{project_name}}.settings.test'") + print( + "Ignoring config('DJANGO_SETTINGS_MODULE') because it's test. " + "Using '{{project_name}}.settings.test'" + ) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings.test") else: if settings_module is None: - print("Error: no DJANGO_SETTINGS_MODULE found. Will NOT start devserver. " - "Remember to create .env file at project root. " - "Check README for more info.") + print( + "Error: no DJANGO_SETTINGS_MODULE found. Will NOT start devserver. " + "Remember to create .env file at project root. " + "Check README for more info." + ) sys.exit(1) os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module) diff --git a/backend/project_name/celery.py b/backend/project_name/celery.py index a36bf14..e729262 100644 --- a/backend/project_name/celery.py +++ b/backend/project_name/celery.py @@ -10,9 +10,10 @@ from .celerybeat_schedule import CELERYBEAT_SCHEDULE + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings.local") -app = Celery('{{project_name}}_tasks') -app.config_from_object('django.conf:settings', namespace='CELERY') +app = Celery("{{project_name}}_tasks") +app.config_from_object("django.conf:settings", namespace="CELERY") app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()]) app.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE) diff --git a/backend/project_name/celerybeat_schedule.py b/backend/project_name/celerybeat_schedule.py index d5e92b9..7b9bc4f 100644 --- a/backend/project_name/celerybeat_schedule.py +++ b/backend/project_name/celerybeat_schedule.py @@ -3,8 +3,5 @@ CELERYBEAT_SCHEDULE = { # Internal tasks - 'clearsessions': { - 'schedule': crontab(hour=3, minute=0), - 'task': 'users.tasks.clearsessions' - }, + "clearsessions": {"schedule": crontab(hour=3, minute=0), "task": "users.tasks.clearsessions"}, } diff --git a/backend/project_name/settings/base.py b/backend/project_name/settings/base.py index a4f28b9..8ff24cc 100644 --- a/backend/project_name/settings/base.py +++ b/backend/project_name/settings/base.py @@ -17,81 +17,69 @@ def base_dir_join(*args): DEBUG = True -ADMINS = ( - ('Admin', 'foo@example.com'), -) +ADMINS = (("Admin", "foo@example.com"),) -AUTH_USER_MODEL = 'users.User' +AUTH_USER_MODEL = "users.User" ALLOWED_HOSTS = [] INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - - 'django_js_reverse', - 'webpack_loader', - 'import_export', - - 'common', - 'users', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "django_js_reverse", + "webpack_loader", + "import_export", + "common", + "users", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', - '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", + "whitenoise.middleware.WhiteNoiseMiddleware", + "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 = '{{project_name}}.urls' +ROOT_URLCONF = "{{project_name}}.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [base_dir_join('templates')], - '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', - 'common.context_processors.sentry_dsn', - 'common.context_processors.commit_sha', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [base_dir_join("templates")], + "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", + "common.context_processors.sentry_dsn", + "common.context_processors.commit_sha", ], }, }, ] -WSGI_APPLICATION = '{{project_name}}.wsgi.application' +WSGI_APPLICATION = "{{project_name}}.wsgi.application" AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, + {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",}, + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, + {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, ] -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -99,26 +87,24 @@ def base_dir_join(*args): USE_TZ = True -STATICFILES_DIRS = ( - base_dir_join('../frontend'), -) +STATICFILES_DIRS = (base_dir_join("../frontend"),) # Webpack WEBPACK_LOADER = { - 'DEFAULT': { - 'CACHE': False, # on DEBUG should be False - 'STATS_FILE': base_dir_join('../webpack-stats.json'), - 'POLL_INTERVAL': 0.1, - 'IGNORE': ['.+\.hot-update.js', '.+\.map'] + "DEFAULT": { + "CACHE": False, # on DEBUG should be False + "STATS_FILE": base_dir_join("../webpack-stats.json"), + "POLL_INTERVAL": 0.1, + "IGNORE": [".+\.hot-update.js", ".+\.map"], } } # Celery -CELERY_ACCEPT_CONTENT = ['json'] -CELERY_TASK_SERIALIZER = 'json' -CELERY_RESULT_SERIALIZER = 'json' +CELERY_ACCEPT_CONTENT = ["json"] +CELERY_TASK_SERIALIZER = "json" +CELERY_RESULT_SERIALIZER = "json" CELERY_ACKS_LATE = True # Sentry -SENTRY_DSN = config('SENTRY_DSN', default='') -COMMIT_SHA = config('HEROKU_SLUG_COMMIT', default='') +SENTRY_DSN = config("SENTRY_DSN", default="") +COMMIT_SHA = config("HEROKU_SLUG_COMMIT", default="") diff --git a/backend/project_name/settings/local_base.py b/backend/project_name/settings/local_base.py index b7ff31e..17c780f 100644 --- a/backend/project_name/settings/local_base.py +++ b/backend/project_name/settings/local_base.py @@ -3,25 +3,22 @@ DEBUG = True -HOST = 'http://localhost:8000' +HOST = "http://localhost:8000" -SECRET_KEY = 'secret' +SECRET_KEY = "secret" DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': base_dir_join('db.sqlite3'), - } + "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": base_dir_join("db.sqlite3"),} } -STATIC_ROOT = base_dir_join('staticfiles') -STATIC_URL = '/static/' +STATIC_ROOT = base_dir_join("staticfiles") +STATIC_URL = "/static/" -MEDIA_ROOT = base_dir_join('mediafiles') -MEDIA_URL = '/media/' +MEDIA_ROOT = base_dir_join("mediafiles") +MEDIA_URL = "/media/" -DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' +DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage" +STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" AUTH_PASSWORD_VALIDATORS = [] # allow easy passwords only on local @@ -29,36 +26,22 @@ CELERY_TASK_ALWAYS_EAGER = True # Email -INSTALLED_APPS += ('naomi',) -EMAIL_BACKEND = 'naomi.mail.backends.naomi.NaomiBackend' -EMAIL_FILE_PATH = base_dir_join('tmp_email') +INSTALLED_APPS += ("naomi",) +EMAIL_BACKEND = "naomi.mail.backends.naomi.NaomiBackend" +EMAIL_FILE_PATH = base_dir_join("tmp_email") # Logging LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'formatters': { - 'standard': { - 'format': '%(levelname)-8s [%(asctime)s] %(name)s: %(message)s' - }, + "version": 1, + "disable_existing_loggers": False, + "formatters": {"standard": {"format": "%(levelname)-8s [%(asctime)s] %(name)s: %(message)s"},}, + "handlers": { + "console": {"level": "DEBUG", "class": "logging.StreamHandler", "formatter": "standard",}, }, - 'handlers': { - 'console': { - 'level': 'DEBUG', - 'class': 'logging.StreamHandler', - 'formatter': 'standard', - }, + "loggers": { + "": {"handlers": ["console"], "level": "INFO"}, + "celery": {"handlers": ["console"], "level": "INFO"}, }, - 'loggers': { - '': { - 'handlers': ['console'], - 'level': 'INFO' - }, - 'celery': { - 'handlers': ['console'], - 'level': 'INFO' - } - } } JS_REVERSE_JS_MINIFY = False diff --git a/backend/project_name/settings/production.py b/backend/project_name/settings/production.py index bb9b3b8..3a6343f 100644 --- a/backend/project_name/settings/production.py +++ b/backend/project_name/settings/production.py @@ -9,31 +9,31 @@ DEBUG = False -SECRET_KEY = config('SECRET_KEY') +SECRET_KEY = config("SECRET_KEY") DATABASES = { - 'default': config('DATABASE_URL', cast=db_url), + "default": config("DATABASE_URL", cast=db_url), } -DATABASES['default']['ATOMIC_REQUESTS'] = True +DATABASES["default"]["ATOMIC_REQUESTS"] = True -ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv()) +ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv()) -STATIC_ROOT = base_dir_join('staticfiles') -STATIC_URL = '/static/' +STATIC_ROOT = base_dir_join("staticfiles") +STATIC_URL = "/static/" -MEDIA_ROOT = base_dir_join('mediafiles') -MEDIA_URL = '/media/' +MEDIA_ROOT = base_dir_join("mediafiles") +MEDIA_URL = "/media/" -SERVER_EMAIL = 'foo@example.com' +SERVER_EMAIL = "foo@example.com" -EMAIL_HOST = 'smtp.sendgrid.net' -EMAIL_HOST_USER = config('SENDGRID_USERNAME') -EMAIL_HOST_PASSWORD = config('SENDGRID_PASSWORD') +EMAIL_HOST = "smtp.sendgrid.net" +EMAIL_HOST_USER = config("SENDGRID_USERNAME") +EMAIL_HOST_PASSWORD = config("SENDGRID_PASSWORD") EMAIL_PORT = 587 EMAIL_USE_TLS = True # Security -SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") SECURE_SSL_REDIRECT = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True @@ -42,88 +42,70 @@ SECURE_CONTENT_TYPE_NOSNIFF = True SECURE_BROWSER_XSS_FILTER = True -X_FRAME_OPTIONS = 'DENY' +X_FRAME_OPTIONS = "DENY" # Webpack -WEBPACK_LOADER['DEFAULT']['CACHE'] = True +WEBPACK_LOADER["DEFAULT"]["CACHE"] = True # Celery -CELERY_BROKER_URL = config('REDIS_URL') -CELERY_RESULT_BACKEND = config('REDIS_URL') +CELERY_BROKER_URL = config("REDIS_URL") +CELERY_RESULT_BACKEND = config("REDIS_URL") CELERY_SEND_TASK_ERROR_EMAILS = True # Whitenoise -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" MIDDLEWARE.insert( # insert WhiteNoiseMiddleware right after SecurityMiddleware - MIDDLEWARE.index('django.middleware.security.SecurityMiddleware') + 1, - 'whitenoise.middleware.WhiteNoiseMiddleware') + MIDDLEWARE.index("django.middleware.security.SecurityMiddleware") + 1, + "whitenoise.middleware.WhiteNoiseMiddleware", +) # django-log-request-id MIDDLEWARE.insert( # insert RequestIDMiddleware on the top - 0, 'log_request_id.middleware.RequestIDMiddleware') + 0, "log_request_id.middleware.RequestIDMiddleware" +) -LOG_REQUEST_ID_HEADER = 'HTTP_X_REQUEST_ID' +LOG_REQUEST_ID_HEADER = "HTTP_X_REQUEST_ID" LOG_REQUESTS = True LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - }, - 'request_id': { - '()': 'log_request_id.filters.RequestIDFilter' - }, + "version": 1, + "disable_existing_loggers": False, + "filters": { + "require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}, + "request_id": {"()": "log_request_id.filters.RequestIDFilter"}, }, - 'formatters': { - 'standard': { - 'format': '%(levelname)-8s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s' + "formatters": { + "standard": { + "format": "%(levelname)-8s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s" }, }, - 'handlers': { - 'null': { - 'class': 'logging.NullHandler', - }, - 'mail_admins': { - 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler', - 'filters': ['require_debug_false'], + "handlers": { + "null": {"class": "logging.NullHandler",}, + "mail_admins": { + "level": "ERROR", + "class": "django.utils.log.AdminEmailHandler", + "filters": ["require_debug_false"], }, - 'console': { - 'level': 'DEBUG', - 'class': 'logging.StreamHandler', - 'filters': ['request_id'], - 'formatter': 'standard', + "console": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "filters": ["request_id"], + "formatter": "standard", }, }, - 'loggers': { - '': { - 'handlers': ['console'], - 'level': 'INFO' + "loggers": { + "": {"handlers": ["console"], "level": "INFO"}, + "django.security.DisallowedHost": {"handlers": ["null"], "propagate": False,}, + "django.request": {"handlers": ["mail_admins"], "level": "ERROR", "propagate": True,}, + "log_request_id.middleware": { + "handlers": ["console"], + "level": "DEBUG", + "propagate": False, }, - 'django.security.DisallowedHost': { - 'handlers': ['null'], - 'propagate': False, - }, - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - 'log_request_id.middleware': { - 'handlers': ['console'], - 'level': 'DEBUG', - 'propagate': False, - }, - } + }, } -JS_REVERSE_EXCLUDE_NAMESPACES = ['admin'] +JS_REVERSE_EXCLUDE_NAMESPACES = ["admin"] # Sentry -sentry_sdk.init( - dsn=SENTRY_DSN, - integrations=[DjangoIntegration()], - release=COMMIT_SHA -) +sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()], release=COMMIT_SHA) diff --git a/backend/project_name/settings/test.py b/backend/project_name/settings/test.py index 87df014..4d5c3bc 100644 --- a/backend/project_name/settings/test.py +++ b/backend/project_name/settings/test.py @@ -1,27 +1,24 @@ from .base import * # noqa -SECRET_KEY = 'test' +SECRET_KEY = "test" DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': base_dir_join('db.sqlite3'), - } + "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": base_dir_join("db.sqlite3"),} } -STATIC_ROOT = base_dir_join('staticfiles') -STATIC_URL = '/static/' +STATIC_ROOT = base_dir_join("staticfiles") +STATIC_URL = "/static/" -MEDIA_ROOT = base_dir_join('mediafiles') -MEDIA_URL = '/media/' +MEDIA_ROOT = base_dir_join("mediafiles") +MEDIA_URL = "/media/" -DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' +DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage" +STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" # Speed up password hashing PASSWORD_HASHERS = [ - 'django.contrib.auth.hashers.MD5PasswordHasher', + "django.contrib.auth.hashers.MD5PasswordHasher", ] # Celery diff --git a/backend/project_name/urls.py b/backend/project_name/urls.py index 6e60367..d108732 100644 --- a/backend/project_name/urls.py +++ b/backend/project_name/urls.py @@ -6,8 +6,7 @@ urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'^jsreverse/$', django_js_reverse.views.urls_js, name='js_reverse'), - - url(r'^$', TemplateView.as_view(template_name='itworks.html'), name='home'), + url(r"^admin/", admin.site.urls), + url(r"^jsreverse/$", django_js_reverse.views.urls_js, name="js_reverse"), + url(r"^$", TemplateView.as_view(template_name="itworks.html"), name="home"), ] diff --git a/backend/users/admin.py b/backend/users/admin.py index b8d033f..e7e069b 100644 --- a/backend/users/admin.py +++ b/backend/users/admin.py @@ -6,22 +6,23 @@ class CustomUserAdmin(UserAdmin): - list_display = ('id', 'email', 'created', 'modified') - list_filter = ('is_active', 'is_staff', 'groups') - search_fields = ('email',) - ordering = ('email',) - filter_horizontal = ('groups', 'user_permissions',) + list_display = ("id", "email", "created", "modified") + list_filter = ("is_active", "is_staff", "groups") + search_fields = ("email",) + ordering = ("email",) + filter_horizontal = ( + "groups", + "user_permissions", + ) fieldsets = ( - (None, {'fields': ('email', 'password')}), - (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', - 'groups', 'user_permissions')}), - ) - add_fieldsets = ( - (None, { - 'classes': ('wide',), - 'fields': ('email', 'password1', 'password2')}), + (None, {"fields": ("email", "password")}), + ( + _("Permissions"), + {"fields": ("is_active", "is_staff", "is_superuser", "groups", "user_permissions")}, + ), ) + add_fieldsets = ((None, {"classes": ("wide",), "fields": ("email", "password1", "password2")}),) admin.site.register(User, CustomUserAdmin) diff --git a/backend/users/apps.py b/backend/users/apps.py index 4ce1fab..3ef1284 100644 --- a/backend/users/apps.py +++ b/backend/users/apps.py @@ -2,4 +2,4 @@ class UsersConfig(AppConfig): - name = 'users' + name = "users" diff --git a/backend/users/managers.py b/backend/users/managers.py index 9f13587..a8e111b 100644 --- a/backend/users/managers.py +++ b/backend/users/managers.py @@ -2,7 +2,6 @@ class UserManager(BaseUserManager): - def create_user(self, email, password=None, **kwargs): email = self.normalize_email(email) user = self.model(email=email, **kwargs) diff --git a/backend/users/models.py b/backend/users/models.py index 65c2ad4..42bdbf1 100644 --- a/backend/users/models.py +++ b/backend/users/models.py @@ -10,17 +10,19 @@ class User(AbstractBaseUser, PermissionsMixin, IndexedTimeStampedModel): email = models.EmailField(max_length=255, unique=True) is_staff = models.BooleanField( - default=False, - help_text=_('Designates whether the user can log into this admin ' - 'site.')) + default=False, help_text=_("Designates whether the user can log into this admin " "site.") + ) is_active = models.BooleanField( default=True, - help_text=_('Designates whether this user should be treated as ' - 'active. Unselect this instead of deleting accounts.')) + help_text=_( + "Designates whether this user should be treated as " + "active. Unselect this instead of deleting accounts." + ), + ) objects = UserManager() - USERNAME_FIELD = 'email' + USERNAME_FIELD = "email" def get_full_name(self): return self.email diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0eb8121 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.black] +line-length = 100 +target-version = ['py36'] +quiet = true +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.venv + | _build + | build + | dist + | [a-z_]+/migrations +)/ +'''