This project uses South migrations for database management. South allows you to make changes to the database without dealing with raw SQL. The workflow is as follows:
-
Make some change to a model which affects the database, e.g. add a field.
-
Create a migration for this change. If the change was made to a model in the
core
application, this is achieved by running:./manage.py schemamigration core --auto
If it's the first migration for an app, replace
--auto
with--initial
. -
Run the migration. In the case of the
core
application, this means running:./manage.py migrate core
To run the migrations for all installed apps, including third party ones such as
taggit
, simply run:./manage.py migrate
Note: You need to run ./manage syncdb
once when you first set up the
project to prepare the database for South.
The CSS for this project is generated from stylesheets written in SASS using the Compass framework. Compass is a Ruby application which can be installed using RubyGems by running:
[sudo] gem install compass
(At the time of writing, this will install compass-0.12.2
and its dependencies
sass
, chunky_png
and fssm
.)
To have Compass pick up on changes to SASS files when they're saved, navigate
into the compass
directory and run:
compass watch
For a one-off compilation, run:
compass compile
from the same directory. Both will generate CSS from the files present in
compass/sass
and write to files in static/css
in accordance with the
settings in compass/config.rb
.
The Python packages required by this project are listed in the file
requirements.txt
. Assuming pip is present, these packages can be
installed with:
pip install -r requirements.txt
The file requirements_dev.txt
includes all of requirements.txt
as well as
packages that should only be installed in a development environment. Similarly,
requirements_prod.txt
includes packages only needed in a production
environment. Both of these can be passed to pip install
in the same way as
requirements.txt
.
Using a virtualenv environment is a good idea, both in development and production, as it allows you to maintain several different Python environments on one system, as well as install packages without root privileges. When using virtualenv with Apache and mod_wsgi, remember to set the WSGIPythonPath or to pass the right path to WSGIDaemonProcess.
For security reasons, the database configuration and SECRET_KEY
of the
project are kept out of Git. These settings, along with other configuration
variables which differ from development to production, are defined in the file
gdsp/settings_prod.py
. In production, this file needs to be present and the
environment variable DJANGO_PRODUCTION
needs to be set to a value which is
truthy in Python, e.g. 1
.
Updating the running application is a simple matter of following these steps from the root directory of the project:
-
Fetch the updated code:
git pull origin master
-
If you have added any Python packages (third party applications or libraries), these need to be installed. Assuming that you've added these packages to either
requirements.txt
orrequirements_prod.txt
, that you are usingvirtualenv
and that thevirtualenv
environment is kept in a directory.virtualenv
in your project root, this is achieved like so:# Enter virtualenv; this assumes you are running bash. source .virtualenv/bin/activate # Install the packages. requirements_prod.txt includes all of # requirements.txt, so packages listed there will also be installed. pip install -r requirements_prod.txt # Leave virtualenv (if you want to). deactivate
-
If you have added any static files (CSS, JavaScript, images etc.), you need to collect these into the directory whence static files are served:
# Enter virtualenv if you haven't already. source .virtualenv/bin/activate ./manage.py collectstatic
-
If you have made any changes to the database schema, i.e. you have added South migrations, you need to run these migrations:
# Enter virtualenv if you haven't already. source .virtualenv/bin/activate ./manage.py migrate
-
Now restart the application. Assuming you are running Apache with mod_wsgi in daemon mode, simply
touch
the WSGI application script:touch gdsp/wsgi.py