From eaa48d04f4c8b654bde8e58eb5339d4e58a28c4f Mon Sep 17 00:00:00 2001 From: Eran Rundstein Date: Thu, 21 Dec 2017 13:28:37 -0800 Subject: [PATCH] add Django2 test project --- test_site/manage.py | 15 +++ test_site/papertrail | 1 + test_site/test_app/__init__.py | 0 test_site/test_app/admin.py | 3 + test_site/test_app/apps.py | 5 + test_site/test_app/migrations/__init__.py | 0 test_site/test_app/models.py | 3 + test_site/test_app/tests.py | 3 + test_site/test_app/urls.py | 7 ++ test_site/test_app/views.py | 18 ++++ test_site/test_site/__init__.py | 0 test_site/test_site/settings.py | 126 ++++++++++++++++++++++ test_site/test_site/urls.py | 7 ++ test_site/test_site/wsgi.py | 16 +++ 14 files changed, 204 insertions(+) create mode 100755 test_site/manage.py create mode 120000 test_site/papertrail create mode 100644 test_site/test_app/__init__.py create mode 100644 test_site/test_app/admin.py create mode 100644 test_site/test_app/apps.py create mode 100644 test_site/test_app/migrations/__init__.py create mode 100644 test_site/test_app/models.py create mode 100644 test_site/test_app/tests.py create mode 100644 test_site/test_app/urls.py create mode 100644 test_site/test_app/views.py create mode 100644 test_site/test_site/__init__.py create mode 100644 test_site/test_site/settings.py create mode 100644 test_site/test_site/urls.py create mode 100644 test_site/test_site/wsgi.py diff --git a/test_site/manage.py b/test_site/manage.py new file mode 100755 index 0000000..86279a2 --- /dev/null +++ b/test_site/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_site.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) diff --git a/test_site/papertrail b/test_site/papertrail new file mode 120000 index 0000000..b3f2f10 --- /dev/null +++ b/test_site/papertrail @@ -0,0 +1 @@ +../papertrail \ No newline at end of file diff --git a/test_site/test_app/__init__.py b/test_site/test_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_site/test_app/admin.py b/test_site/test_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/test_site/test_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/test_site/test_app/apps.py b/test_site/test_app/apps.py new file mode 100644 index 0000000..fc04070 --- /dev/null +++ b/test_site/test_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestAppConfig(AppConfig): + name = 'test_app' diff --git a/test_site/test_app/migrations/__init__.py b/test_site/test_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_site/test_app/models.py b/test_site/test_app/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/test_site/test_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/test_site/test_app/tests.py b/test_site/test_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/test_site/test_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/test_site/test_app/urls.py b/test_site/test_app/urls.py new file mode 100644 index 0000000..88a9cac --- /dev/null +++ b/test_site/test_app/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/test_site/test_app/views.py b/test_site/test_app/views.py new file mode 100644 index 0000000..a406572 --- /dev/null +++ b/test_site/test_app/views.py @@ -0,0 +1,18 @@ +import papertrail + +from django.http import HttpResponse +from django.utils import timezone + + +def index(request): + papertrail.log( + 'hello-world', + 'Hi!', + targets={ + 'user': request.user if request.user.is_authenticated else None, + }, + data={ + 'now': timezone.now(), + }, + ) + return HttpResponse("Hello, world.") diff --git a/test_site/test_site/__init__.py b/test_site/test_site/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_site/test_site/settings.py b/test_site/test_site/settings.py new file mode 100644 index 0000000..ae74753 --- /dev/null +++ b/test_site/test_site/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for test_site project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# 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/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '0%te(_0m&$gr#4#1_&2_%d_mc2+-t11s*&1w-dk_cg-zo1_zqp' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'test_app', + 'papertrail', +] + +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 = 'test_site.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'test_site.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'papertrail-test', + 'USER': '', + 'PASSWORD': '', + 'HOST': 'localhost', + 'PORT': '5432', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/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', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/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.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/test_site/test_site/urls.py b/test_site/test_site/urls.py new file mode 100644 index 0000000..d1b76c3 --- /dev/null +++ b/test_site/test_site/urls.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('', include('test_app.urls')), + path('admin/', admin.site.urls), +] diff --git a/test_site/test_site/wsgi.py b/test_site/test_site/wsgi.py new file mode 100644 index 0000000..1016211 --- /dev/null +++ b/test_site/test_site/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for test_site 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.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_site.settings") + +application = get_wsgi_application()