diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/.ash_history | 8 | ||||
| -rw-r--r-- | app/app/settings.py | 141 | ||||
| -rw-r--r-- | app/config-compose.yml | 89 | ||||
| -rw-r--r-- | app/config-example.yml | 76 | ||||
| -rwxr-xr-x | app/demo.sh | 14 | ||||
| -rw-r--r-- | app/requirements.txt | 2 | ||||
| -rw-r--r-- | app/uwsgi.ini | 15 |
7 files changed, 106 insertions, 239 deletions
diff --git a/app/.ash_history b/app/.ash_history deleted file mode 100644 index 315e6ea..0000000 --- a/app/.ash_history +++ /dev/null @@ -1,8 +0,0 @@ -ls -pwd -cd -ls -la -pwd -vi manage.py -woami -whoami diff --git a/app/app/settings.py b/app/app/settings.py index d3dca5d..78cd7db 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -11,71 +11,98 @@ https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os -import yaml - -try: - from yaml import CLoader as Loader, CDumper as Dumper -except ImportError: - from yaml import Loader, Dumper - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -def get_default_config(): - if os.path.exists(BASE_DIR + '/config.yml'): - return yaml.load(open(BASE_DIR + '/config.yml').read(), Loader=Loader) - else: - print("Warning: loading example config! Create config.yml Soon!") - return yaml.load(open(BASE_DIR + '/config-example.yml').read(), \ - Loader=Loader) +def getenv(param): + return os.environ.get(param) -CONFIG = {} - -if os.environ.get('CUSTOM_CONFIG'): - try: - fn = "{}/{}".format(BASE_DIR, os.environ.get('CUSTOM_CONFIG')) - CONFIG = yaml.load(open(fn)) - except Exception as e: - print("WARNING: Loading default configuration. \n{}".format(e)) - CONFIG = get_default_config() -else: - CONFIG = get_default_config() - +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = CONFIG['SECRET_KEY'] +if os.environ.get("SECRET_KEY"): + SECRET_KEY = os.environ.get("SECRET_KEY") +else: + # DO *NOT* use this in production + SECRET_KEY = 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = CONFIG['debug'] - -ALLOWED_HOSTS = CONFIG['allowed_hosts'] - -ADMINS = CONFIG['admins'] +DEBUG = True if getenv("DEBUG") == "yes" else False -WEBSITE_URI = CONFIG['website_uri'] -WEB_APP_NAME =CONFIG['application_name'] +try: + ALLOWED_HOSTS = getenv("ALLOWED_HOSTS").split(",") +except Exception: + ALLOWED_HOSTS = ["127.0.0.1", "localhost"] -if CONFIG.get('SET_EMAIL'): - EMAIL_HOST = CONFIG['EMAIL_HOST'] - EMAIL_HOST_PASSWORD = CONFIG['EMAIL_HOST_PASSWORD'] - EMAIL_HOST_USER = CONFIG['EMAIL_HOST_USER'] - EMAIL_PORT = CONFIG['EMAIL_PORT'] - EMAIL_USE_TLS = CONFIG['EMAIL_USE_TLS'] - DEFAULT_FROM_EMAIL = CONFIG['DEFAULT_FROM_EMAIL'] +try: + ADMINS = [] + adm = getenv("ADMINS").split(",") + for person in adm: + ADMINS.append(person.split(":")) +except Exception: + ADMINS = [("bob", "bob@example.com")] + +WEBSITE_URI = getenv("WEBSITE_URI") if getenv("WEBSITE_URI") \ + else "http://localhost:8080" +WEB_APP_NAME = getenv("WEBSITE_APP_NAME") if getenv("WEBSITE_APP_NAME") \ + else "Example dispatch tracker" + +if getenv('USE_EMAIL') == "yes": + EMAIL_HOST = getenv("EMAIL_HOST") + EMAIL_HOST_PASSWORD = getenv("EMAIL_HOST_PASSWORD") + EMAIL_HOST_USER = getenv("EMAIL_HOST_USER") + EMAIL_PORT = getenv("EMAIL_PORT") + EMAIL_USE_TLS = True if getenv("EMAIL_USE_TLS") != "no" else False + DEFAULT_FROM_EMAIL = getenv("DEFAULT_FROM_EMAIL") else: print("WARNING EMAIL SETTINGS NOT APPLIED. CHECK CONFIG") TEMPLATE_VARS = {} -if CONFIG.get('TEMPLATE_VARS'): - TEMPLATE_VARS = CONFIG['TEMPLATE_VARS'] +TEMPLATE_VARS['app_name'] = "Subcontractor Invoicing system Demo" +if getenv('TEMPLATE_VARS'): + templateEnvVars = getenv("TEMPLATE_VARS").split(",") + for suffix in templateEnvVars: + TEMPLATE_VARS[suffix] = getenv("TEMPLATE_VARS_"+suffix) +else: + TEMPLATE_VARS['login_info'] = """ + <p class="flow-text"> + Welcome to a demo Subcontractor Invoicing system. + </p> + <p class="flow-text"> + We can design a system that customized specifically for your + use case. + </p> + <p class="flow-text"> + <a href="https://mitchriedstra.com/resume">Please contact me</a> + if you would like more information. This version has been + specifically designed for a trucking company that continues to + use it more than two years after implementation. + </p> + </p> + <script> + /* Shh, it's a little bit of a hack */ + window.onload = function () { + document.querySelector("#id_username").value="admin@example.com"; + document.querySelector("#id_password").value="password"; + document.querySelector("#id_username").parentElement.parentElement.hidden=true + document.querySelector("#login_register").hidden=true + document.querySelector('.card-title').innerText="Click below to start discovering"; + document.querySelector('#login_submit').parentElement.classList = [ 'center-align' ]; + document.querySelector('#login_submit').parentElement.style = "padding-top: 20px;"; + document.querySelector('#login_submit').value="LOGIN NOW!"; + } + </script> + """ -ACCOUNT_ACTIVATION_DAYS = CONFIG['ACCOUNT_ACTIVATION_DAYS'] +try: + ACCOUNT_ACTIVATION_DAYS = int(getenv("ACCOUNT_ACTIVATION_DAYS")) +except Exception: + ACCOUNT_ACTIVATION_DAYS = 7 AUTH_USER_MODEL = 'dispatchAuth.User' @@ -92,7 +119,6 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'dispatch.apps.DispatchConfig', 'dispatchAuth.apps.DispatchauthConfig', - # 'auditlog', ] MIDDLEWARE = [ @@ -104,7 +130,6 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'dispatch.middleware.LoginRequiredMiddleware', - # 'auditlog.middleware.AuditlogMiddleware', ] ROOT_URLCONF = 'app.urls' @@ -128,12 +153,28 @@ TEMPLATES = [ WSGI_APPLICATION = 'app.wsgi.application' +APP_DB_CONF = {} +if getenv('APP_DB_CONF'): + envVars = getenv("APP_DB_CONF").split(",") + for suffix in envVars: + APP_DB_CONF[suffix] = getenv("APP_DB_CONF_"+suffix) +else: + APP_DB_CONF["ENGINE"] = 'django.db.backends.postgresql' + APP_DB_CONF["NAME"] = 'dispatch' + APP_DB_CONF["USER"] = 'postgres' + APP_DB_CONF["PASSWORD"] = '' + APP_DB_CONF["PORT"] = '5432' + +try: + APP_DB_CONF["PORT"] = int(APP_DB_CONF["PORT"]) +except Exception: + APP_DB_CONF["PORT"] = 5432 # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { - 'default': CONFIG['db_default'] + 'default': APP_DB_CONF # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), @@ -187,7 +228,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' -STATIC_ROOT = CONFIG['static_root'] +STATIC_ROOT = getenv("STATIC_ROOT") if getenv("STATIC_ROOT") else "/static" LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' diff --git a/app/config-compose.yml b/app/config-compose.yml deleted file mode 100644 index f93b76e..0000000 --- a/app/config-compose.yml +++ /dev/null @@ -1,89 +0,0 @@ ---- -# Postgres Example -db_default: - ENGINE: django.db.backends.postgresql - NAME: dispatch - USER: postgres - PASSWORD: - HOST: postgres - PORT: 5432 -# MySQL Example -# db_default: -# ENGINE: django.db.backends.mysql -# NAME: dispatch_test -# USER: dispatch -# PASSWORD: ahB2lee5 -# HOST: 127.0.0.1 -# PORT: 3306 -# Sqlite example. Full path is recommended -# db_default: -# ENGINE: django.db.backends.sqlite3 -# NAME: /home/mitch/scm/dispatch-tracker/app/db.sqlite3 - -allowed_hosts: - - localhost - - 127.0.0.1 - - 172.21.23.2 - -static_root: '/static' - -debug: True - -# CHANGE THIS BEFORE USING IN PRODUCTION -SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' - -# These people will be emailed if debug = false -admins: - - 'bob@example.com' - -application_name: "Yo Momma's Dispatch Tracker" -website_uri: 'http://172.21.23.2:8080' - -ACCOUNT_ACTIVATION_DAYS: 7 - -# Email settings won't be loaded from this file if this is false -SET_EMAIL: False -# Email settings, edit for your needs -EMAIL_HOST: smtp.example.com -EMAIL_HOST_PASSWORD: p@$$w0rd9876543210 -EMAIL_HOST_USER: django@example.com -EMAIL_PORT: 2525 -EMAIL_USE_TLS: True -DEFAULT_FROM_EMAIL: webmaster@localhost - -TEMPLATE_VARS: - app_name: Subcontractor Invoicing System Demo - # login_blurb: Login with "admin@example.com", "password" - login_info: | - <p class="flow-text"> - Welcome to a demo Subcontractor Invoicing system. - </p> - <p class="flow-text"> - We can design a system that customized specifically for your - use case. - </p> - <p class="flow-text"> - <a href="https://mitchriedstra.com/resume">Please contact me</a> - if you would like more information. This version has been - specifically designed for a trucking company that continues to - use it more than two years after implementation. - </p> - </p> - <script> - /* Shh, it's a little bit of a hack */ - window.onload = function () { - document.querySelector("#id_username").value="admin@example.com"; - document.querySelector("#id_password").value="password"; - document.querySelector("#id_username").parentElement.parentElement.hidden=true - document.querySelector("#login_register").hidden=true - document.querySelector('.card-title').innerText="Click below to start discovering"; - document.querySelector('#login_submit').parentElement.classList = [ 'center-align' ]; - document.querySelector('#login_submit').parentElement.style = "padding-top: 20px;"; - document.querySelector('#login_submit').value="LOGIN NOW!"; - } - </script> - - - - - diff --git a/app/config-example.yml b/app/config-example.yml deleted file mode 100644 index dfc0872..0000000 --- a/app/config-example.yml +++ /dev/null @@ -1,76 +0,0 @@ ---- -# Postgres Example -db_default: - ENGINE: django.db.backends.postgresql - NAME: dispatch - USER: postgres - PASSWORD: - HOST: 127.0.0.1 - PORT: 5432 -# MySQL Example -# db_default: -# ENGINE: django.db.backends.mysql -# NAME: dispatch_test -# USER: dispatch -# PASSWORD: ahB2lee5 -# HOST: 127.0.0.1 -# PORT: 3306 -# Sqlite example. Full path is recommended -# db_default: -# ENGINE: django.db.backends.sqlite3 -# NAME: /home/mitch/scm/dispatch-tracker/app/db.sqlite3 - -allowed_hosts: - - localhost - - 127.0.0.1 - -static_root: '/full/path/to/static/root' - -debug: True - -# CHANGE THIS BEFORE USING IN PRODUCTION -SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' - -# These people will be emailed if debug = false -admins: - - 'bob@example.com' - -application_name: "Yo Momma's Dispatch Tracker" -website_uri: 'http://localhost:8080' - -ACCOUNT_ACTIVATION_DAYS: 7 - -# Email settings won't be loaded from this file if this is false -SET_EMAIL: False -# Email settings, edit for your needs -EMAIL_HOST: smtp.example.com -EMAIL_HOST_PASSWORD: p@$$w0rd9876543210 -EMAIL_HOST_USER: django@example.com -EMAIL_PORT: 2525 -EMAIL_USE_TLS: True -DEFAULT_FROM_EMAIL: webmaster@localhost - -TEMPLATE_VARS: - app_name: Subcontractor Invoicing System Demo - login_blurb: Here's an example blurb above the sign-in box. This can be changed according to your needs. - login_info: ' - <p class="flow-text"> - Welcome to a demo Subcontractor Invoicing system. - </p> - <p class="flow-text"> - We can design a system that works specifically for your - use case. - </p> - <p class="flow-text"> - <a href="https://mitchriedstra.com/resume">Please contact me</a> - if you would like more information. This version has been - specifically designed for a trucking company that continues to - use it more than two years after implementation. - </p> - </p> - ' - - - - - diff --git a/app/demo.sh b/app/demo.sh new file mode 100755 index 0000000..79d1815 --- /dev/null +++ b/app/demo.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +set -x +#shellcheck disable=SC2046 +python="$(find $(echo "$PATH" | tr : '\n') -type f -executable -iname 'python*' | sed 1q)" +manage() { +$python manage.py "$@" +} + +manage migrate +manage setup +manage setup_identity +manage insert_fake_data --companies 20 --users 20 --loads 600 \ + --attachments=True --invoices=True --start-date='-6w' --end-date='+6w' diff --git a/app/requirements.txt b/app/requirements.txt index ac816f3..8cf4ce5 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -8,6 +8,6 @@ Faker==9.2.0 python-dateutil==2.6.0 pytz==2021.3 PyYAML==5.4.1 -six==1.16.0 +# six==1.16.0 sqlparse==0.4.2 text-unidecode==1.3 diff --git a/app/uwsgi.ini b/app/uwsgi.ini deleted file mode 100644 index 2dae309..0000000 --- a/app/uwsgi.ini +++ /dev/null @@ -1,15 +0,0 @@ -[uwsgi] -processes = 1 -threads = 4 - -env = CUSTOM_CONFIG=config-compose.yml - -# use 127.0.0.1 instead of 0.0.0.0 if possible -# this is for a containerized deployment -socket = 0.0.0.0:9200 - -module = wsgi:application - -# uid = uwsgi - -# home = env |
