From ab1762c18028d29d5cf4c0c95c93c3b548a3f7bb Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 30 Jan 2020 10:31:00 +0000 Subject: [PATCH] Initial commit with core project structure --- .gitignore | 12 ++ breccia_mapper/__init__.py | 0 breccia_mapper/settings.py | 207 ++++++++++++++++++++++++++++++ breccia_mapper/urls.py | 21 +++ breccia_mapper/wsgi.py | 16 +++ manage.py | 21 +++ people/__init__.py | 0 people/admin.py | 7 + people/apps.py | 5 + people/migrations/0001_initial.py | 44 +++++++ people/migrations/__init__.py | 0 people/models.py | 8 ++ requirements.txt | 5 + 13 files changed, 346 insertions(+) create mode 100644 .gitignore create mode 100644 breccia_mapper/__init__.py create mode 100644 breccia_mapper/settings.py create mode 100644 breccia_mapper/urls.py create mode 100644 breccia_mapper/wsgi.py create mode 100755 manage.py create mode 100644 people/__init__.py create mode 100644 people/admin.py create mode 100644 people/apps.py create mode 100644 people/migrations/0001_initial.py create mode 100644 people/migrations/__init__.py create mode 100644 people/models.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..285cdca --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# IDE files +.idea/ +.vscode/ + +# Runtime +venv/ + +db.sqlite3 +debug.log* + +# Configuration +settings.ini diff --git a/breccia_mapper/__init__.py b/breccia_mapper/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/breccia_mapper/settings.py b/breccia_mapper/settings.py new file mode 100644 index 0000000..211d98a --- /dev/null +++ b/breccia_mapper/settings.py @@ -0,0 +1,207 @@ +""" +Django settings for breccia_mapper project. + +Generated by 'django-admin startproject' using Django 2.2.9. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import collections +import pathlib + +from decouple import config, Csv +import dj_database_url + +# Build paths inside the project like this: BASE_DIR.joinpath(...) +BASE_DIR = pathlib.Path(__file__).parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = config('SECRET_KEY') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = config('DEBUG', default=False, cast=bool) + +ALLOWED_HOSTS = config( + 'ALLOWED_HOSTS', + default='*' if DEBUG else '127.0.0.1,localhost,localhost.localdomain', + cast=Csv() +) + + +# Application definition + +DJANGO_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +THIRD_PARTY_APPS = [ +] + +FIRST_PARTY_APPS = [ + 'people', +] + +INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + FIRST_PARTY_APPS + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'breccia_mapper.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR.joinpath('breccia_mapper', 'templates')], + '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 = 'breccia_mapper.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': config( + 'DATABASE_URL', + default='sqlite:///' + str(BASE_DIR.joinpath('db.sqlite3')), + cast=dj_database_url.parse + ) +} + +# Django DBBackup +# https://django-dbbackup.readthedocs.io/en/stable/index.html + +DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage' +DBBACKUP_STORAGE_OPTIONS = { + 'location': config('DBBACKUP_STORAGE_LOCATION', default=BASE_DIR.joinpath('.dbbackup')), +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +# Custom user model +# https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project + +AUTH_USER_MODEL = 'people.User' + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' + +STATIC_ROOT = BASE_DIR.joinpath('static') + +STATICFILES_DIRS = [ + BASE_DIR.joinpath('breccia_mapper', 'static') +] + + +# Logging - NB the logger name is empty to capture all output + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'file': { + 'level': config('LOG_LEVEL', default='INFO'), + 'class': 'logging.handlers.TimedRotatingFileHandler', + 'filename': config('LOG_FILENAME', default='debug.log'), + 'when': 'midnight', + 'backupCount': config('LOG_DAYS', default=14, cast=int), + 'formatter': 'timestamped', + }, + 'console': { + 'level': config('LOG_LEVEL', default='INFO'), + 'class': 'logging.StreamHandler', + 'formatter': 'timestamped', + }, + }, + 'loggers': { + '': { + 'handlers': ['console', 'file'], + 'level': config('LOG_LEVEL', default='INFO'), + 'propagate': True, + }, + }, + 'formatters': { + 'timestamped': { + 'format': '[{asctime} {levelname} {module} {funcName}] {message}', + 'style': '{', + } + } +} + + +# Admin panel variables + +CONSTANCE_CONFIG = collections.OrderedDict([ + ('NOTICE_TEXT', ('', 'Text to be displayed in a notice banner at the top of every page.')), + ('NOTICE_CLASS', ('alert-warning', 'CSS class to use for background of notice banner.')), +]) + +CONSTANCE_CONFIG_FIELDSETS = { + 'Notice Banner': ('NOTICE_TEXT', 'NOTICE_CLASS'), +} + +CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend' diff --git a/breccia_mapper/urls.py b/breccia_mapper/urls.py new file mode 100644 index 0000000..7fa8c62 --- /dev/null +++ b/breccia_mapper/urls.py @@ -0,0 +1,21 @@ +"""breccia_mapper URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/breccia_mapper/wsgi.py b/breccia_mapper/wsgi.py new file mode 100644 index 0000000..2f4ecbd --- /dev/null +++ b/breccia_mapper/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for breccia_mapper project. + +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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'breccia_mapper.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..882dfa5 --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'breccia_mapper.settings') + 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() diff --git a/people/__init__.py b/people/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/admin.py b/people/admin.py new file mode 100644 index 0000000..125e9bb --- /dev/null +++ b/people/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin + +from . import models + + +admin.site.register(models.User, UserAdmin) diff --git a/people/apps.py b/people/apps.py new file mode 100644 index 0000000..3eae75a --- /dev/null +++ b/people/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PeopleConfig(AppConfig): + name = 'people' diff --git a/people/migrations/0001_initial.py b/people/migrations/0001_initial.py new file mode 100644 index 0000000..3ef3a2a --- /dev/null +++ b/people/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# Generated by Django 2.2.9 on 2020-01-30 10:17 + +import django.contrib.auth.models +import django.contrib.auth.validators +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0011_update_proxy_permissions'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), + ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/people/migrations/__init__.py b/people/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/models.py b/people/models.py new file mode 100644 index 0000000..b21370b --- /dev/null +++ b/people/models.py @@ -0,0 +1,8 @@ +from django.contrib.auth.models import AbstractUser + + +class User(AbstractUser): + """ + Custom user model in case we need to make changes later. + """ + pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..13dae2c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +dj-database-url +django~=2.2 +django-constance +django-dbbackup +python-decouple