From: Radek Czajka Date: Wed, 2 Apr 2014 11:51:44 +0000 (+0200) Subject: Django 1.6 X-Git-Url: https://git.mdrn.pl/koed-quiz.git/commitdiff_plain/a384028a39ea0546549ce29b4020e73a71f6b7c7?ds=inline Django 1.6 --- diff --git a/NOTICE b/NOTICE old mode 100755 new mode 100644 diff --git a/apps/quiz/templates/quiz/question_detail.html b/apps/quiz/templates/quiz/question_detail.html index c219434..691d5ae 100755 --- a/apps/quiz/templates/quiz/question_detail.html +++ b/apps/quiz/templates/quiz/question_detail.html @@ -1,6 +1,5 @@ {% extends "quiz/base.html" %} {% load i18n %} -{% load url from future %} {% block "title" %}{{ question.quiz.name }}{% endblock %} diff --git a/apps/quiz/templates/quiz/result_detail.html b/apps/quiz/templates/quiz/result_detail.html index 4b04ef2..6d66753 100755 --- a/apps/quiz/templates/quiz/result_detail.html +++ b/apps/quiz/templates/quiz/result_detail.html @@ -1,6 +1,5 @@ {% extends "quiz/base.html" %} {% load i18n %} -{% load url from future %} {% block "title" %}{{ result.quiz.name }}{% endblock %} diff --git a/apps/quiz/urls.py b/apps/quiz/urls.py index 8d43f02..6241cd8 100644 --- a/apps/quiz/urls.py +++ b/apps/quiz/urls.py @@ -2,7 +2,7 @@ # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url urlpatterns = patterns('quiz.views', diff --git a/fabfile.py b/fabfile.py index e06bdda..c3de350 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,233 +1,22 @@ -from __future__ import with_statement # needed for python 2.5 -from fabric.api import * -from fabric.contrib import files +from fnpdjango.deploy import * -import os - -# ========== -# = Config = -# ========== -# Globals env.project_name = 'koedquiz' -env.wsgi_name = env.project_name -env.use_south = True -env.virtualenv = '/usr/bin/virtualenv' - -# Servers -def localhost(): - """SSH to localhost (for debugging). - - This will deploy to `test-deployment` in the project dir. - - """ - import os.path - from getpass import getuser - - env.hosts = ['localhost'] - env.user = getuser() - env.path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test-deployment') - # This goes to VHost configuration - env.server_name = 'koedquiz.example.com' - env.server_admin = 'koedquiz ' - # /var/log/apache2/* logs - env.access_log = 'koedquiz.log' - env.error_log = 'koedquiz-errors.log' - - -# add additional servers here +@task def openquiz(): env.hosts = ['giewont.icm.edu.pl'] env.user = 'rczajka' - env.path = '/srv/koedquiz/openquiz' - env.server_name = 'otwartosc.nowoczesnapolska.org.pl' - env.server_admin = 'Radek Czajka ' - env.access_log = 'koedquiz/openquiz.log' - env.error_log = 'koedquiz/openquiz-errors.log' - env.wsgi_name = 'openquiz' + env.app_path = '/srv/koedquiz/openquiz' + env.services = [ + DebianGunicorn('openquiz'), + ] +@task def pdquiz(): env.hosts = ['giewont.icm.edu.pl'] env.user = 'rczajka' - env.path = '/srv/koedquiz/pdquiz' - env.server_name = 'domena.nowoczesnapolska.org.pl' - env.server_admin = 'Radek Czajka ' - env.access_log = 'koedquiz/pdquiz.log' - env.error_log = 'koedquiz/pdquiz-errors.log' - env.wsgi_name = 'pdquiz' - - - -servers = [localhost, openquiz, pdquiz] - -# ========= -# = Tasks = -# ========= -def test(): - "Run the test suite and bail out if it fails" - require('hosts', 'path', provided_by=servers) - require('python', provided_by=[find_python]) - result = run('cd %(path)s/%(project_name)s; %(python)s manage.py test' % env) - -def setup(): - """ - Setup a fresh virtualenv as well as a few useful directories, then run - a full deployment. virtualenv with pip should be already installed. - """ - require('hosts', 'path', 'virtualenv', provided_by=servers) - - run('mkdir -p %(path)s; cd %(path)s; %(virtualenv)s ve;' % env, pty=True) - run('cd %(path)s; mkdir releases; mkdir packages;' % env, pty=True) - run('cd %(path)s/releases; ln -s . current; ln -s . previous' % env, pty=True) - upload_default_localsettings() - deploy() - -def deploy(): - """ - Deploy the latest version of the site to the servers, - install any required third party modules, - install the virtual host and then restart the webserver - """ - - import time - env.release = time.strftime('%Y-%m-%dT%H%M') - - upload_tar_from_git() - find_python() - upload_wsgi_script() - upload_vhost_sample() - install_requirements() - copy_localsettings() - symlink_current_release() - collectstatic() - migrate() - restart_webserver() - -def deploy_version(version): - "Specify a specific version to be made live" - require('hosts', 'path', provided_by=servers) - env.version = version - with cd(env.path): - run('rm releases/previous; mv releases/current releases/previous;', pty=True) - run('ln -s %(version)s releases/current' % env, pty=True) - restart_webserver() - -def rollback(): - """ - Limited rollback capability. Simple loads the previously current - version of the code. Rolling back again will swap between the two. - """ - require('hosts', 'path', provided_by=servers) - with cd(env.path): - run('mv releases/current releases/_previous;', pty=True) - run('mv releases/previous releases/current;', pty=True) - run('mv releases/_previous releases/previous;', pty=True) - restart_webserver() - - -# ===================================================================== -# = Helpers. These are called by other functions rather than directly = -# ===================================================================== -def upload_tar_from_git(): - "Create an archive from the current Git branch and upload it" - print '>>> upload tar from git' - require('path', provided_by=servers) - require('release', provided_by=[deploy]) - local('/bin/bash lib/git-archive-all.sh --format tar %(release)s.tar' % env) - local('gzip %(release)s.tar' % env) - run('mkdir -p %(path)s/releases/%(release)s' % env, pty=True) - run('mkdir -p %(path)s/packages' % env, pty=True) - put('%(release)s.tar.gz' % env, '%(path)s/packages/' % env) - run('cd %(path)s/releases/%(release)s && tar zxf ../../packages/%(release)s.tar.gz' % env, pty=True) - local('rm %(release)s.tar.gz' % env) - -def find_python(): - "Finds where virtualenv Python stuff is" - print ">>> find Python paths" - require('path', provided_by=servers) - env.python = '%(path)s/ve/bin/python' % env - env.pip = '%(path)s/ve/bin/pip' % env - env.site_packages = run('%(python)s -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"' % env) - -def upload_vhost_sample(): - "Create and upload Apache virtual host configuration sample" - print ">>> upload vhost sample" - require('path', 'project_name', 'user', provided_by=servers) - require('access_log', 'error_log', 'server_admin', 'server_name', provided_by=servers) - require('site_packages', provided_by=[find_python]) - files.upload_template('%(project_name)s.vhost.template' % env, '%(path)s/%(project_name)s.vhost' % env, context=env) - -def upload_wsgi_script(): - "Create and upload a wsgi script sample" - print ">>> upload wsgi script sample" - require('path', 'project_name', provided_by=servers) - require('python', 'site_packages', provided_by=[find_python]) - files.upload_template('%(project_name)s.wsgi.template' % env, '%(path)s/%(project_name)s.wsgi' % env, context=env) - run('chmod ug+x %(path)s/%(project_name)s.wsgi' % env) - -def install_requirements(): - "Install the required packages from the requirements file using pip" - print '>>> install requirements' - require('path', provided_by=servers) - require('release', provided_by=[deploy]) - require('pip', provided_by=[find_python]) - run('%(pip)s install -r %(path)s/releases/%(release)s/requirements.txt' % env, pty=True) - -def secret_key(): - """Generates a new SECRET_KEY.""" - from random import Random - import string - - r = Random() - return "".join(r.choice(string.printable) for i in range(64)) - -def upload_default_localsettings(): - "Uploads localsettings.py with media paths and stuff" - print ">>> upload default localsettings.py" - require('path', provided_by=servers) - - env.secret_key = secret_key() - files.upload_template('%(project_name)s/localsettings.py.template' % env, '%(path)s/localsettings.py' % env, context=env) - -def copy_localsettings(): - "Copy localsettings.py from root directory to release directory (if this file exists)" - print ">>> copy localsettings" - require('path', 'project_name', provided_by=servers) - require('release', provided_by=[deploy]) - - with settings(warn_only=True): - run('cp %(path)s/localsettings.py %(path)s/releases/%(release)s/%(project_name)s' % env) - -def symlink_current_release(): - "Symlink our current release" - print '>>> symlink current release' - require('path', provided_by=servers) - require('release', provided_by=[deploy]) - with cd(env.path): - run('rm releases/previous; mv releases/current releases/previous') - run('ln -s %(release)s releases/current' % env) - -def collectstatic(): - """Runs collectstatic management command from Django staticfiles.""" - print '>>> collectstatic' - require('path', 'project_name', provided_by=servers) - require('python', provided_by=[find_python]) - with cd('%(path)s/releases/current/%(project_name)s' % env): - run('%(python)s manage.py collectstatic --noinput' % env, pty=True) - -def migrate(): - "Update the database" - print '>>> migrate' - require('path', 'project_name', provided_by=servers) - require('python', provided_by=[find_python]) - with cd('%(path)s/releases/current/%(project_name)s' % env): - run('%(python)s manage.py syncdb --noinput' % env, pty=True) - if env.use_south: - run('%(python)s manage.py migrate' % env, pty=True) - -def restart_webserver(): - "Restart the web server" - print '>>> restart webserver' - require('path', 'project_name', provided_by=servers) - run('touch %(path)s/%(project_name)s.wsgi' % env) + env.app_path = '/srv/koedquiz/pdquiz' + env.services = [ + DebianGunicorn('pdquiz'), + ] diff --git a/koedquiz/manage.py b/koedquiz/manage.py deleted file mode 100755 index eb91c2d..0000000 --- a/koedquiz/manage.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -import os.path -import sys - -ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# Add apps and lib directories to PYTHONPATH -sys.path = [ - os.path.join(ROOT, 'apps'), - os.path.join(ROOT, 'lib'), - # add /lib/* paths here for submodules -] + sys.path - -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 - -if __name__ == "__main__": - execute_manager(settings) diff --git a/koedquiz/urls.py b/koedquiz/urls.py index 207af23..7ff451a 100644 --- a/koedquiz/urls.py +++ b/koedquiz/urls.py @@ -2,7 +2,7 @@ # This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.conf.urls.defaults import patterns, include, url +from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() diff --git a/koedquiz/wsgi.py b/koedquiz/wsgi.py new file mode 100644 index 0000000..628b5b1 --- /dev/null +++ b/koedquiz/wsgi.py @@ -0,0 +1,19 @@ +import os +import os.path +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# Add apps and lib directories to PYTHONPATH +sys.path = [ + ROOT, + os.path.join(ROOT, 'apps'), +] + sys.path + + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "koedquiz.settings") + +# This application object is used by the development server +# as well as any WSGI server configured to use this file. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/lib/git-archive-all.sh b/lib/git-archive-all.sh deleted file mode 100644 index 95e8582..0000000 --- a/lib/git-archive-all.sh +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/bash - -# -# File: git-archive-all.sh -# -# Description: A utility script that builds an archive file(s) of all -# git repositories and submodules in the current path. -# Useful for creating a single tarfile of a git super- -# project that contains other submodules. -# -# Examples: Use git-archive-all.sh to create archive distributions -# from git repositories. To use, simply do: -# -# cd $GIT_DIR; git-archive-all.sh -# -# where $GIT_DIR is the root of your git superproject. -# -# License: GPL3 -# -############################################################################### -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -############################################################################### - -# DEBUGGING -set -e -set -C # noclobber - -# TRAP SIGNALS -trap 'cleanup' QUIT EXIT - -# For security reasons, explicitly set the internal field separator -# to newline, space, tab -OLD_IFS=$IFS -IFS=' - ' - -function cleanup () { - rm -f $TMPFILE - rm -f $TOARCHIVE - IFS="$OLD_IFS" -} - -function usage () { - echo "Usage is as follows:" - echo - echo "$PROGRAM <--version>" - echo " Prints the program version number on a line by itself and exits." - echo - echo "$PROGRAM <--usage|--help|-?>" - echo " Prints this usage output and exits." - echo - echo "$PROGRAM [--format ] [--prefix ] [--separate|-s] [output_file]" - echo " Creates an archive for the entire git superproject, and its submodules" - echo " using the passed parameters, described below." - echo - echo " If '--format' is specified, the archive is created with the named" - echo " git archiver backend. Obviously, this must be a backend that git archive" - echo " understands. The format defaults to 'tar' if not specified." - echo - echo " If '--prefix' is specified, the archive's superproject and all submodules" - echo " are created with the prefix named. The default is to not use one." - echo - echo " If '--separate' or '-s' is specified, individual archives will be created" - echo " for each of the superproject itself and its submodules. The default is to" - echo " concatenate individual archives into one larger archive." - echo - echo " If 'output_file' is specified, the resulting archive is created as the" - echo " file named. This parameter is essentially a path that must be writeable." - echo " When combined with '--separate' ('-s') this path must refer to a directory." - echo " Without this parameter or when combined with '--separate' the resulting" - echo " archive(s) are named with a dot-separated path of the archived directory and" - echo " a file extension equal to their format (e.g., 'superdir.submodule1dir.tar')." -} - -function version () { - echo "$PROGRAM version $VERSION" -} - -# Internal variables and initializations. -readonly PROGRAM=`basename "$0"` -readonly VERSION=0.2 - -OLD_PWD="`pwd`" -TMPDIR=${TMPDIR:-/tmp} -TMPFILE=`mktemp "$TMPDIR/$PROGRAM.XXXXXX"` # Create a place to store our work's progress -TOARCHIVE=`mktemp "$TMPDIR/$PROGRAM.toarchive.XXXXXX"` -OUT_FILE=$OLD_PWD # assume "this directory" without a name change by default -SEPARATE=0 - -FORMAT=tar -PREFIX= -TREEISH=HEAD - -# RETURN VALUES/EXIT STATUS CODES -readonly E_BAD_OPTION=254 -readonly E_UNKNOWN=255 - -# Process command-line arguments. -while test $# -gt 0; do - case $1 in - --format ) - shift - FORMAT="$1" - shift - ;; - - --prefix ) - shift - PREFIX="$1" - shift - ;; - - --separate | -s ) - shift - SEPARATE=1 - ;; - - --version ) - version - exit - ;; - - -? | --usage | --help ) - usage - exit - ;; - - -* ) - echo "Unrecognized option: $1" >&2 - usage - exit $E_BAD_OPTION - ;; - - * ) - break - ;; - esac -done - -if [ ! -z "$1" ]; then - OUT_FILE="$1" - shift -fi - -# Validate parameters; error early, error often. -if [ $SEPARATE -eq 1 -a ! -d $OUT_FILE ]; then - echo "When creating multiple archives, your destination must be a directory." - echo "If it's not, you risk being surprised when your files are overwritten." - exit -elif [ `git config -l | grep -q '^core\.bare=false'; echo $?` -ne 0 ]; then - echo "$PROGRAM must be run from a git working copy (i.e., not a bare repository)." - exit -fi - -# Create the superproject's git archive -git archive --format=$FORMAT --prefix="$PREFIX" $TREEISH > $TMPDIR/$(basename $(pwd)).$FORMAT -echo $TMPDIR/$(basename $(pwd)).$FORMAT >| $TMPFILE # clobber on purpose -superfile=`head -n 1 $TMPFILE` - -# find all '.git' dirs, these show us the remaining to-be-archived dirs -find . -name '.git' -type d -print | sed -e 's/^\.\///' -e 's/\.git$//' | (grep -v '^$' || echo -n) >> $TOARCHIVE - -while read path; do - TREEISH=$(git submodule | grep "^ .*${path%/} " | cut -d ' ' -f 2) # git submodule does not list trailing slashes in $path - cd "$path" - git archive --format=$FORMAT --prefix="${PREFIX}$path" ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT - if [ $FORMAT == 'zip' ]; then - # delete the empty directory entry; zipped submodules won't unzip if we don't do this - zip -d "$(tail -n 1 $TMPFILE)" "${PREFIX}${path%/}" >/dev/null # remove trailing '/' - fi - echo "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT >> $TMPFILE - cd "$OLD_PWD" -done < $TOARCHIVE - -# Concatenate archives into a super-archive. -if [ $SEPARATE -eq 0 ]; then - if [ $FORMAT == 'tar' ]; then - sed -e '1d' $TMPFILE | while read file; do - tar --concatenate -f "$superfile" "$file" && rm -f "$file" - done - elif [ $FORMAT == 'zip' ]; then - sed -e '1d' $TMPFILE | while read file; do - # zip incorrectly stores the full path, so cd and then grow - cd `dirname "$file"` - zip -g "$superfile" `basename "$file"` && rm -f "$file" - done - cd "$OLD_PWD" - fi - - echo "$superfile" >| $TMPFILE # clobber on purpose -fi - -while read file; do - mv "$file" "$OUT_FILE" -done < $TMPFILE diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..bc211fe --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +ROOT = os.path.dirname(os.path.abspath(__file__)) +sys.path = [ + os.path.join(ROOT, 'apps'), +] + sys.path + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "koedquiz.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/requirements-dev.txt b/requirements-dev.txt index aec394f..e400248 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,5 @@ +-i http://pypi.nowoczesnapolska.org.pl/simple + django-debug-toolbar +fnpdjango +Fabric diff --git a/requirements.txt b/requirements.txt index 20e6116..0212b10 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +-i http://pypi.nowoczesnapolska.org.pl/simple + # Django basics -django>=1.3,<1.4 +django>=1.6,<1.7 South>=0.7