From 048f58b3bb2a27d2f3768c0b2a9f27ee9e23dd78 Mon Sep 17 00:00:00 2001 From: Justin Karneges Date: Fri, 5 Apr 2019 21:51:39 -0700 Subject: [PATCH] update project --- api/admin.py | 6 ++ api/apps.py | 8 +++ api/middleware.py | 3 +- {webhookinbox => api/migrations}/__init__.py | 0 api/models.py | 5 ++ api/tests.py | 18 ++---- api/views.py | 3 + manage.py | 20 ++++-- requirements.txt | 31 ++++++--- server/__init__.py | 0 {webhookinbox => server}/hosts.py | 0 {webhookinbox => server}/settings.py | 68 ++++++++++++-------- {webhookinbox => server}/urls.py | 0 {webhookinbox => server}/wsgi.py | 6 +- website/admin.py | 6 ++ website/apps.py | 8 +++ website/migrations/__init__.py | 0 website/models.py | 6 ++ website/tests.py | 18 ++---- website/views.py | 7 +- 20 files changed, 141 insertions(+), 72 deletions(-) create mode 100644 api/admin.py create mode 100644 api/apps.py rename {webhookinbox => api/migrations}/__init__.py (100%) create mode 100644 server/__init__.py rename {webhookinbox => server}/hosts.py (100%) rename {webhookinbox => server}/settings.py (71%) rename {webhookinbox => server}/urls.py (100%) rename {webhookinbox => server}/wsgi.py (75%) create mode 100644 website/admin.py create mode 100644 website/apps.py create mode 100644 website/migrations/__init__.py diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..881120e --- /dev/null +++ b/api/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +#from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..8f01aa8 --- /dev/null +++ b/api/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + name = 'api' diff --git a/api/middleware.py b/api/middleware.py index 9208286..cc8e9c4 100644 --- a/api/middleware.py +++ b/api/middleware.py @@ -1,6 +1,7 @@ from django.http import HttpResponse +from django.utils.deprecation import MiddlewareMixin -class OptionsMiddleware: +class OptionsMiddleware(MiddlewareMixin): def process_request(self, request): if request.method == 'OPTIONS': return HttpResponse() diff --git a/webhookinbox/__init__.py b/api/migrations/__init__.py similarity index 100% rename from webhookinbox/__init__.py rename to api/migrations/__init__.py diff --git a/api/models.py b/api/models.py index 6b20219..af609b7 100644 --- a/api/models.py +++ b/api/models.py @@ -1 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +#from django.db import models + # Create your models here. diff --git a/api/tests.py b/api/tests.py index 501deb7..04522fc 100644 --- a/api/tests.py +++ b/api/tests.py @@ -1,16 +1,6 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". +# -*- coding: utf-8 -*- +from __future__ import unicode_literals -Replace this with more appropriate tests for your application. -""" +#from django.test import TestCase -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) +# Create your tests here. diff --git a/api/views.py b/api/views.py index 05cbeb9..57a5dc6 100644 --- a/api/views.py +++ b/api/views.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + from base64 import b64encode, b64decode import datetime import copy diff --git a/manage.py b/manage.py index e87fb21..3bcfd15 100755 --- a/manage.py +++ b/manage.py @@ -6,8 +6,20 @@ dotenv.read_dotenv() if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webhookinbox.settings") - - from django.core.management import execute_from_command_line - + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise execute_from_command_line(sys.argv) diff --git a/requirements.txt b/requirements.txt index 329d241..4305142 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,31 @@ -Django==1.8.2 -PyJWT==1.4.0 -argparse==1.2.1 +alabaster==0.7.12 +Babel==2.6.0 dj-database-url==0.3.0 dj-static==0.0.6 +Django==1.11.20 django-dotenv==1.4.1 -django-grip==1.7.0 -django-hosts==1.2 -gripcontrol==2.4.2 +django-grip==2.0.0 +django-hosts==3.0 +docutils==0.14 +gripcontrol==3.3.0 gunicorn==19.3.0 -pubcontrol==2.2.7 +imagesize==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.1 +packaging==19.0 +pkg-resources==0.0.0 +pubcontrol==2.4.2 +Pygments==2.3.1 +PyJWT==1.4.0 +pyparsing==2.3.1 +pytz==2018.9 redis==2.10.3 requests==2.10.0 +six==1.12.0 +snowballstemmer==1.2.1 +Sphinx==1.8.5 +sphinxcontrib-websupport==1.1.0 static3==0.6.1 +typing==3.6.6 +Werkzeug==0.15.2 whitenoise==1.0.6 -wsgiref==0.1.2 diff --git a/server/__init__.py b/server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webhookinbox/hosts.py b/server/hosts.py similarity index 100% rename from webhookinbox/hosts.py rename to server/hosts.py diff --git a/webhookinbox/settings.py b/server/settings.py similarity index 71% rename from webhookinbox/settings.py rename to server/settings.py index 82e5dc3..7912ec5 100644 --- a/webhookinbox/settings.py +++ b/server/settings.py @@ -1,23 +1,23 @@ """ -Django settings for webhookinbox project. +Django settings for server project. -Generated by 'django-admin startproject' using Django 1.8.2. +Generated by 'django-admin startproject' using Django 1.11.20. For more information on this file, see -https://docs.djangoproject.com/en/1.8/topics/settings/ +https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.8/ref/settings/ +https://docs.djangoproject.com/en/1.11/ref/settings/ """ -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 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/1.8/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'secret') @@ -30,7 +30,7 @@ # Application definition -INSTALLED_APPS = ( +INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -40,25 +40,23 @@ 'django_hosts', 'api', 'website', -) +] -MIDDLEWARE_CLASSES = ( - 'django_hosts.middleware.HostsRequestMiddleware', +MIDDLEWARE = [ 'django_grip.GripMiddleware', + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'api.middleware.OptionsMiddleware', #'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django.middleware.security.SecurityMiddleware', 'django_hosts.middleware.HostsResponseMiddleware', -) +] -ROOT_HOSTCONF = 'webhookinbox.hosts' -ROOT_URLCONF = 'webhookinbox.urls' +ROOT_HOSTCONF = 'server.hosts' +ROOT_URLCONF = 'server.urls' DEFAULT_HOST = 'website' @@ -78,17 +76,36 @@ }, ] -WSGI_APPLICATION = 'webhookinbox.wsgi.application' +WSGI_APPLICATION = 'server.wsgi.application' # Database -# https://docs.djangoproject.com/en/1.8/ref/settings/#databases +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = {} +# Password validation +# https://docs.djangoproject.com/en/1.11/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/1.8/topics/i18n/ +# https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -102,7 +119,7 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.8/howto/static-files/ +# https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = '/static/' @@ -146,25 +163,24 @@ REDIS_HOST = os.environ.get('REDIS_HOST') if 'REDIS_PORT' in os.environ: - REDIS_PORT = int(os.environ['REDIS_PORT']) + REDIS_PORT = int(os.environ['REDIS_PORT']) if 'REDIS_DB' in os.environ: - REDIS_DB = int(os.environ['REDIS_DB']) + REDIS_DB = int(os.environ['REDIS_DB']) from gripcontrol import parse_grip_uri GRIP_PROXY_REQUIRED = True -if 'GRIP_URL' in os.environ: - GRIP_PROXIES = [parse_grip_uri(os.environ['GRIP_URL'])] +GRIP_URL = os.environ.get('GRIP_URL') WHINBOX_API_BASE = os.environ.get('WHINBOX_API_BASE') WHINBOX_REDIS_PREFIX = os.environ.get('WHINBOX_REDIS_PREFIX') WHINBOX_GRIP_PREFIX = os.environ.get('WHINBOX_GRIP_PREFIX') if 'WHINBOX_ITEM_MAX' in os.environ: - WHINBOX_ITEM_MAX = int(os.environ['WHINBOX_ITEM_MAX']) + WHINBOX_ITEM_MAX = int(os.environ['WHINBOX_ITEM_MAX']) if 'WHINBOX_ITEM_BURST_TIME' in os.environ: - WHINBOX_ITEM_BURST_TIME = int(os.environ['WHINBOX_ITEM_BURST_TIME']) + WHINBOX_ITEM_BURST_TIME = int(os.environ['WHINBOX_ITEM_BURST_TIME']) if 'WHINBOX_ITEM_BURST_MAX' in os.environ: - WHINBOX_ITEM_BURST_MAX = int(os.environ['WHINBOX_ITEM_BURST_MAX']) + WHINBOX_ITEM_BURST_MAX = int(os.environ['WHINBOX_ITEM_BURST_MAX']) WHINBOX_ORIG_HEADERS = (os.environ.get('WHINBOX_ORIG_HEADERS', '0') == '1') GA_ID = os.environ.get('GA_ID') diff --git a/webhookinbox/urls.py b/server/urls.py similarity index 100% rename from webhookinbox/urls.py rename to server/urls.py diff --git a/webhookinbox/wsgi.py b/server/wsgi.py similarity index 75% rename from webhookinbox/wsgi.py rename to server/wsgi.py index d33b1d3..3e9f5c5 100644 --- a/webhookinbox/wsgi.py +++ b/server/wsgi.py @@ -1,10 +1,10 @@ """ -WSGI config for webhookinbox project. +WSGI config for server 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/1.8/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ """ import os @@ -14,7 +14,7 @@ dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env')) -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webhookinbox.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") from django.conf import settings diff --git a/website/admin.py b/website/admin.py new file mode 100644 index 0000000..881120e --- /dev/null +++ b/website/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +#from django.contrib import admin + +# Register your models here. diff --git a/website/apps.py b/website/apps.py new file mode 100644 index 0000000..2d30ae4 --- /dev/null +++ b/website/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class WebsiteConfig(AppConfig): + name = 'website' diff --git a/website/migrations/__init__.py b/website/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/website/models.py b/website/models.py index e69de29..af609b7 100644 --- a/website/models.py +++ b/website/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +#from django.db import models + +# Create your models here. diff --git a/website/tests.py b/website/tests.py index 501deb7..04522fc 100644 --- a/website/tests.py +++ b/website/tests.py @@ -1,16 +1,6 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". +# -*- coding: utf-8 -*- +from __future__ import unicode_literals -Replace this with more appropriate tests for your application. -""" +#from django.test import TestCase -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) +# Create your tests here. diff --git a/website/views.py b/website/views.py index 87689ba..3a95258 100644 --- a/website/views.py +++ b/website/views.py @@ -1,6 +1,9 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + from django.conf import settings from django.template import RequestContext -from django.shortcuts import render_to_response +from django.shortcuts import render def _page(request, name, inbox_id=None): if settings.WHINBOX_API_BASE: @@ -19,7 +22,7 @@ def _page(request, name, inbox_id=None): if ga_id: context['ga_id'] = ga_id - return render_to_response('website/%s.html' % name, context, context_instance=RequestContext(request)) + return render(request, 'website/%s.html' % name, context) def home(request): return _page(request, 'home')