update django generate local settings os that it copies over internally generated values from the project files rather than directly connecting. this means ALL projects need to be updated wihenever project configuraiton settings are changed

This commit is contained in:
Ronny Abraham 2019-02-09 23:48:04 +02:00
parent 8cc2e9a101
commit 16f43982a0
3 changed files with 99 additions and 52 deletions

View file

@ -328,6 +328,51 @@ def generate_scripts(template_name, make_copy=False):
project_name=project_name)
build_name = "%s.py" % project_branch
# add extra local specfic context variables
# NOTE:
# if you change project settings, you MUST run generate
context['paths_django_templates'] = \
configuration.paths.django.templates
context['server_database_backend'] = \
configuration.server.database.backend
context['server_database_name'] = configuration.server.database.name
context['server_database_user'] = configuration.server.database.user
context['server_database_password'] = \
configuration.server.database.password
context['server_database_host'] = configuration.server.database.host
context['server_database_port'] = configuration.server.database.port
context['paths_server_media_static'] = \
configuration.paths.server.media.static
context['paths_server_media_dynamic'] = \
configuration.paths.server.media.dynamic
context['paths_project_root'] = configuration.paths.project.root
context['project_django_allowedhosts'] = \
configuration.project.django.allowedhosts
# convenience variable naming, otherwise it's too long to deal with
file_debug_handler = configuration.logging.django.handlers.file_debug
context['file_debug_handler__name_project'] = \
file_debug_handler.name.project
context['file_debug_handler__path_project'] = \
file_debug_handler.path.project
context['file_debug_handler__name_server'] = \
file_debug_handler.name.server
context['file_debug_handler__path_server'] = \
file_debug_handler.path.server
copy_full_path = "{copy_path}/{build_name}".format(
copy_path=copy_path, build_name=build_name)

View file

