From 163c036f847be97bcb9e92b22476c66977138ca0 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sat, 18 Jul 2015 21:56:40 +0200 Subject: [PATCH] Update sandbox project to Django 1.8.3 template --- vows/sandbox/__init__.py | 9 --- vows/sandbox/main/admin.py | 3 +- vows/sandbox/main/models.py | 1 + vows/sandbox/main/urls.py | 0 vows/sandbox/main/views.py | 3 + vows/sandbox/manage.py | 18 ++--- vows/sandbox/sandbox/__init__.py | 0 vows/sandbox/sandbox/settings.py | 109 +++++++++++++++++++++++++++++++ vows/sandbox/sandbox/urls.py | 25 +++++++ vows/sandbox/sandbox/wsgi.py | 16 +++++ 10 files changed, 163 insertions(+), 21 deletions(-) create mode 100644 vows/sandbox/main/urls.py create mode 100644 vows/sandbox/sandbox/__init__.py create mode 100644 vows/sandbox/sandbox/settings.py create mode 100644 vows/sandbox/sandbox/urls.py create mode 100644 vows/sandbox/sandbox/wsgi.py diff --git a/vows/sandbox/__init__.py b/vows/sandbox/__init__.py index 2e71dd5..e69de29 100644 --- a/vows/sandbox/__init__.py +++ b/vows/sandbox/__init__.py @@ -1,9 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# django-pyvows extensions -# https://github.com/rafaelcaricio/django-pyvows - -# Licensed under the MIT license: -# http://www.opensource.org/licenses/mit-license -# Copyright (c) 2011 Rafael Caricio rafael@caricio.com diff --git a/vows/sandbox/main/admin.py b/vows/sandbox/main/admin.py index f7e6678..e09a757 100644 --- a/vows/sandbox/main/admin.py +++ b/vows/sandbox/main/admin.py @@ -10,7 +10,8 @@ from django.contrib import admin -from sandbox.main.models import StringModel +from models import StringModel + class StringModelAdmin(admin.ModelAdmin): list_display = ('name', ) diff --git a/vows/sandbox/main/models.py b/vows/sandbox/main/models.py index f1c183e..8c7dbca 100644 --- a/vows/sandbox/main/models.py +++ b/vows/sandbox/main/models.py @@ -10,5 +10,6 @@ from django.db import models + class StringModel(models.Model): name = models.CharField(max_length=100) diff --git a/vows/sandbox/main/urls.py b/vows/sandbox/main/urls.py new file mode 100644 index 0000000..e69de29 diff --git a/vows/sandbox/main/views.py b/vows/sandbox/main/views.py index b956c7c..cefbb26 100644 --- a/vows/sandbox/main/views.py +++ b/vows/sandbox/main/views.py @@ -15,6 +15,7 @@ from django.http import HttpResponse def home(request): return HttpResponse('hello world') + def say_hello(request): SAY_HELLO_WITHOUT_NAME = getattr(settings, "SAY_HELLO_WITHOUT_NAME", False) if 'name' in request.GET: @@ -25,8 +26,10 @@ def say_hello(request): return HttpResponse("What's your name?") return HttpResponse("Hello, %s!" % name) + def post_it(request): return HttpResponse(request.POST['value']) + def post_file(request): return HttpResponse(request.FILES['the_file'].read().strip()) diff --git a/vows/sandbox/manage.py b/vows/sandbox/manage.py index 3e4eedc..3b13742 100755 --- a/vows/sandbox/manage.py +++ b/vows/sandbox/manage.py @@ -1,14 +1,10 @@ #!/usr/bin/env python -from django.core.management import execute_manager -import imp -try: - imp.find_module('settings') # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) - sys.exit(1) - -import settings +import os +import sys if __name__ == "__main__": - execute_manager(settings) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sandbox.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/vows/sandbox/sandbox/__init__.py b/vows/sandbox/sandbox/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vows/sandbox/sandbox/settings.py b/vows/sandbox/sandbox/settings.py new file mode 100644 index 0000000..2ddacc8 --- /dev/null +++ b/vows/sandbox/sandbox/settings.py @@ -0,0 +1,109 @@ +""" +Django settings for sandbox project. + +Generated by 'django-admin startproject' using Django 1.8.3. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# 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__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '+1e*=5h9ri-$#@xmgs*9wrm&@d#li6d9u3e&atmzo5s*6k%_#o' + +# 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', + + 'sandbox.main', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + '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', +) + +ROOT_URLCONF = 'sandbox.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(BASE_DIR, "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 = 'sandbox.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/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.8/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.8/howto/static-files/ + +STATIC_URL = '/static/' + +# Custom config to be used in tests +SAY_HELLO_WITHOUT_NAME = False diff --git a/vows/sandbox/sandbox/urls.py b/vows/sandbox/sandbox/urls.py new file mode 100644 index 0000000..6a48525 --- /dev/null +++ b/vows/sandbox/sandbox/urls.py @@ -0,0 +1,25 @@ +"""sandbox URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) +""" +from django.conf.urls import url +from main.views import home, say_hello, post_it, post_file + + +urlpatterns = [ + url(r'^$', home, name='home'), + url(r'^say/$', say_hello, name='say_hello'), + url(r'^post_it/$', post_it, name='post_it'), + url(r'^post_file/$', post_file, name='post_file'), +] diff --git a/vows/sandbox/sandbox/wsgi.py b/vows/sandbox/sandbox/wsgi.py new file mode 100644 index 0000000..0e7d688 --- /dev/null +++ b/vows/sandbox/sandbox/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sandbox 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/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sandbox.settings") + +application = get_wsgi_application()