kopia lustrzana https://github.com/jedie/PyInventory
Refactor settings
rodzic
bc761d3624
commit
021bd59c23
3
Makefile
3
Makefile
|
@ -1,5 +1,6 @@
|
|||
SHELL := /bin/bash
|
||||
MAX_LINE_LENGTH := 119
|
||||
export DJANGO_SETTINGS_MODULE ?= inventory_project.settings.local
|
||||
|
||||
help: ## List all commands
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
@ -75,6 +76,8 @@ publish: ## Release new version to PyPi
|
|||
|
||||
|
||||
run-dev-server: ## Run the django dev server in endless loop.
|
||||
./manage.sh collectstatic --noinput --link
|
||||
./manage.sh migrate
|
||||
./manage.sh runserver
|
||||
|
||||
messages: ## Make and compile locales message files
|
||||
|
|
|
@ -84,14 +84,6 @@ restart Restart all containers
|
|||
}}}
|
||||
|
||||
|
||||
=== .env
|
||||
|
||||
Create a {{{.env}}} file, for some settings, e.g.:
|
||||
{{{
|
||||
# enable Django-Debug-Toolbar:
|
||||
ENABLE_DJDT=1
|
||||
}}}
|
||||
|
||||
|
||||
=== local install without docker
|
||||
|
||||
|
@ -179,6 +171,8 @@ Nothing, yet ;)
|
|||
== history
|
||||
|
||||
* [[https://github.com/jedie/PyInventory/compare/v0.2.0...master|compare v0.2.0...master]] **dev**
|
||||
** Remove usage of {{{.env}}} file
|
||||
** split settings for local development and production use
|
||||
** tbc
|
||||
* [[https://github.com/jedie/PyInventory/compare/v0.1.0...v0.2.0|v0.2.0 - 24.10.2020]]
|
||||
** Simplify item change list by nested item
|
||||
|
|
|
@ -11,7 +11,7 @@ services:
|
|||
- "8000:8000"
|
||||
env_file: ./docker/common.env
|
||||
environment:
|
||||
- ENABLE_DJDT=$ENABLE_DJDT
|
||||
- DJANGO_SETTINGS_MODULE=inventory_project.settings.local_docker
|
||||
links:
|
||||
- postgres:postgres
|
||||
depends_on:
|
||||
|
|
|
@ -15,5 +15,4 @@ class InventoryConfig(AppConfig):
|
|||
verbose_name = "Inventory"
|
||||
|
||||
def ready(self):
|
||||
import inventory.checks # noqa
|
||||
import inventory.signals # noqa
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
from pathlib import Path
|
||||
|
||||
from django.core.checks import Error, register
|
||||
|
||||
|
||||
@register()
|
||||
def inventory_checks(app_configs, **kwargs):
|
||||
errors = []
|
||||
if not Path('.env').is_file():
|
||||
errors.append(
|
||||
Error(
|
||||
'No ".env" file found!',
|
||||
hint='Create a ".env" file. See README for details',
|
||||
id='pyinventory.E001',
|
||||
)
|
||||
)
|
||||
return errors
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
Just print version line on every call from commandline ;)
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from django import __version__ as django_version
|
||||
|
@ -12,3 +12,4 @@ from inventory import __version__
|
|||
if __name__ == 'inventory_project':
|
||||
if '--version' not in sys.argv:
|
||||
print(f'PyInventory v{__version__} (Django v{django_version})', file=sys.stderr)
|
||||
print(f'DJANGO_SETTINGS_MODULE={os.environ["DJANGO_SETTINGS_MODULE"]!r}', file=sys.stderr)
|
||||
|
|
|
@ -1,31 +1,15 @@
|
|||
"""
|
||||
Django settings
|
||||
Base Django settings
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os as __os
|
||||
import sys as __sys
|
||||
from pathlib import Path as __Path
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
print(f'Use settings: {__file__!r}', file=__sys.stderr)
|
||||
|
||||
|
||||
# Build paths inside the project:
|
||||
BASE_PATH = __Path(__file__).resolve().parent.parent
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'TODO: Read secret.txt ;)'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
# Required for the debug toolbar to be displayed:
|
||||
INTERNAL_IPS = ('127.0.0.1', '0.0.0.0', 'localhost')
|
||||
|
||||
ALLOWED_HOSTS = INTERNAL_IPS
|
||||
BASE_PATH = __Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
|
||||
# Application definition
|
||||
|
@ -84,42 +68,6 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
if DEBUG:
|
||||
# Disable caches:
|
||||
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
|
||||
|
||||
|
||||
if 'DB_HOST' in __os.environ:
|
||||
# docker-compose usage with postgres database
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': __os.environ['DB_NAME'],
|
||||
'USER': __os.environ['DB_USER'],
|
||||
'PASSWORD': __os.environ['DB_PASS'],
|
||||
'HOST': __os.environ['DB_HOST'],
|
||||
'PORT': __os.environ['DB_PORT'],
|
||||
'DEBUG_NAME': 'default',
|
||||
'CONN_MAX_AGE': 600,
|
||||
},
|
||||
}
|
||||
else:
|
||||
# local run with SQLite
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': str(__Path(BASE_PATH.parent, 'PyInventory-database.sqlite3')),
|
||||
# 'NAME': ':memory:'
|
||||
# https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors
|
||||
'timeout': 30,
|
||||
}
|
||||
}
|
||||
print(f'Use Database: {DATABASES["default"]["NAME"]!r}', file=__sys.stderr)
|
||||
|
||||
# _____________________________________________________________________________
|
||||
# Internationalization
|
||||
|
||||
|
@ -152,29 +100,6 @@ MEDIA_ROOT = str(__Path(BASE_PATH, 'media'))
|
|||
DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
|
||||
DBBACKUP_STORAGE_OPTIONS = {'location': str(__Path(BASE_PATH, 'backups'))}
|
||||
|
||||
# _____________________________________________________________________________
|
||||
# Django-Debug-Toolbar
|
||||
|
||||
ENABLE_DJDT = __os.environ.get('ENABLE_DJDT') in ('true', '1')
|
||||
if ENABLE_DJDT:
|
||||
print('Enable Django-Debug-Toolbar')
|
||||
INSTALLED_APPS += ['debug_toolbar']
|
||||
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
|
||||
|
||||
DEBUG_TOOLBAR_PATCH_SETTINGS = True
|
||||
from debug_toolbar.settings import CONFIG_DEFAULTS as DEBUG_TOOLBAR_CONFIG # noqa
|
||||
|
||||
# Disable some more panels that will slow down the page:
|
||||
DEBUG_TOOLBAR_CONFIG['DISABLE_PANELS'].add('debug_toolbar.panels.sql.SQLPanel')
|
||||
DEBUG_TOOLBAR_CONFIG['DISABLE_PANELS'].add('debug_toolbar.panels.cache.CachePanel')
|
||||
|
||||
# don't load jquery from ajax.googleapis.com, just use django's version:
|
||||
DEBUG_TOOLBAR_CONFIG['JQUERY_URL'] = STATIC_URL + 'admin/js/vendor/jquery/jquery.min.js'
|
||||
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_TEMPLATE_CONTEXT'] = True
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_COLLAPSED'] = True # Show toolbar collapsed by default.
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_TOOLBAR_CALLBACK'] = 'inventory_project.middlewares.djdt_show'
|
||||
|
||||
# _____________________________________________________________________________
|
||||
# django-ckeditor
|
||||
|
||||
|
@ -218,10 +143,10 @@ TAGULOUS_SLUG_TRUNCATE_UNIQUE = 5
|
|||
TAGULOUS_SLUG_ALLOW_UNICODE = False
|
||||
|
||||
SERIALIZATION_MODULES = {
|
||||
'xml': 'tagulous.serializers.xml_serializer',
|
||||
'json': 'tagulous.serializers.json',
|
||||
'xml': 'tagulous.serializers.xml_serializer',
|
||||
'json': 'tagulous.serializers.json',
|
||||
'python': 'tagulous.serializers.python',
|
||||
'yaml': 'tagulous.serializers.pyyaml',
|
||||
'yaml': 'tagulous.serializers.pyyaml',
|
||||
}
|
||||
|
||||
# _____________________________________________________________________________
|
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
Django settings for local development
|
||||
"""
|
||||
import sys as __sys
|
||||
from pathlib import Path as __Path
|
||||
|
||||
from inventory_project.settings.base import * # noqa
|
||||
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
# Disable caches:
|
||||
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
|
||||
|
||||
# Required for the debug toolbar to be displayed:
|
||||
INTERNAL_IPS = ('127.0.0.1', '0.0.0.0', 'localhost')
|
||||
|
||||
ALLOWED_HOSTS = INTERNAL_IPS
|
||||
|
||||
SECRET_KEY = 'no secret for local development'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': str(__Path(BASE_PATH.parent, 'PyInventory-database.sqlite3')),
|
||||
# 'NAME': ':memory:'
|
||||
# https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors
|
||||
'timeout': 30,
|
||||
}
|
||||
}
|
||||
print(f'Use Database: {DATABASES["default"]["NAME"]!r}', file=__sys.stderr)
|
||||
|
||||
# _____________________________________________________________________________
|
||||
# Django-Debug-Toolbar
|
||||
|
||||
INSTALLED_APPS += ['debug_toolbar']
|
||||
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
|
||||
|
||||
DEBUG_TOOLBAR_PATCH_SETTINGS = True
|
||||
from debug_toolbar.settings import CONFIG_DEFAULTS as DEBUG_TOOLBAR_CONFIG # noqa
|
||||
|
||||
|
||||
# Disable some more panels that will slow down the page:
|
||||
DEBUG_TOOLBAR_CONFIG['DISABLE_PANELS'].add('debug_toolbar.panels.sql.SQLPanel')
|
||||
DEBUG_TOOLBAR_CONFIG['DISABLE_PANELS'].add('debug_toolbar.panels.cache.CachePanel')
|
||||
|
||||
# don't load jquery from ajax.googleapis.com, just use django's version:
|
||||
DEBUG_TOOLBAR_CONFIG['JQUERY_URL'] = STATIC_URL + 'admin/js/vendor/jquery/jquery.min.js'
|
||||
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_TEMPLATE_CONTEXT'] = True
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_COLLAPSED'] = True # Show toolbar collapsed by default.
|
||||
DEBUG_TOOLBAR_CONFIG['SHOW_TOOLBAR_CALLBACK'] = 'inventory_project.middlewares.djdt_show'
|
|
@ -0,0 +1,20 @@
|
|||
"""
|
||||
Django settings for local development with docker-compose usage
|
||||
"""
|
||||
import os as __os
|
||||
|
||||
from inventory_project.settings.local import * # noqa
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': __os.environ['DB_NAME'],
|
||||
'USER': __os.environ['DB_USER'],
|
||||
'PASSWORD': __os.environ['DB_PASS'],
|
||||
'HOST': __os.environ['DB_HOST'],
|
||||
'PORT': __os.environ['DB_PORT'],
|
||||
'DEBUG_NAME': 'default',
|
||||
'CONN_MAX_AGE': 600,
|
||||
},
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
Django settings for production usage
|
||||
"""
|
||||
import os as __os
|
||||
from pathlib import Path as __Path
|
||||
|
||||
from inventory_project.settings.base import * # noqa
|
||||
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
|
||||
INTERNAL_IPS = ()
|
||||
|
||||
ALLOWED_HOSTS = ('domain.tld',) # TODO
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = __Path('secret.txt').resolve().open('r').read().strip()
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': __os.environ['DB_NAME'],
|
||||
'USER': __os.environ['DB_USER'],
|
||||
'PASSWORD': __os.environ['DB_PASS'],
|
||||
'HOST': __os.environ['DB_HOST'],
|
||||
'PORT': __os.environ['DB_PORT'],
|
||||
'DEBUG_NAME': 'default',
|
||||
'CONN_MAX_AGE': 600,
|
||||
},
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
from django.conf import settings
|
||||
from django.conf.urls import include, static, url
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from inventory_project import settings
|
||||
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
WSGI config
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "inventory_project.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
|
|
@ -5,7 +5,7 @@ import sys
|
|||
|
||||
|
||||
def main():
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'inventory_project.settings'
|
||||
assert 'DJANGO_SETTINGS_MODULE' in os.environ, 'No "DJANGO_SETTINGS_MODULE" in environment!'
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
|
Ładowanie…
Reference in New Issue