From e1bf2f5982a870cc01c6a5853f57a3cd5b4075aa Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 7 Nov 2015 03:13:15 -0800 Subject: [PATCH] Small project to test with --- testproject/chtest/__init__.py | 0 testproject/chtest/consumers.py | 4 ++++ testproject/chtest/models.py | 3 +++ testproject/manage.py | 10 ++++++++ testproject/testproject/__init__.py | 0 testproject/testproject/settings.py | 36 +++++++++++++++++++++++++++++ testproject/testproject/urls.py | 7 ++++++ testproject/testproject/wsgi.py | 16 +++++++++++++ 8 files changed, 76 insertions(+) create mode 100644 testproject/chtest/__init__.py create mode 100644 testproject/chtest/consumers.py create mode 100644 testproject/chtest/models.py create mode 100644 testproject/manage.py create mode 100644 testproject/testproject/__init__.py create mode 100644 testproject/testproject/settings.py create mode 100644 testproject/testproject/urls.py create mode 100644 testproject/testproject/wsgi.py diff --git a/testproject/chtest/__init__.py b/testproject/chtest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/testproject/chtest/consumers.py b/testproject/chtest/consumers.py new file mode 100644 index 0000000..ba7385c --- /dev/null +++ b/testproject/chtest/consumers.py @@ -0,0 +1,4 @@ + +def ws_message(message): + "Echoes messages back to the client" + message.reply_channel.send(message.content) diff --git a/testproject/chtest/models.py b/testproject/chtest/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/testproject/chtest/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/testproject/manage.py b/testproject/manage.py new file mode 100644 index 0000000..97ed576 --- /dev/null +++ b/testproject/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/testproject/testproject/__init__.py b/testproject/testproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/testproject/testproject/settings.py b/testproject/testproject/settings.py new file mode 100644 index 0000000..5bae6cb --- /dev/null +++ b/testproject/testproject/settings.py @@ -0,0 +1,36 @@ +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +SECRET_KEY = '-3yt98bfvxe)7+^h#(@8k#1(1m_fpd9x3q2wolfbf^!r5ma62u' + +DEBUG = True + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'channels', +) + +ROOT_URLCONF = 'testproject.urls' + +WSGI_APPLICATION = 'testproject.wsgi.application' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +CHANNEL_BACKENDS = { + "default": { + "BACKEND": "channels.backends.database.DatabaseChannelBackend", + "ROUTING": "testproject.urls.channel_routing", + }, +} + +if os.environ.get("USEREDIS", None): + CHANNEL_BACKENDS['default']['BACKEND'] = "channels.backends.redis_py.RedisChannelBackend" diff --git a/testproject/testproject/urls.py b/testproject/testproject/urls.py new file mode 100644 index 0000000..0337b72 --- /dev/null +++ b/testproject/testproject/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import include, url +from chtest import consumers +urlpatterns = [] + +channel_routing = { + "websocket.message": consumers.ws_message, +} diff --git a/testproject/testproject/wsgi.py b/testproject/testproject/wsgi.py new file mode 100644 index 0000000..c24d001 --- /dev/null +++ b/testproject/testproject/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for testproject 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/dev/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") + +application = get_wsgi_application()