Skip to content

Commit

Permalink
update django configuration (fixes #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Dec 10, 2021
1 parent 21dcb7b commit 02c7ced
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 47 deletions.
22 changes: 17 additions & 5 deletions db/manage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/usr/bin/env python3
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.dev")

from django.core.management import execute_from_command_line

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings.dev')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
16 changes: 16 additions & 0 deletions db/project_name/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for {{ project_name }} project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings.prod')

application = get_asgi_application()
91 changes: 60 additions & 31 deletions db/project_name/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
"""
Django settings for {{ project_name }} project.
Based on the Django 2.0 template, with wq-specific modifications noted as such.
Based on the Django 3.2 template, with wq-specific modifications noted as such.
Generated by 'wq create' {{ wq_create_version }}.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
https://docs.djangoproject.com/en/3.2/ref/settings/
For more information about wq.db's Django settings see
http://wq.io/docs/settings
https://wq.io/wq.db/settings
"""

import os
from os.path import dirname
from pathlib import Path

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# wq: extra dirname()s to account for db/ and settings/ folders
BASE_DIR = dirname(dirname(dirname(dirname(os.path.abspath(__file__)))))
# Build paths inside the project like this: BASE_DIR / 'subdir'.
# wq: extra .parent.parent to account for db/ and settings/ folders
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent

# wq: SECRET_KEY, DEBUG, and ALLOWED_HOSTS are defined in dev.py/prod.py

Expand Down Expand Up @@ -56,28 +55,53 @@

ROOT_URLCONF = '{{ project_name }}.urls'

# wq: Recommended settings for Django and rest_framework
from wq.db.default_settings import (
TEMPLATES,
SESSION_COOKIE_HTTPONLY,
REST_FRAMEWORK,
)
if TEMPLATES[0]['BACKEND'] == 'django_mustache.Mustache':
TEMPLATES = TEMPLATES[1:]

# wq: Recommended settings unique to wq.db
from wq.db.default_settings import (
ANONYMOUS_PERMISSIONS,
SRID,
)
# wq: Leverage wq.db for Django REST Framework defaults
REST_FRAMEWORK = {

'DEFAULT_RENDERER_CLASSES': (
'wq.db.rest.renderers.HTMLRenderer',
'wq.db.rest.renderers.JSONRenderer',
'wq.db.rest.renderers.GeoJSONRenderer',
),

'DEFAULT_PAGINATION_CLASS': 'wq.db.rest.pagination.Pagination',
'PAGE_SIZE': 50,

'DEFAULT_PERMISSION_CLASSES': (
'wq.db.rest.permissions.ModelPermissions',
),

'DEFAULT_FILTER_BACKENDS': (
'wq.db.rest.filters.FilterBackend',
),

'DEFAULT_CONTENT_NEGOTIATION_CLASS':
'wq.db.rest.negotiation.ContentNegotiation'
}

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',
],
},
},
]

WSGI_APPLICATION = '{{ project_name }}.wsgi.application'


# wq: DATABASES is defined in dev.py/prod.py

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -96,7 +120,7 @@


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -110,17 +134,22 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'{% if not with_npm %}
STATICFILES_DIRS = [
('app', os.path.join(BASE_DIR, 'app'))
('app', BASE_DIR / 'app'),
]{% endif %}

# wq: Configure paths for default project layout
PROJECT_NAME = '{{ title }}'
STATIC_ROOT = os.path.join(BASE_DIR, 'htdocs', 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
WQ_APP_TEMPLATE = os.path.join(BASE_DIR, 'htdocs', 'index.html')
VERSION_TXT = os.path.join(BASE_DIR, 'version.txt')
STATIC_ROOT = BASE_DIR / 'htdocs' / 'static'
MEDIA_ROOT = BASE_DIR / 'media'
WQ_APP_TEMPLATE = BASE_DIR / 'htdocs' / 'index.html'
VERSION_TXT = BASE_DIR / 'version.txt'
MEDIA_URL = '/media/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
12 changes: 5 additions & 7 deletions db/project_name/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
import mimetypes
from .base import *
Expand All @@ -16,26 +15,25 @@
if DEBUG_WITH_RUNSERVER:
{% if with_npm %}
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app', 'build', 'static')
BASE_DIR / 'app' / 'build' / 'static'
]
WQ_CONFIG_FILE = os.path.join(BASE_DIR, 'app', 'src', 'data', 'config.js')
WQ_CONFIG_FILE = BASE_DIR / 'app' / 'src' / 'data' / 'config.js'
{% else %}
WQ_CONFIG_FILE = os.path.join(BASE_DIR, 'app', 'js', 'data', 'config.js')
WQ_CONFIG_FILE = BASE_DIR / 'app' / 'js' / 'data' / 'config.js'
{% endif %}
mimetypes.add_type("application/javascript", ".js", True)

ALLOWED_HOSTS = []

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
{% if with_gis %}'ENGINE': 'django.contrib.gis.db.backends.spatialite',
{% else %}'ENGINE': 'django.db.backends.sqlite3',
# To enable GeoDjango:
# 'ENGINE': 'django.contrib.gis.db.backends.spatialite',
{% endif %}'NAME': os.path.join(BASE_DIR, 'conf', '{{ project_name }}.sqlite3'),
{% endif %}'NAME': BASE_DIR / 'conf' / '{{ project_name }}.sqlite3',
}
}

Expand Down
2 changes: 1 addition & 1 deletion db/project_name/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
Expand Down
2 changes: 1 addition & 1 deletion db/project_name/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""{{ project_name }} URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
Expand Down
4 changes: 2 additions & 2 deletions db/project_name/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.prod")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings.prod')

application = get_wsgi_application()

0 comments on commit 02c7ced

Please sign in to comment.