django1.4 branch merged!

We merged the django1.4 branch with commit ef290a6031 on Jun 02, 2012

EDIT: We release PyLucid v1.0.0 today (Jun 04, 2012, commit eac8cc19)

The main goals of this release:

Small enhancements:

Compare master...django1.4 diff.

How to update a environment

Here the steps to update a existing virtualenv:

  1. call upgrade_pylucid_env.sh and update only "PyLucid"
  2. call upgrade_pylucid_env.sh again and update all
1
2
~$ cd PyLucid_env
~/PyLucid_env$ ./upgrade_pylucid_env.sh

Don't miss to restart the server process, after update ;)

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

Note: this should run without errors and you should see some output lines like * Update template: ...

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