@ -1,19 +1,20 @@
# this file contains settings that are automatically generated
# put custom commands/ imports in a separate file!
LOCAL_SETTINGS = True # avoid recursive imports
BRANCH = '{{ project_branch }}'
from {{ project_name }}.settings import *
from modules import initialize
import logging
LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH
logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG)
configuration = initialize.environment(BRANCH)
SITE_ID = 1
TEMPLATES[0]['DIRS'].append(configuration.paths.django.templates)
TEMPLATES[0]['DIRS'].append(
"{{paths_django_templates}}")
#
# NOTE: a lot of the code in these local settings files are automated and you
@ -26,16 +27,13 @@ TEMPLATES[0]['DIRS'].append(configuration.paths.django.templates)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.{db_backend}'.format(
db_backend=configuration.server.database.backend),
db_backend='{{server_database_backend}}'),
'NAME': '{db_name}'.format(db_name=configuration.server.database.name),
'USER': '{db_user}'.format(db_user=configuration.server.database.user),
'PASSWORD': '{db_pass}'.format(
db_pass=configuration.server.database.password),
'HOST': '{db_host}'.format(db_host=configuration.server.database.host),
'PORT': '{db_port}'.format(db_port=configuration.server.database.port),
'NAME': '{db_name}'.format(db_name='{{server_database_name}}'),
'USER': '{db_user}'.format(db_user='{{server_database_user}}'),
'PASSWORD': '{db_pass}'.format(db_pass='{{server_database_password}}'),
'HOST': '{db_host}'.format(db_host='{{server_database_host}}'),
'PORT': '{db_port}'.format(db_port='{{server_database_port}}'),
}
}
@ -51,15 +49,15 @@ DATABASES = {
# MEDIA_ROOT is the dynamic media information that the web server, user or
# admin # will be adding and taking out. It's why I call it "dynamic"
STATIC_ROOT = configuration.paths.server.media.static
MEDIA_ROOT = configuration.paths.server.media.dynamic
STATIC_ROOT = '{{paths_server_media_static}}'
MEDIA_ROOT = '{{paths_server_media_dynamic}}'
# directories from which we search for static files to place in STATIC_ROOT
# these static files are located within the project root as opposed to the
# server root location
STATICFILES_DIRS = (
os.path.join(configuration.paths.project.root, "share", "media"),
os.path.join("{{paths_project_root}}", "share", "media"),
)
# debug and debug toolbar settings
@ -70,14 +68,11 @@ USE_DEBUG_TOOLBAR = DEBUG
# allow template debug outputs on {{ project_branch }} environment
INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ]
ALLOWED_HOSTS = configuration.project.django.allowedhosts
ALLOWED_HOSTS = {{ project_django_allowedhosts }}
# -----------------------------------------
# Debug logging to the console
# convenience variable naming, otherwise it's too long to deal with
file_debug_handler = configuration.logging.django.handlers.file_debug
LOGGING = {
'version': 1,
'formatters': {
@ -94,17 +89,23 @@ LOGGING = {
},
},
'handlers': {
file_debug_handler.name.project: {
'{{ file_debug_handler__name_project }}': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': file_debug_handler.path.project,
'filename':
'{{file_debug_handler__path_project}}',
'formatter': 'code'
},
file_debug_handler.name.server: {
'{{ file_debug_handler__name_server }}': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': file_debug_handler.path.server,
'filename':
'{{file_debug_handler__path_server}}',
'formatter': 'code'
},
@ -124,8 +125,8 @@ LOGGING = {
'handlers':
[
'console',
file_debug_handler.name.project,
file_debug_handler.name.server
'{{ file_debug_handler__name_project }}',
'{{ file_debug_handler__name_server }}',
],
'level': 'DEBUG',

View file

@ -1,19 +1,20 @@
# this file contains settings that are automatically generated
# put custom commands/ imports in a separate file!
LOCAL_SETTINGS = True # avoid recursive imports
BRANCH = '{{ project_branch }}'
from {{ project_name }}.settings import *
from modules import initialize
import logging
LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH
logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG)
configuration = initialize.environment(BRANCH)
SITE_ID = 1
TEMPLATES[0]['DIRS'].append(configuration.paths.django.templates)
TEMPLATES[0]['DIRS'].append(
"{{paths_django_templates}}")
#
# NOTE: a lot of the code in these local settings files are automated and you
@ -26,16 +27,13 @@ TEMPLATES[0]['DIRS'].append(configuration.paths.django.templates)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.{db_backend}'.format(
db_backend=configuration.server.database.backend),
db_backend='{{server_database_backend}}'),
'NAME': '{db_name}'.format(db_name=configuration.server.database.name),
'USER': '{db_user}'.format(db_user=configuration.server.database.user),
'PASSWORD': '{db_pass}'.format(
db_pass=configuration.server.database.password),
'HOST': '{db_host}'.format(db_host=configuration.server.database.host),
'PORT': '{db_port}'.format(db_port=configuration.server.database.port),
'NAME': '{db_name}'.format(db_name='{{server_database_name}}'),
'USER': '{db_user}'.format(db_user='{{server_database_user}}'),
'PASSWORD': '{db_pass}'.format(db_pass='{{server_database_password}}'),
'HOST': '{db_host}'.format(db_host='{{server_database_host}}'),
'PORT': '{db_port}'.format(db_port='{{server_database_port}}'),
}
}
@ -51,15 +49,15 @@ DATABASES = {
# MEDIA_ROOT is the dynamic media information that the web server, user or
# admin # will be adding and taking out. It's why I call it "dynamic"
STATIC_ROOT = configuration.paths.server.media.static
MEDIA_ROOT = configuration.paths.server.media.dynamic
STATIC_ROOT = '{{paths_server_media_static}}'
MEDIA_ROOT = '{{paths_server_media_dynamic}}'
# directories from which we search for static files to place in STATIC_ROOT
# these static files are located within the project root as opposed to the
# server root location
STATICFILES_DIRS = (
os.path.join(configuration.paths.project.root, "share", "media"),
os.path.join("{{paths_project_root}}", "share", "media"),
)
# debug and debug toolbar settings
@ -70,14 +68,11 @@ USE_DEBUG_TOOLBAR = DEBUG
# allow template debug outputs on {{ project_branch }} environment
INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ]
ALLOWED_HOSTS = configuration.project.allowedhosts
ALLOWED_HOSTS = {{ project_django_allowedhosts }}
# -----------------------------------------
# Debug logging to the console
# convenience variable naming, otherwise it's too long to deal with
file_debug_handler = configuration.logging.django.handlers.file_debug
LOGGING = {
'version': 1,
'formatters': {
@ -94,17 +89,23 @@ LOGGING = {
},
},
'handlers': {
file_debug_handler.name.project: {
'{{ file_debug_handler__name_project }}': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': file_debug_handler.path.project,
'filename':
'{{file_debug_handler__path_project}}',
'formatter': 'code'
},
file_debug_handler.name.server: {
'{{ file_debug_handler__name_server }}': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': file_debug_handler.path.server,
'filename':
'{{file_debug_handler__path_server}}',
'formatter': 'code'
},
@ -124,8 +125,8 @@ LOGGING = {
'handlers':
[
'console',
file_debug_handler.name.project,
file_debug_handler.name.server
'{{ file_debug_handler__name_project }}',
'{{ file_debug_handler__name_server }}',
],
'level': 'DEBUG',