Commit bdf41676 authored by chris's avatar chris

mysite/common_settings.py: refactor default settings 1/2

parent 4ab777e9
......@@ -46,53 +46,57 @@ MEDIA_URL = "%s%s%s" % (os.sep, "media", os.sep)
STATIC_ROOT = os.path.join(PROJECT_DIR, "collect-static")
DJANGO_SETTINGS_SITE_NAME = os.path.split(PROJECT_DIR)[-1]
config = configparser.RawConfigParser(allow_no_value=True)
conf_file_name = '%s%s%s.ini' % (
PROJECT_DIR,
os.sep,
DJANGO_SETTINGS_SITE_NAME
)
try:
# Open the file with the correct encoding
with codecs.open(conf_file_name, 'r', encoding='utf-8') as f:
config.readfp(f)
DJANGO_SETTINGS_ADMIN_EMAIL = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ADMIN_EMAIL')
DJANGO_SETTINGS_ADMIN_NAME = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ADMIN_NAME')
DJANGO_SETTINGS_DATABASE_HOST = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_HOST')
DJANGO_SETTINGS_DATABASE_NAME = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_NAME')
DJANGO_SETTINGS_DATABASE_PASSWORD = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_PASSWORD')
DJANGO_SETTINGS_DATABASE_PORT = config.getint('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_PORT')
DJANGO_SETTINGS_DATABASE_USER = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_USER')
DJANGO_SETTINGS_DEBUG = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DEBUG')
DJANGO_SETTINGS_DEMO = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DEMO')
DJANGO_SETTINGS_EMAIL_HOST = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST')
DJANGO_SETTINGS_EMAIL_HOST_PASSWORD = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST_PASSWORD')
DJANGO_SETTINGS_EMAIL_HOST_USER = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST_USER')
DJANGO_SETTINGS_EMAIL_PORT = config.getint('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_PORT')
DJANGO_SETTINGS_EMAIL_USE_SSL = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_USE_TLS')
DJANGO_SETTINGS_EMAIL_USE_TLS = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_USE_TLS')
DJANGO_SETTINGS_ENV = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ENV')
DJANGO_SETTINGS_LANGUAGE = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_LANGUAGE')
DJANGO_SETTINGS_LOGGING = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_LOGGING')
DJANGO_SETTINGS_CACHE = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_CACHE')
DJANGO_SETTINGS_SESSION = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_SESSION')
DJANGO_SETTINGS_COUNTRY = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_COUNTRY')
DJANGO_SETTINGS_IS_MINIMALIST = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_IS_MINIMALIST')
DJANGO_STATIC = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_STATIC')
DJANGO_SETTINGS_ALLOWED_HOSTS = []
for name in config.options('ALLOWED_HOSTS'):
allowed_host = config.get('ALLOWED_HOSTS', name)
if allowed_host.startswith("demo"):
DJANGO_SETTINGS_DEMO = True
DJANGO_SETTINGS_ALLOWED_HOSTS.append(allowed_host)
logging.info("Settings loaded from %s" % (conf_file_name,))
print ("Settings loaded from %s" % (conf_file_name,))
print(DJANGO_SETTINGS_ALLOWED_HOSTS)
DJANGO_SETTINGS_ALLOWED_MAIL_EXTENSION = get_allowed_mail_extension()
except IOError:
logging.exception("Unable to open %s settings" % (conf_file_name,))
print ("Unable to open %s settings" % (conf_file_name,))
raise SystemExit(-1)
DJANGO_SETTINGS_ADMIN_EMAIL = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ADMIN_EMAIL')
DJANGO_SETTINGS_ADMIN_NAME = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ADMIN_NAME')
DJANGO_SETTINGS_DATABASE_HOST = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_HOST')
DJANGO_SETTINGS_DATABASE_NAME = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_NAME')
DJANGO_SETTINGS_DATABASE_PASSWORD = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_PASSWORD')
DJANGO_SETTINGS_DATABASE_PORT = config.getint('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_PORT')
DJANGO_SETTINGS_DATABASE_USER = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DATABASE_USER')
DJANGO_SETTINGS_DEBUG = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DEBUG')
DJANGO_SETTINGS_DEMO = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_DEMO')
DJANGO_SETTINGS_EMAIL_HOST = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST')
DJANGO_SETTINGS_EMAIL_HOST_PASSWORD = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST_PASSWORD')
DJANGO_SETTINGS_EMAIL_HOST_USER = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_HOST_USER')
DJANGO_SETTINGS_EMAIL_PORT = config.getint('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_PORT')
DJANGO_SETTINGS_EMAIL_USE_SSL = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_USE_TLS')
DJANGO_SETTINGS_EMAIL_USE_TLS = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_EMAIL_USE_TLS')
DJANGO_SETTINGS_ENV = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_ENV')
DJANGO_SETTINGS_LANGUAGE = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_LANGUAGE')
DJANGO_SETTINGS_LOGGING = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_LOGGING')
DJANGO_SETTINGS_CACHE = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_CACHE')
DJANGO_SETTINGS_SESSION = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_SESSION')
DJANGO_SETTINGS_COUNTRY = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_COUNTRY')
DJANGO_SETTINGS_IS_MINIMALIST = config.getboolean('DJANGO_SETTINGS', 'DJANGO_SETTINGS_IS_MINIMALIST')
DJANGO_STATIC = config.get('DJANGO_SETTINGS', 'DJANGO_SETTINGS_STATIC')
DJANGO_SETTINGS_ALLOWED_HOSTS = []
for name in config.options('ALLOWED_HOSTS'):
allowed_host = config.get('ALLOWED_HOSTS', name)
if allowed_host.startswith("demo"):
DJANGO_SETTINGS_DEMO = True
DJANGO_SETTINGS_ALLOWED_HOSTS.append(allowed_host)
logging.info("Settings loaded from %s" % (conf_file_name,))
print ("Settings loaded from %s" % (conf_file_name,))
print(DJANGO_SETTINGS_ALLOWED_HOSTS)
DJANGO_SETTINGS_ALLOWED_MAIL_EXTENSION = get_allowed_mail_extension()
DJANGO_SETTINGS_DATE = "%d-%m-%Y"
DJANGO_SETTINGS_DATETIME = "%d-%m-%Y %H:%M"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment