diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f25ba5d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv +db.sqlite3 diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..465d3bf --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "notes.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/notes/__init__.py b/notes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notes/migrations/0001_initial.py b/notes/migrations/0001_initial.py new file mode 100644 index 0000000..3aeffdd --- /dev/null +++ b/notes/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('text', models.CharField(max_length=255)), + ('last_updated', models.DateTimeField(auto_now=True)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/notes/migrations/__init__.py b/notes/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notes/models.py b/notes/models.py new file mode 100644 index 0000000..bd4ca7e --- /dev/null +++ b/notes/models.py @@ -0,0 +1,15 @@ +from django.db import models +from django.contrib import admin +from swampdragon.serializers.model_serializer import ModelSerializer +from swampdragon.models import SelfPublishModel + +class NoteSerializer(ModelSerializer): + class Meta: + model = 'notes.Note' + publish_fields = ('text','last_updated') + +class Note(SelfPublishModel, models.Model): + text = models.CharField(max_length=255) + last_updated = models.DateTimeField(auto_now=True) + serializer_class = NoteSerializer +admin.site.register(Note) diff --git a/notes/routers.py b/notes/routers.py new file mode 100644 index 0000000..984a2cf --- /dev/null +++ b/notes/routers.py @@ -0,0 +1,17 @@ +from swampdragon import route_handler +from swampdragon.route_handler import ModelRouter +from notes.models import Note, NoteSerializer + + +class NoteRouter(ModelRouter): + route_name = 'note-list' + serializer_class = NoteSerializer + model = Note + + def get_object(self, **kwargs): + return self.model.objects.get(pk=kwargs['id']) + + def get_query_set(self, **kwargs): + return self.model.objects.all() + +route_handler.register(NoteRouter) diff --git a/notes/settings.py b/notes/settings.py new file mode 100644 index 0000000..62b68ec --- /dev/null +++ b/notes/settings.py @@ -0,0 +1,96 @@ +""" +Django settings for notes project. + +For more information on this file, see +https://docs.djangoproject.com/en/1.6/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.6/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '2+u_)-dlz+&8(jrd!58ru-o&sg4_mj$97xmslmvnmxb=mnd@i@' +TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')] +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] +DRAGON_URL = os.environ['DRAGON_URL'] +SWAMP_DRAGON_CONNECTION = ('swampdragon.connections.sockjs_connection.DjangoSubscriberConnection', '/data') + + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +TEMPLATE_DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'notes', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'swampdragon' + +) + +TEMPLATE_LOADERS = ( + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.filesystem.Loader', +) + + +MIDDLEWARE_CLASSES = ( + '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 = 'notes.urls' + +WSGI_APPLICATION = 'notes.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.6/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +# Internationalization +# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/notes/templates/add_note.html b/notes/templates/add_note.html new file mode 100644 index 0000000..278b19f --- /dev/null +++ b/notes/templates/add_note.html @@ -0,0 +1,5 @@ +
diff --git a/notes/templates/list_notes.html b/notes/templates/list_notes.html new file mode 100644 index 0000000..d9bfbaa --- /dev/null +++ b/notes/templates/list_notes.html @@ -0,0 +1,27 @@ +{% load static swampdragon_tags %} +{% swampdragon_settings %} +