developer info for django 1.4 branch

Here are notes for developer for the new django 1.4 branch. Migrate instruction for enduser would be created later!

We worked on django v1.4 support in a new branch: https://github.com/jedie/PyLucid/tree/django1.4 But it's not ready, yet. PyLucid run's well, but we would like to test it more...

The main goals of this release:

Small enhancements:

Compare master...django1.4 diff.

how to test

update a environment

IMHO it's easier to create a fresh, new virtualenv, see below.

Here the steps to update a existing virtualenv:

1
2
3
4
# Switch from master to django1.4 branch:
~/PyLucid_env/src/pylucid$ git checkout origin/django1.4 -t
Branch django1.4 set up to track remote branch django1.4 from origin.
Switched to a new branch 'django1.4'

Before upgrade, you can call the version info like this:

1
(PyLucid_env)~/PyLucid_env$ ./src/pylucid/scripts/upgrade_pylucid_env.py --version-info
./src/pylucid/scripts/upgrade_pylucid_env.py --version-info
 package name        installed version    versions on PyPi                                 
PyLucid              0.12.1.0524          0.11.4.0423
django-tools         0.23.1               0.23.1.0514
flup                 1.0.3.dev-20110405   1.0.3.dev-20110405 - 1.0.3.dev-20110111, 1.0.2
django-tagging       0.3.1                0.3.1
django-dbpreferences 0.4.4                0.4.4.1012
django-processinfo   0.6.2                0.6.1.0503
django-reversion     1.4                  1.6.0
django-dbtemplates   1.3                  1.3
python-creole        1.0.2                1.0.2
Pygments             1.4                  1.5
South                0.7.5                0.7.5
django-appconf       0.5                  0.5
feedparser           5.0.1                5.1.2
Django               1.3.1                1.4 - 1.3.1, 1.3, 1.2.7, 1.2.6, 1.2.5, 1.2.4, 1.2.3 ...

Now you can use upgrade_pylucid_env.sh to upgrade all packages except PyLucid editable!
At lease you must select:

  • Django
  • django_compressor
  • django-reversion
  • django-reversion-compare

See also /requirements/*.txt files in https://github.com/jedie/PyLucid/compare/django1.4

Note: After django1.4 was merged into master the update is easier:

  1. call upgrade_pylucid_env.sh and update only "PyLucid"
  2. call upgrade_pylucid_env.sh and update all

media -> static files

Now we used the django.contrib.staticfiles and used both MEDIA_ROOT / MEDIA_URL and STATIC_ROOT / STATIC_URL
In previous version we have only the MEDIA_ROOT to store every includes files. Now we add the STATIC_ROOT and split the files info:

STATIC_* static media files (images, CSS, Javascript) that are needed to render a complete web page.
MEDIA_* user-uploaded media files (e.g. images)

Needed changes in your local_settings.py:

1
2
3
4
5
6
7
+ STATIC_ROOT = "/var/www/YourSite/static/"
MEDIA_ROOT = "/var/www/YourSite/media/"

+ STATIC_URL = "/static/"
MEDIA_URL = "/media/"

- ADMIN_MEDIA_PREFIX = "/media/django/"

You can cleanup the media folder, e.g:

1
2
3
/var/www/YourSite$ rm media/django -rf
/var/www/YourSite$ rm media/PyLucid -rf
/var/www/YourSite$ rm media/PyLucid_cache -rf

Create STATIC_ROOT directory and collect all static files:

1
2
3
4
5
# create static directory
/var/www/YourSite$ mkdir static

# collect all static files
/var/www/YourSite$ ./manage.py collectstatic --link

(Without --link all files will be copied and not created by links)

Changes in templates, related to this are e.g.:

1
2
3
4
5
- DjangoTag0Assembly
+ DjangoTag1Assemblyadmin/

- DjangoTag2Assembly
+ DjangoTag3AssemblyPyLucid/

update a page instance

migrate database changes

1
2
# Do south migrations
/var/www/YourSite$ ./manage.py migrate

use django-compressor

To speed up the static file handling we use django_compressor to merge and compress CSS/JavaScript content.

Edit your page templates like this, e.g.:

Diff
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
+ {% compress js %}
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.min.js" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');" ></script>
<script type="text/javascript" src="{{ STATIC_URL }}PyLucid/pylucid_js_tools.js" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
+ {% endcompress %}

+ {% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}PyLucid/blueprint/screen.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="{{ STATIC_URL }}PyLucid/blueprint/print.css" type="text/css" media="print" />
<!--[if lt IE 8]>
  <link rel="stylesheet" href="{{ STATIC_URL }}PyLucid/blueprint/ie.css" type="text/css" media="screen, projection" />
<![endif]-->
+ {% endcompress %}

create a new environment

Create a test virtual environment with the django1.4 branch, just use the bootstrap file from the branch:

1
2
3
4
5
# get PyLucid boot script:
/home/FooBar$ wget https://raw.github.com/jedie/PyLucid/django1.4/bootstrap/pylucid-boot.py

# Create the PyLucid virtual environment:
/home/FooBar$ python pylucid-boot.py PyLucid_env

See also: http://www.pylucid.org/permalink/333/1a1-create-a-pylucid-environment-with-pylucid-boot

create new page instance

Is very similar to the old way. But syncdb and migration must be in two steps. Here all steps in short:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# create a new page instance with our script:
~/PyLucid_env$ ./create_page_instance.sh /var/www/YourSite
~/PyLucid_env$ cd /var/www/YourSite

# create all database tables (without creating a superuser at this time):
/var/www/YourSite$ ./manage.py syncdb --all --noinput

# Do faked south migrations
/var/www/YourSite$ ./manage.py migrate --fake

# Create a superuser:
/var/www/YourSite$ ./manage.py createsuperuser

# Load PyLucid base data into database:
/var/www/YourSite$ ./manage.py loaddata pylucid.json

# create initial revisions
/var/www/YourSite$ ./manage.py createinitialrevisions

# collect all static files as links
/var/www/YourSite$ ./manage.py collectstatic --link

dev.server

1
2
# startup dev server with static files served with index view:
/var/www/YourSite$ ./manage.py runserver 0.0.0.0:8000 --traceback --insecure --nostatic

Note: If you experiment and compressed static files would not be loaded, than clean the cache, e.g.:

1
$ rm /tmp/PyLucid_* -rf

see also: https://github.com/jezdez/django_compressor/issues/268