diff --git a/.gitignore b/.gitignore index 8b7ba6c73ab49ff8a8b0ce66115896aa6624e68f..3954c81843b91c1c4f278e2e9900b7d926340391 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ build/ dist/ venv/ -helloworld.db -helloworld/settings/private.py +db.sqlite3 +helloworld/settings/prod.py +helloworld/settings/dev.py diff --git a/helloworld/settings/__init__.py b/helloworld/settings/__init__.py index 523517dab0afd258eba63b262cb2f87ee0f92654..f89d07a5592465393c1a4c14e49eba6251772baf 100644 --- a/helloworld/settings/__init__.py +++ b/helloworld/settings/__init__.py @@ -1,5 +1,17 @@ -from helloworld.settings.common import * -from helloworld.settings.logging import * +from .common import * -# this comes after all other settings (since private settings will override several values) -from helloworld.settings.private import * +try: + from .prod import * + _PRODUCTION = True + assert DEBUG is False, "DEBUG in development?!" +except ImportError: + _PRODUCTION = False + +try: + from .dev import * + _DEVELOPMENT = True +except ImportError: + _DEVELOPMENT = False + + +assert _DEVELOPMENT ^ _PRODUCTION, "Bad settings: development {0}, production {1}".format(_DEVELOPMENT, _PRODUCTION) \ No newline at end of file diff --git a/helloworld/settings/common.py b/helloworld/settings/common.py index 6dba931962a316c37db49c35dcbf8db54128ac35..8cf7f9139bfc3f1e104233680d97a04434035ad7 100644 --- a/helloworld/settings/common.py +++ b/helloworld/settings/common.py @@ -2,6 +2,9 @@ # Django settings for helloworld project. import os +import sys + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ADMINS = ( # ('Your Name', 'your_email@example.com'), @@ -9,6 +12,15 @@ ADMINS = ( MANAGERS = ADMINS +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles' +) + # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. @@ -99,15 +111,47 @@ TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), "templates"), ) -INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - # Uncomment the next line to enable the admin: - 'django.contrib.admin', - # Uncomment the next line to enable admin documentation: - 'django.contrib.admindocs', -) +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'with_timestamp': { + 'format': '[%(asctime)s %(levelname).3s %(process)d] %(message)s', + 'datefmt': '%Y-%m-%d %H:%M:%S', + }, + }, + 'handlers': { + 'console': { + 'stream': sys.stdout, + 'level': 'INFO', + 'class': 'logging.StreamHandler', + 'formatter': 'with_timestamp' + }, + }, + 'loggers': { + '': { + 'handlers': ['console'], + 'level': 'DEBUG' + }, + 'django': { + 'level': 'WARNING', + 'handlers': ['console'], + 'propagate': False, + }, + 'django.db': { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + }, + 'pika': { + 'level': 'WARNING', + 'handlers': ['console'], + 'propagate': False, + }, + 'pikatasks': { + 'level': 'INFO', + 'handlers': ['console'], + 'propagate': False, + }, + } +} \ No newline at end of file diff --git a/helloworld/settings/dev_example.py b/helloworld/settings/dev_example.py new file mode 100644 index 0000000000000000000000000000000000000000..eb6a1c1d7917fd8cb3b72087cec5f7b51bfff4b2 --- /dev/null +++ b/helloworld/settings/dev_example.py @@ -0,0 +1,46 @@ +from .common import * + + +DEBUG = True + + +SECRET_KEY = str(getattr(os.uname(), "nodename")) + + +ALLOWED_HOSTS = ["127.0.0.1", "localhost"] + + +SESSION_COOKIE_SECURE = False + + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "../db.sqlite3"), + } +} + + +LOGGING["handlers"]["console"]["level"] = "DEBUG" + + +PIKATASKS_BROKER_HOST = "localhost" +PIKATASKS_VIRTUAL_HOST = "idm" +PIKATASKS_SSL_ENABLED = False +PIKATASKS_BROKER_PORT = 5672 # No TLS/SSL + +PIKATASKS_USERNAME = "accountmgr" +PIKATASKS_PASSWORD = "" +PIKATASKS_CLIENT_EXCHANGE_NAME = "" + + +try: # Colored logger CaaS. Auto downloaded and verified. + import os + import hashlib + from urllib import request + cache, url = "/tmp/_colored_logger.py", "https://lab.it.hs-hannover.de/lukyanch/pydevutils/raw/fa4af6555a8eb996e1be158ca12691de9b33ba45/colored_logger.py" + code = bool(os.path.exists(cache) or request.urlretrieve(url, cache)) and open(cache, "r").read() + assert hashlib.sha256(code.encode()).hexdigest() == "d4d261a40f95733f9fb184fc4ccb55d007b880cb62c8d6a06824d43eeb1391ac", "unrecognized content in " + cache + exec(code) +except Exception as e: + print("No colored logger: {e.__class__.__name__}: {e}".format(e=e)) diff --git a/helloworld/settings/private.example.py b/helloworld/settings/private.example.py deleted file mode 100644 index db867dbb81ae41ad58056b7cf016b4827185e1b5..0000000000000000000000000000000000000000 --- a/helloworld/settings/private.example.py +++ /dev/null @@ -1,13 +0,0 @@ -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'helloworld.db', # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. - } -} - -# Make this unique, and don't share it with anybody. -SECRET_KEY = '0h@p1(0e%*b9r4k+dnpc+7s18lpap6+=cu^#^d=hll+38zv_)r' diff --git a/helloworld/settings/prod_example.py b/helloworld/settings/prod_example.py new file mode 100644 index 0000000000000000000000000000000000000000..313e729b60f8318890830132263110f002cc8e0c --- /dev/null +++ b/helloworld/settings/prod_example.py @@ -0,0 +1,12 @@ +SECRET_KEY = r"" + + +ALLOWED_HOSTS = [] + + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + } +} diff --git a/helloworld/urls.py b/helloworld/urls.py index fcae7dd27b1ba00d83fa33e3ee504f78601a96cb..d16df743c483afa0b6f6522a41940497e0290cbe 100644 --- a/helloworld/urls.py +++ b/helloworld/urls.py @@ -1,29 +1,9 @@ # -*- coding: utf-8 -*- -from django.conf.urls import patterns, include -from django.conf import settings +from django.conf.urls import url +from .views import index -# Uncomment the next two lines to enable the admin: -from django.contrib import admin -admin.autodiscover() - -urlpatterns = patterns('', - # Example: - # (r'^helloworld/', include('helloworld.foo.urls')), - - # Uncomment the admin/doc line below to enable admin documentation: - (r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - (r'^admin/', include(admin.site.urls)), - - # Hello, world! - (r'', 'helloworld.views.index'), +urlpatterns = ( + url(r'', index), ) -if settings.DEBUG: - urlpatterns += patterns('', - (r'^media/(?P<path>.*)$', 'django.views.static.serve', - {'document_root': settings.MEDIA_ROOT}), - ) - diff --git a/requirements.txt b/requirements.txt index 9607b39557ac52a13d5582c2b86efb3f16134018..3439e9956406cdd31ed6ee06dfae6ba1717a8a7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ # requirements.txt - -Django==1.9.4 \ No newline at end of file +Django>=2.2,<2.3 \ No newline at end of file