From dc3e797be881cf466c9fcd37721be11cca9ca23a Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 7 Dec 2019 09:38:07 +0100 Subject: [PATCH] Further cleanup along settings and debris. --- .env | 3 -- dpaste/models.py | 2 -- dpaste/settings/base.py | 70 ++++++++++------------------------------ dpaste/settings/tests.py | 11 ++----- runtests.py | 24 -------------- setup.cfg | 6 ++-- 6 files changed, 22 insertions(+), 94 deletions(-) delete mode 100644 .env delete mode 100755 runtests.py diff --git a/.env b/.env deleted file mode 100644 index 8c48127..0000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -APPNAME = dpaste -DJANGO_SETTINGS_MODULE=dpaste.settings.local - diff --git a/dpaste/models.py b/dpaste/models.py index c685276..180039f 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -5,7 +5,6 @@ from django.apps import apps from django.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ -from six import python_2_unicode_compatible from dpaste import highlight @@ -39,7 +38,6 @@ def generate_secret_id(length): return generate_secret_id(length=length + 1) -@python_2_unicode_compatible class Snippet(models.Model): EXPIRE_TIME = 1 EXPIRE_KEEP = 2 diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index d60da0c..a94b2b6 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -1,53 +1,33 @@ +# ============================================================================== # Import global settings to make it easier to extend settings. # ============================================================================== -# Calculation of directories relative to the module location -# ============================================================================== import os -import sys - -from django.conf.global_settings import * - import dpaste +import dj_database_url -PROJECT_DIR, PROJECT_MODULE_NAME = os.path.split( +env = os.environ.get + +BASE_DIR, PROJECT_MODULE_NAME = os.path.split( os.path.dirname(os.path.realpath(dpaste.__file__)) ) -PYTHON_BIN = os.path.dirname(sys.executable) -if os.path.exists(os.path.join(PYTHON_BIN, "activate_this.py")): - # Assume that the presence of 'activate_this.py' in the python bin/ - # directory means that we're running in a virtual environment. Set the - # variable root to $VIRTUALENV/var. - VAR_ROOT = os.path.join(os.path.dirname(PYTHON_BIN), "var") - if not os.path.exists(VAR_ROOT): - os.mkdir(VAR_ROOT) -else: - # Set the variable root to the local configuration location (which is - # ignored by the repository). - VAR_ROOT = os.path.join(PROJECT_DIR, PROJECT_MODULE_NAME, "conf", "local") - # ============================================================================== -# Generic Django project settings +# Settings # ============================================================================== -DEBUG = False +DEBUG = env("DEBUG", False) -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -TIME_ZONE = "UTC" SITE_ID = 1 # Make this unique, and don't share it with anybody. -SECRET_KEY = "" +SECRET_KEY = env("SECRET_KEY", "") -ALLOWED_HOSTS = ["*"] - -# ============================================================================== -# I18N -# ============================================================================== +ALLOWED_HOSTS = env("ALLOWED_HOSTS", "*").split(",") +TIME_ZONE = "UTC" USE_I18N = True -USE_L10N = False +USE_L10N = True +USE_TZ = True LANGUAGE_CODE = "en" LANGUAGES = (("en", "English"),) @@ -56,10 +36,6 @@ LANGUAGES = (("en", "English"),) # os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')), # ) -# ============================================================================== -# Project URLS and media settings -# ============================================================================== - STATICFILES_STORAGE = ( "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" ) @@ -69,20 +45,14 @@ STATICFILES_FINDERS = ( "django.contrib.staticfiles.finders.AppDirectoriesFinder", ) -STATIC_ROOT = os.path.join(VAR_ROOT, "static") +STATIC_ROOT = env("STATIC_ROOT", ".static") +MEDIA_ROOT = env("MEDIA_ROOT", ".media") STATIC_URL = "/static/" -ADMIN_MEDIA_PREFIX = "/static/admin/" ROOT_URLCONF = "dpaste.urls" -LOGIN_URL = "/accounts/login/" -LOGOUT_URL = "/accounts/logout/" -LOGIN_REDIRECT_URL = "/" - -# ============================================================================== -# Templates -# ============================================================================== +WSGI_APPLICATION = "dpaste.wsgi.application" MIDDLEWARE = [ "django.middleware.csrf.CsrfViewMiddleware", @@ -116,14 +86,8 @@ INSTALLED_APPS = [ "dpaste.apps.dpasteAppConfig", ] -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': 'dev.db', -# 'USER': '', -# 'PASSWORD': '', -# } -# } +DATABASE_URL = env("DATABASE_URL", "sqlite:///dpaste.sqlite") +DATABASES = {"default": dj_database_url.config(DATABASE_URL)} # ============================================================================== # App specific settings diff --git a/dpaste/settings/tests.py b/dpaste/settings/tests.py index 5febd79..6c3fe0e 100644 --- a/dpaste/settings/tests.py +++ b/dpaste/settings/tests.py @@ -1,17 +1,10 @@ """ -Settings for the test suite +Settings for the testsuite runs. """ -import django - -from .base import * +from .base import * # noqa SECRET_KEY = "test-key" DATABASES = { "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"} } - -# Drop CSP middleware for Django 3.0 until it was fixed upstream -# https://github.com/mozilla/django-csp/issues/129 -if django.get_version().startswith("3."): - MIDDLEWARE.remove("csp.middleware.CSPMiddleware") diff --git a/runtests.py b/runtests.py deleted file mode 100755 index cb56879..0000000 --- a/runtests.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - - -import sys - -from django import setup -from django.conf import settings -from django.test.runner import DiscoverRunner as TestRunner - -from dpaste.settings import tests as test_settings - - -def runtests(*test_args): - # Setup settings - if not settings.configured: - settings.configure(**test_settings.__dict__) - setup() - test_runner = TestRunner(verbosity=1) - failures = test_runner.run_tests(['dpaste']) - if failures: - sys.exit(failures) - -if __name__ == '__main__': - runtests(*sys.argv[1:]) diff --git a/setup.cfg b/setup.cfg index 5a688fe..8595e2d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,11 +28,11 @@ zip_safe = False python_requires = >=3.5 install_requires = # Essential packages - six django>=2.2 pygments>=1.6 django-staticinline>=1.0 django-csp>=3.3 + dj_database_url==0.5.0 # Additional Lexer jsx-lexer==0.0.8 @@ -47,7 +47,7 @@ install_requires = # Extra packages for local development [options.extras_require] -dev = +dev = ipdb isort black @@ -96,4 +96,4 @@ addopts = --cov-append --cov-branch --nomigrations - --reuse-db \ No newline at end of file + --reuse-db