Further cleanup along settings and debris.

This commit is contained in:
Martin Mahner 2019-12-07 09:38:07 +01:00
parent 27ff3fb89e
commit dc3e797be8
6 changed files with 22 additions and 94 deletions

3
.env
View file

@ -1,3 +0,0 @@
APPNAME = dpaste
DJANGO_SETTINGS_MODULE=dpaste.settings.local

View file

@ -5,7 +5,6 @@ from django.apps import apps
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from six import python_2_unicode_compatible
from dpaste import highlight from dpaste import highlight
@ -39,7 +38,6 @@ def generate_secret_id(length):
return generate_secret_id(length=length + 1) return generate_secret_id(length=length + 1)
@python_2_unicode_compatible
class Snippet(models.Model): class Snippet(models.Model):
EXPIRE_TIME = 1 EXPIRE_TIME = 1
EXPIRE_KEEP = 2 EXPIRE_KEEP = 2

View file

@ -1,53 +1,33 @@
# ==============================================================================
# Import global settings to make it easier to extend settings. # Import global settings to make it easier to extend settings.
# ============================================================================== # ==============================================================================
# Calculation of directories relative to the module location
# ==============================================================================
import os import os
import sys
from django.conf.global_settings import *
import dpaste 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__)) 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 SITE_ID = 1
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = "" SECRET_KEY = env("SECRET_KEY", "")
ALLOWED_HOSTS = ["*"] ALLOWED_HOSTS = env("ALLOWED_HOSTS", "*").split(",")
# ==============================================================================
# I18N
# ==============================================================================
TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
USE_L10N = False USE_L10N = True
USE_TZ = True
LANGUAGE_CODE = "en" LANGUAGE_CODE = "en"
LANGUAGES = (("en", "English"),) LANGUAGES = (("en", "English"),)
@ -56,10 +36,6 @@ LANGUAGES = (("en", "English"),)
# os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')), # os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')),
# ) # )
# ==============================================================================
# Project URLS and media settings
# ==============================================================================
STATICFILES_STORAGE = ( STATICFILES_STORAGE = (
"django.contrib.staticfiles.storage.ManifestStaticFilesStorage" "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
) )
@ -69,20 +45,14 @@ STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.AppDirectoriesFinder", "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/" STATIC_URL = "/static/"
ADMIN_MEDIA_PREFIX = "/static/admin/"
ROOT_URLCONF = "dpaste.urls" ROOT_URLCONF = "dpaste.urls"
LOGIN_URL = "/accounts/login/" WSGI_APPLICATION = "dpaste.wsgi.application"
LOGOUT_URL = "/accounts/logout/"
LOGIN_REDIRECT_URL = "/"
# ==============================================================================
# Templates
# ==============================================================================
MIDDLEWARE = [ MIDDLEWARE = [
"django.middleware.csrf.CsrfViewMiddleware", "django.middleware.csrf.CsrfViewMiddleware",
@ -116,14 +86,8 @@ INSTALLED_APPS = [
"dpaste.apps.dpasteAppConfig", "dpaste.apps.dpasteAppConfig",
] ]
# DATABASES = { DATABASE_URL = env("DATABASE_URL", "sqlite:///dpaste.sqlite")
# 'default': { DATABASES = {"default": dj_database_url.config(DATABASE_URL)}
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': 'dev.db',
# 'USER': '',
# 'PASSWORD': '',
# }
# }
# ============================================================================== # ==============================================================================
# App specific settings # App specific settings

View file

@ -1,17 +1,10 @@
""" """
Settings for the test suite Settings for the testsuite runs.
""" """
import django from .base import * # noqa
from .base import *
SECRET_KEY = "test-key" SECRET_KEY = "test-key"
DATABASES = { DATABASES = {
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"} "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")

View file

@ -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:])

View file

@ -28,11 +28,11 @@ zip_safe = False
python_requires = >=3.5 python_requires = >=3.5
install_requires = install_requires =
# Essential packages # Essential packages
six
django>=2.2 django>=2.2
pygments>=1.6 pygments>=1.6
django-staticinline>=1.0 django-staticinline>=1.0
django-csp>=3.3 django-csp>=3.3
dj_database_url==0.5.0
# Additional Lexer # Additional Lexer
jsx-lexer==0.0.8 jsx-lexer==0.0.8
@ -47,7 +47,7 @@ install_requires =
# Extra packages for local development # Extra packages for local development
[options.extras_require] [options.extras_require]
dev = dev =
ipdb ipdb
isort isort
black black
@ -96,4 +96,4 @@ addopts =
--cov-append --cov-append
--cov-branch --cov-branch
--nomigrations --nomigrations
--reuse-db --reuse-db