aboutsummaryrefslogtreecommitdiffstats
path: root/config/settings
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-07 21:03:11 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-07 21:03:11 +0100
commit2e21f37eaf031300b4f7ec0626333255f16e7bd0 (patch)
tree420922015307fde6156345a942f383313f7df180 /config/settings
parent2947010fe6fe3d54019164f9d8213a2fede55a45 (diff)
big update! got working on gcloud and with log and new navbar
Diffstat (limited to 'config/settings')
-rw-r--r--config/settings/base.py11
-rw-r--r--config/settings/gcloud_settings.py267
2 files changed, 211 insertions, 67 deletions
diff --git a/config/settings/base.py b/config/settings/base.py
index c699798..e3a93a0 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -1,6 +1,7 @@
"""
Base settings to build other settings files upon.
"""
+import os
import environ
@@ -40,8 +41,12 @@ LOCALE_PATHS = [ROOT_DIR.path("locale")]
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
-DATABASES = {"default": env.db("DATABASE_URL", default="postgres:///ctrack")}
-DATABASES["default"]["ATOMIC_REQUESTS"] = True
+import pymysql # noqa: 402
+pymysql.version_info = (1, 4, 6, 'final', 0) # change mysqlclient version
+pymysql.install_as_MySQLdb()
+
+# DATABASES = {"default": env.db("DATABASE_URL", default="postgres:///ctrack")}
+# DATABASES["default"]["ATOMIC_REQUESTS"] = True
# URLS
# ------------------------------------------------------------------------------
@@ -68,7 +73,7 @@ DJANGO_APPS = [
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
- "django_pdb", ## this needs to be before django.contrib.staticfiles according to its docs
+ # "django_pdb", ## this needs to be before django.contrib.staticfiles according to its docs
"django.contrib.staticfiles",
# "django.contrib.humanize", # Handy template tags
"django.contrib.admin",
diff --git a/config/settings/gcloud_settings.py b/config/settings/gcloud_settings.py
index 253a76b..c7c2680 100644
--- a/config/settings/gcloud_settings.py
+++ b/config/settings/gcloud_settings.py
@@ -1,41 +1,150 @@
-# Copyright 2015 Google Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+"""
+Django settings for mysite project.
+
+Generated by 'django-admin startproject' using Django 2.1.1.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/2.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/2.1/ref/settings/
+"""
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
+import environ
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ROOT_DIR = environ.Path(__file__) - 3 # (ctrack/config/settings/base.py - 3 = ctrack/)
+APPS_DIR = ROOT_DIR.path("ctrack")
+
+
+# STATIC
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
+STATIC_ROOT = str(ROOT_DIR("static"))
+# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
+STATIC_URL = "/static/"
+# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
+STATICFILES_DIRS = [str(APPS_DIR.path("static"))]
+# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
+STATICFILES_FINDERS = [
+ "django.contrib.staticfiles.finders.FileSystemFinder",
+ "django.contrib.staticfiles.finders.AppDirectoriesFinder",
+]
+
+# MEDIA
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
+MEDIA_ROOT = str(APPS_DIR("media"))
+# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
+MEDIA_URL = "/media/"
+
+# TEMPLATES
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#templates
+TEMPLATES = [
+ {
+ # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ # https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
+ "DIRS": [str(APPS_DIR.path("templates"))],
+ "OPTIONS": {
+ # https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
+ # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
+ "loaders": [
+ "django.template.loaders.filesystem.Loader",
+ "django.template.loaders.app_directories.Loader",
+ ],
+ # https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
+ "context_processors": [
+ "django.template.context_processors.debug",
+ "django.template.context_processors.request",
+ "django.contrib.auth.context_processors.auth",
+ "django.template.context_processors.i18n",
+ "django.template.context_processors.media",
+ "django.template.context_processors.static",
+ "django.template.context_processors.tz",
+ "django.contrib.messages.context_processors.messages",
+ "ctrack.utils.context_processors.settings_context",
+ ],
+ },
+ }
+]
+# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
+CRISPY_TEMPLATE_PACK = "bootstrap4"
+
+# FIXTURES
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
+FIXTURE_DIRS = (str(APPS_DIR.path("fixtures")),)
+
+# https://docs.djangoproject.com/en/dev/ref/settings/#site-id
+SITE_ID = 1
+
# Quick-start development settings - unsuitable for production
-# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
+# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'pf-@jxtojga)z+4s*uwbgjrq$aep62-thd0q7f&o77xtpka!_m'
+# Update the secret key to a value of your own before deploying the app.
+SECRET_KEY = 'lldtg$9(wi49j_hpv8nnqlh!cj7kmbwq0$rj7vy(b(b30vlyzj'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
-# SECURITY WARNING: If you deploy a Django app to production, make sure to set
-# an appropriate host here.
-# See https://docs.djangoproject.com/en/1.10/ref/settings/
+# SECURITY WARNING: App Engine's security features ensure that it is safe to
+# have ALLOWED_HOSTS = ['*'] when the app is deployed. If you deploy a Django
+# app not on App Engine, make sure to set an appropriate host here.
+# See https://docs.djangoproject.com/en/2.1/ref/settings/
ALLOWED_HOSTS = ['*']
+# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
+AUTH_USER_MODEL = "users.User"
+
+ROOT_DIR = environ.Path(__file__) - 3 # (ctrack/config/settings/base.py - 3 = ctrack/)
+APPS_DIR = ROOT_DIR.path("ctrack")
+env = environ.Env()
+
+READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True)
+if READ_DOT_ENV_FILE:
+ # OS environment variables take precedence over variables from .env
+ env.read_env(str(ROOT_DIR.path(".env")))
+
+# MEDIA
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
+MEDIA_ROOT = str(APPS_DIR("media"))
+# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
+MEDIA_URL = "/media/"
+
+# Django Admin URL.
+ADMIN_URL = "admin/"
+# https://docs.djangoproject.com/en/dev/ref/settings/#admins
+ADMINS = [("""Matt Lemon""", "matt@matthewlemon.com")]
+# https://docs.djangoproject.com/en/dev/ref/settings/#managers
+MANAGERS = ADMINS
+
+# STATIC
+# ------------------------------------------------------------------------------
+# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
+STATIC_ROOT = str(ROOT_DIR("static"))
+# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
+STATIC_URL = "/static/"
+# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
+STATICFILES_DIRS = [str(APPS_DIR.path("static"))]
+# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
+STATICFILES_FINDERS = [
+ "django.contrib.staticfiles.finders.FileSystemFinder",
+ "django.contrib.staticfiles.finders.AppDirectoriesFinder",
+]
+
# Application definition
-INSTALLED_APPS = (
+INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
+ 'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
@@ -43,15 +152,16 @@ INSTALLED_APPS = (
'crispy_forms',
'allauth',
'allauth.account',
+ "allauth.socialaccount",
"ctrack.users.apps.UsersConfig",
"ctrack.organisations.apps.OrganisationsConfig",
"ctrack.caf.apps.CafConfig",
"ctrack.register.apps.RegisterConfig",
"ctrack.assessments.apps.AssessmentsConfig",
"ctrack.core.apps.CoreConfig",
-)
+]
-MIDDLEWARE = (
+MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@@ -59,49 +169,81 @@ MIDDLEWARE = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
-)
-
-ROOT_URLCONF = 'mysite.urls'
-
-TEMPLATES = [
- {
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'DIRS': [],
- 'APP_DIRS': True,
- 'OPTIONS': {
- 'context_processors': [
- 'django.template.context_processors.debug',
- 'django.template.context_processors.request',
- 'django.contrib.auth.context_processors.auth',
- 'django.contrib.messages.context_processors.messages',
- ],
- },
- },
]
+ROOT_URLCONF = 'config.urls'
+
+WSGI_APPLICATION = 'config.wsgi.application'
-WSGI_APPLICATION = "config.wsgi.application"
# Database
-# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
-
-# [START dbconfig]
-DATABASES = {
- 'default': {
- # If you are using Cloud SQL for MySQL rather than PostgreSQL, set
- # 'ENGINE': 'django.db.backends.mysql' instead of the following.
- 'ENGINE': 'django.db.backends.postgresql',
- 'NAME': 'ctrack',
- 'USER': os.getenv('DATABASE_USER'),
- 'PASSWORD': os.getenv('DATABASE_PASSWORD'),
- 'HOST': '127.0.0.1',
- 'PORT': '5432',
+# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
+
+# Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter
+# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
+# for more information
+import pymysql # noqa: 402
+pymysql.version_info = (1, 4, 6, 'final', 0) # change mysqlclient version
+pymysql.install_as_MySQLdb()
+
+# [START db_setup]
+if os.getenv('GAE_APPLICATION', None):
+ # Running on production App Engine, so connect to Google Cloud SQL using
+ # the unix socket at /cloudsql/<your-cloudsql-connection string>
+ DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'HOST': '/cloudsql/ctrack-291710:europe-west2:ctrack-alt',
+ 'USER': 'ctrack',
+ 'PASSWORD': os.getenv('DATABASE_PASSWORD'),
+ 'NAME': 'ctrack',
+ }
+ }
+else:
+ # Running locally so connect to either a local MySQL instance or connect to
+ # Cloud SQL via the proxy. To start the proxy via command line:
+ #
+ # $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
+ #
+ # See https://cloud.google.com/sql/docs/mysql-connect-proxy
+ DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(BASE_DIR, 'ctrack.db'),
+ }
}
-}
-# [END dbconfig]
+# [END db_setup]
+
+# Use a in-memory sqlite3 database when testing in CI systems
+if os.getenv('TRAMPOLINE_CI', None):
+ DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
+ }
+ }
+
+# Password validation
+# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa: 501
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa: 501
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa: 501
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa: 501
+ },
+]
+
# Internationalization
-# https://docs.djangoproject.com/en/1.8/topics/i18n/
+# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-gb'
@@ -113,12 +255,9 @@ USE_L10N = True
USE_TZ = True
-# Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/1.8/howto/static-files/
-# [START staticurl]
-#STATIC_URL = '/static/'
-STATIC_URL = 'https://storage.googleapis.com/ctrack/static/'
-# [END staticurl]
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/2.1/howto/static-files/
-STATIC_ROOT = 'static/'
+# STATIC_ROOT = 'static'
+# STATIC_URL = '/static/'