Permalink
Browse files

adaptions for Django 1.4

  • Loading branch information...
1 parent 944a1ea commit b28c7fe430f4e0b9bad288fd97a615c97d2409f2 @fiee committed Nov 25, 2012
Showing with 170 additions and 36 deletions.
  1. +3 −2 README.rst
  2. +3 −3 apache2.conf
  3. +0 −7 django.wsgi
  4. +5 −5 fabfile.py
  5. +10 −0 manage.py
  6. +0 −11 project_name/manage.py
  7. +32 −6 project_name/settings.py
  8. +1 −1 project_name/urls.py
  9. +31 −0 project_name/wsgi.py
  10. +2 −0 supervisor.ini
  11. +82 −0 tools/makeproject.py
  12. +1 −1 tools/nginxsite.sh
View
@@ -17,7 +17,7 @@ Requirements
* local OS: MacOS X (only some local settings are OSX specific)
* web server: Apache/mod_wsgi or Nginx/gunicorn or Nginx/fcgi
* Python_ version: 2.5+
-* Django_ version: 1.3
+* Django_ version: 1.4
* version control: Git_
* deployment tool: Fabric_
* local development database: SQLite3_
@@ -61,7 +61,7 @@ local:
* copy `generic_project`
* replace all occurrences of lowercase "project_name" with your project name. this is also the webserver and database server username!
-* check the settings in fabfile.py_, gunicorn-settings.py_, settings.py_, settings_local.py_, supervisor.ini_ or service-run.sh_
+* check the settings in manage.py_, fabfile.py_, gunicorn-settings.py_, settings.py_, settings_local.py_, supervisor.ini_ or service-run.sh_
* set up an email account for your project’s error messages and configure it in settings.py_
* if you use Nginx, change the internal port in nginx.conf_ (``fastcgi_pass 127.0.0.1:8001;``); I use "8 + last 3 numbers of UID" (UIDs start at 1000 on Debian): ``id -u project_name``
* ``git init``, always commit all changes
@@ -159,6 +159,7 @@ Modules:
.. _Redis: http://redis.io
.. _makeuser.sh: blob/master/tools/makeuser.sh
+.. _manage.py: blob/master/manage.py
.. _settings.py: blob/master/project_name/settings.py
.. _settings_local.py: blob/master/project_name/settings_local.py
.. _gunicorn-settings.py: blob/master/gunicorn-settings.py
View
@@ -19,7 +19,7 @@
</Location>
# general admin media
- Alias /django_admin_media /var/www/project_name/lib/python2.5/site-packages/django/contrib/admin/media
+ Alias /django_admin_media /var/www/project_name/lib/python2.7/site-packages/django/contrib/admin/media
<Location "/django_admin_media">
SetHandler None
</Location>
@@ -36,9 +36,9 @@
SetHandler None
</Location>
- WSGIDaemonProcess project_name-production user=project_name group=project_name threads=10 maximum-requests=2000 python-path=/var/www/project_name/lib/python2.5/site-packages:/var/www/python
+ WSGIDaemonProcess project_name-production user=project_name group=project_name threads=10 maximum-requests=2000 python-path=/var/www/project_name/lib/python2.7/site-packages:/var/www/python
WSGIProcessGroup project_name-production
- WSGIScriptAlias / /var/www/project_name/releases/current/django.wsgi
+ WSGIScriptAlias / /var/www/project_name/releases/current/project_name/wsgi.py
ErrorLog /var/www/project_name/logs/error.log
LogLevel warn
View
@@ -1,7 +0,0 @@
-import os
-import sys
-# put the Django project on sys.path
-sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
-os.environ["DJANGO_SETTINGS_MODULE"] = "project_name.settings"
-from django.core.handlers.wsgi import WSGIHandler
-application = WSGIHandler()
View
@@ -218,20 +218,20 @@ def symlink_current_release():
# copy South migrations from previous release, if there are any
run('cd releases/previous/%(prj_name)s; if [ -d migrations ]; then cp -r migrations ../../current/%(prj_name)s/; fi' % env, pty=True)
# collect static files
- with cd('releases/current/%(prj_name)s' % env):
+ with cd('releases/current'):
run('%(path)s/bin/python manage.py collectstatic -v0 --noinput' % env, pty=True)
if env.use_photologue:
- run('cd static; rm -rf photologue; ln -s %(path)s/photologue photologue;' % env, pty=True)
+ run('cd %(prj_name)s/static; rm -rf photologue; ln -s %(path)s/photologue photologue;' % env, pty=True)
def migrate(param=''):
"Update the database"
require('prj_name')
require('path')
env.southparam = '--auto'
if param=='first':
- run('cd %(path)s/releases/current/%(prj_name)s; %(path)s/bin/python manage.py syncdb --noinput' % env, pty=True)
+ run('cd %(path)s/releases/current; %(path)s/bin/python manage.py syncdb --noinput' % env, pty=True)
env.southparam = '--initial'
- #with cd('%(path)s/releases/current/%(prj_name)s' % env):
+ #with cd('%(path)s/releases/current' % env):
# run('%(path)s/bin/python manage.py schemamigration %(prj_name)s %(southparam)s && %(path)s/bin/python manage.py migrate %(prj_name)s' % env)
# # TODO: should also migrate other apps! get migrations from previous releases
@@ -249,5 +249,5 @@ def restart_webserver():
if env.use_celery:
sudo('supervisorctl restart %(prj_name)s:celery' % env, pty=True)
#require('prj_name')
- #run('cd %(path)s; bin/python releases/current/%(prj_name)s/manage.py runfcgi method=threaded maxchildren=6 maxspare=4 minspare=2 host=127.0.0.1 port=%(port)s pidfile=./logs/django.pid' % env)
+ #run('cd %(path)s; bin/python releases/current/manage.py runfcgi method=threaded maxchildren=6 maxspare=4 minspare=2 host=127.0.0.1 port=%(port)s pidfile=./logs/django.pid' % env)
sudo('/etc/init.d/%(webserver)s reload' % env, pty=True)
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
View
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-from django.core.management import execute_manager
-try:
- import 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(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
- sys.exit(1)
-
-if __name__ == "__main__":
- execute_manager(settings)
View
@@ -147,7 +147,7 @@
DATABASES = {
'default': {
- 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': PROJECT_NAME, # Or path to database file if using sqlite3.
'USER': PROJECT_NAME, # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
@@ -160,12 +160,14 @@
# i18n and url settings
# ==============================================================================
-TIME_ZONE = 'Europe/Zurich'
-LANGUAGE_CODE = 'de'
+TIME_ZONE = 'Europe/Berlin'
+LANGUAGE_CODE = 'de' # 'en-us'
LANGUAGES = (('en', _(u'English')),
('de', _(u'German')))
USE_I18N = True
USE_L10N = True
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
LOCALE_PATHS = (
rel('locale/'),
@@ -175,15 +177,38 @@
ROOT_URLCONF = '%s.urls' % PROJECT_NAME
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = '%s.wsgi.application' % PROJECT_NAME
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
# don’t use /media/! FeinCMS’ media library uses MEDIA_ROOT/medialibrary
MEDIA_ROOT = rootrel('')
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/'
# setup Django 1.3 staticfiles
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
STATIC_ROOT = rel('static_collection')
-STATICFILES_DIRS = (rel('static'), ) #'.../feincms/media',
-ADMIN_MEDIA_PREFIX = '%sadmin/' % STATIC_URL
+STATICFILES_DIRS = (
+ rel('static'),
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+) #'.../feincms/media',
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+ADMIN_MEDIA_PREFIX = '%sadmin/' % STATIC_URL # Don’t know if that’s still used
# ==============================================================================
# application and middleware settings
@@ -220,11 +245,12 @@
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
- #'django.middleware.csrf.CsrfResponseMiddleware', # Deprecated in Django 1.3
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.doc.XViewMiddleware', # for local IPs
+ # Uncomment the next line for simple clickjacking protection:
+ # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware', # last
]
View
@@ -1,5 +1,5 @@
from django.conf import settings
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.sitemaps import GenericSitemap
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
View
@@ -0,0 +1,31 @@
+"""
+WSGI config for project_name project.
+
+This module contains the WSGI application used by Django's development server
+and any production WSGI deployments. It should expose a module-level variable
+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
+this application via the ``WSGI_APPLICATION`` setting.
+
+Usually you will have the standard Django WSGI application here, but it also
+might make sense to replace the whole Django WSGI application with a custom one
+that later delegates to the Django one. For example, you could introduce WSGI
+middleware here, or combine a Django application with an application of another
+framework.
+
+"""
+import os
+#import sys
+## put the Django project on sys.path
+#sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)
View
@@ -1,5 +1,7 @@
; this is the configuration for supervisor
; "fab webserver deploy" will copy it to /etc/supervisor/project_name.ini
+; check if there’s a line like the following in your supervisord.conf, [supervisord] section:
+; environment=LANG=de_DE.UTF-8,LC_ALL=de_DE.UTF-8,LC_LANG=de_DE.UTF-8
[program:project_name]
command=/var/www/project_name/bin/python /var/www/project_name/releases/current/project_name/manage.py run_gunicorn -c /var/www/project_name/releases/current/gunicorn-settings.py
View
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+Configurator for new Django project, based on fiee's "generic_django_project".
+
+Uses `urwid` (ncurses wrapper/replacement) from http://excess.org/urwid/
+"""
+import os, sys
+import urwid
+
+def _(text):
+ return text
+
+palette = [
+ ('header', 'dark green', 'black', 'standout'),
+ ('footer', 'white', 'dark green', 'standout'),
+ ('button', 'white', 'dark cyan', 'underline'),
+ ('question', 'default,bold', 'default', 'bold'),
+ ('answer', 'dark green', 'default', 'default'),
+ ('bg', 'black', 'light gray'),
+]
+
+questions = [
+ ('project_name', _(u'Name of the project? (same as user on webserver and database!)'), 'project_name'),
+ ('project_root', _(u'Local project root?'), '~/workspace/'),
+ ('server_domain', _(u'Name of your domain? (without server name)'), 'example.com'),
+ ('server_name', _(u'Name of your web server? (without domain name)'), 'www'),
+ ('database_type', _(u'Database on server? (mysql, postgresql, sqlite)'), 'mysql'),
+ ('webserver', _(u'Webserver software? (apache+mod_wsgi, nginx+gunicorn, nginx+fcgi)'), 'nginx+gunicorn'),
+ ('processcontrol', _(u'Process supervision? (daemontools, supervisord'), 'supervisord'),
+ ('messagequeue', _(u'Message queue? (celery)'), ''),
+ ('modules', _(u'Use special modules? (feincms, medialibrary, photologue, south)'), 'feincms,medialibrary,south'),
+ ('server_root_user', _(u'Name of server admin user?'), 'root'),
+]
+
+# make directory below workspace
+# copy (or git clone) generic_django_project
+# replace "project_name" in files...
+# git init
+
+# use feincms, medialibrary, photologue, daemontools, supervisord, celery, nginx/apache, mysql/postgresql ?
+
+# get server name
+# get server root account
+# get server db root account
+# make user account
+# make db user account
+
+answers = {}
+
+widgets = [
+]
+offset = len(widgets) # number of widgets in front of questions
+for key, text, default in questions:
+ answers[key] = default
+ widgets.append(urwid.Edit(('question', u'%s\n' % text), default))
+
+content = urwid.SimpleListWalker(widgets)
+listbox = urwid.ListBox(content)
+
+def update(input):
+ focus_widget, position = listbox.get_focus()
+ if not hasattr(focus_widget, 'edit_text'):
+ return
+ if input == 'ctrl x': # delete input
+ focus_widget.edit_text = ''
+ if input in ('ctrl q', 'ctrl s', 'esc'):
+ raise urwid.ExitMainLoop()
+ key = questions[position-offset][0]
+ answers[key] = focus_widget.edit_text
+ listbox.set_focus(position+1)
+
+header = urwid.Padding(urwid.Text(('header', _(u' Configure your project. Have fun! '))))
+footer = urwid.Padding(urwid.Text(('footer', _(u' Abort with Ctrl-C, exit with Esc, delete a line with Ctrl-X. '))))
+
+frame = urwid.Frame(listbox, header, footer)
+
+loop = urwid.MainLoop(frame, palette, unhandled_input=update)
+loop.run()
+
+print answers
+# STILL DOES NOTHING!
View
@@ -52,7 +52,7 @@ then
else
export SERVER_PROTOCOL=http
echo "Starting $SITE on port $PORT..."
- cd $DJANGODIR; $PYTHON $DJANGODIR/manage.py runfcgi method=threaded maxchildren=6 maxspare=4 minspare=2 host=127.0.0.1 port=$PORT pidfile=$PIDFILE $DEBUG
+ cd $DJANGODIR; $PYTHON $DJANGODIR/../manage.py runfcgi method=threaded maxchildren=6 maxspare=4 minspare=2 host=127.0.0.1 port=$PORT pidfile=$PIDFILE $DEBUG
/etc/init.d/nginx reload
fi

0 comments on commit b28c7fe

Please sign in to comment.