Commit c69de514 authored by David Haynes's avatar David Haynes 🙆

Migrate to consolidated settings model

- plus CI now uses pipenv
parent cb93750f
Pipeline #3718 failed with stage
in 1 minute and 30 seconds
......@@ -12,8 +12,9 @@ before_script:
- apt-get update -qy
- apt-get install -y mysql-client default-libmysqlclient-dev python-mysqldb
gdal-bin libproj-dev proj-data proj-bin binutils
- pip install -r requirements/test.txt
- cd whats-open/
- pip install pipenv
- pipenv install --system --deploy
- export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9"
| fold -w 60 | head -n1 2>/dev/null)
- export WOPEN_EMAIL_DOMAIN="@masonlive.gmu.edu"
......
......@@ -27,3 +27,4 @@ services:
- WOPEN_DB_HOST=db
- WOPEN_DB_PORT=3306
- WOPEN_SUPERUSER=admin
- WOPEN_ENV="dev"
......@@ -6,7 +6,6 @@ done
export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
python whats-open/manage.py flush --no-input
python whats-open/manage.py makemigrations
python whats-open/manage.py makemigrations api
python whats-open/manage.py migrate
......
......@@ -11,6 +11,9 @@ http://www.django-rest-framework.org/api-guide/routers/
from django.urls import include, path
from django.views.generic.base import RedirectView
# Other Imports
from rest_framework.routers import DefaultRouter
# App Imports
from .views import (
CategoryViewSet,
......@@ -20,9 +23,6 @@ from .views import (
AlertViewSet,
)
# Other Imports
from rest_framework.routers import DefaultRouter
# Instantiate our DefaultRouter
ROUTER = DefaultRouter()
......
......@@ -9,7 +9,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.local")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
from django.core.management import execute_from_command_line
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/local.py
Development settings and globals.
"""
# Import the base settings and override where necessary
from .base import *
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/production.py
Production settings and globals.
"""
# Python std. lib imports
from os import environ
# Django Imports
from django.core.exceptions import ImproperlyConfigured
# Import the base settings and override where necessary
from .base import *
def get_env_setting(setting):
"""
Get the environment setting or return exception
"""
try:
return environ[setting]
except KeyError as ex:
print(str(ex))
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
"""
HOST CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production
ALLOWED_HOSTS = ["*"]
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
"""
SECRET CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = get_env_setting("WOPEN_SECRET_KEY")
########## END SECRET CONFIGURATION
......@@ -6,23 +6,34 @@ settings/base.py
Base Django settings for whats-open.
"""
# Python std. lib. imports
import os
import sys
from os.path import abspath, dirname, join, normpath
from sys import path
from os import path, environ
# DEV vs PROD
if environ["WOPEN_ENV"] != "production":
DEBUG = True
# dummy cache for development-- doesn't actually cache things
CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
else:
DEBUG = False
CACHES = {
"default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": "localhost:6379"}
}
ALLOWED_HOSTS = ["*"]
SECRET_KEY = environ["WOPEN_SECRET_KEY"]
"""
PATH CONFIGURATION
"""
# Absolute filesystem path to the Django project directory:
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
DJANGO_ROOT = path.dirname(path.dirname(path.abspath(__file__)))
# Absolute filesystem path to the top-level project folder:
SITE_ROOT = dirname(DJANGO_ROOT)
SITE_ROOT = path.dirname(DJANGO_ROOT)
# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(DJANGO_ROOT)
sys.path.append(DJANGO_ROOT)
"""
MANAGER CONFIGURATION
......@@ -71,7 +82,7 @@ MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = normpath(join(SITE_ROOT, "media"))
MEDIA_ROOT = path.normpath(path.join(SITE_ROOT, "media"))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
......@@ -87,7 +98,7 @@ STATIC FILE CONFIGURATION
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = normpath(join(SITE_ROOT, "static"))
STATIC_ROOT = path.normpath(path.join(SITE_ROOT, "static"))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
# URL prefix for static files.
......@@ -122,7 +133,7 @@ ALLOWED_HOSTS = ["*"]
FIXTURE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(SITE_ROOT, "fixtures")),)
FIXTURE_DIRS = (path.normpath(path.join(SITE_ROOT, "fixtures")),)
"""
DATABASE CONFIGURATION
......@@ -132,11 +143,11 @@ DATABASE CONFIGURATION
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.mysql",
"NAME": os.environ["WOPEN_DB_NAME"],
"USER": os.environ["WOPEN_DB_USER"],
"PASSWORD": os.environ["WOPEN_DB_PASSWORD"],
"HOST": os.environ["WOPEN_DB_HOST"],
"PORT": os.environ["WOPEN_DB_PORT"],
"NAME": environ["WOPEN_DB_NAME"],
"USER": environ["WOPEN_DB_USER"],
"PASSWORD": environ["WOPEN_DB_PASSWORD"],
"HOST": environ["WOPEN_DB_HOST"],
"PORT": environ["WOPEN_DB_PORT"],
}
}
......@@ -148,9 +159,9 @@ TEMPLATES = [
"BACKEND": "django.template.backends.django.DjangoTemplates",
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
"DIRS": [
normpath(join(SITE_ROOT, "templates")),
path.normpath(path.join(SITE_ROOT, "templates")),
# may specify to avoid requiring paths
normpath(join(SITE_ROOT, "api/templates")),
path.normpath(path.join(SITE_ROOT, "api/templates")),
],
"OPTIONS": {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
......
......@@ -21,8 +21,8 @@ urlpatterns = [
path("admin/doc/", include("django.contrib.admindocs.urls")),
# /admin - The admin panels
path("admin/", admin.site.urls),
# /api-auth - API Auth page
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
# /auth - API Auth page
path("auth/", include("rest_framework.urls", namespace="rest_framework")),
# /logout - Redirect to the homepage on logout
path("logout/", django.contrib.auth.views.logout, {"next_page": "/"}),
]
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