I use the following directory hierarchy: /home/germ/web/projects/{admin-media,django,media,templates}/test1 (where test1 is the project name)

For all Django projects that don't have their own admin media:

ln -s /home/germ/django/trunk/django/contrib/admin/media /home/germ/web/projects/admin-media/myproject

In addition I put all project names in /etc/hosts so that I can access http://test1.localhost:8000/

127.0.0.1 localhost test1.localhost

It's a pain to tack on :8000 to the hostname everytime that I want to access the web site, so I use the following iptables, which redirects all traffic going to 127.0.0.1 on port 80 to port 8000:

iptables -t nat -I OUTPUT --src 0/0 --dst 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports 8000

I have decided to use lighttpd and fastcgi. I am doing so by applying JCrasta's patch to the trunk.

Here's my lighttpd.conf file:


# /etc/lighttpd/lighttpd.conf
# lighttpd configuration file

server.port = 8000
server.username = "lighttpd"
server.groupname = "lighttpd"
server.pid-file = "/var/run/lighttpd.pid"

server.modules = ( "mod_rewrite", "mod_redirect", "mod_alias",
                   "mod_access", "mod_fastcgi", "mod_accesslog" )

accesslog.filename = "/var/log/lighttpd/access.log"
server.errorlog = "/var/log/lighttpd/error.log"
server.indexfiles = ( "index.html" )

mimetype.assign = (
  ".css"  => "text/css",
  ".gif"  => "image/gif",
  ".html" => "text/html",
  ".jpeg" => "image/jpeg",
  ".jpg"  => "image/jpeg",
  ".js"   => "text/javascript",
  ".pdf"  => "application/pdf",
  ".png"  => "image/png",
  ".txt"  => "text/plain"
)

var.web_root = "/home/germ/web"

server.document-root = var.web_root + "/misc"

include_shell "cat /etc/lighttpd/hosts-enabled/*"

And here's the virtual host config for lighttpd.conf (I chose not to do simple-vhost, because I didn't find it appropriate for my directory structure and naming).


# /etc/lighttpd/hosts-enabled/test1.localhost (a symlink
#  /etc/lighttpd/hosts-available/test1.localhost)
$HTTP["host"] == "test1.localhost" {
  server.document-root = var.web_root + "/projects/django/test1"

fastcgi.server = ( "/test1.fcgi" =>
    ( "main" =>
      (
        "socket" => "/var/www/sockets/germ/test1.sock",
        "check-local" => "disable",
      )
    )
  )

alias.url = (
    "/media/" => var.web_root + "/projects/media/test1/",
    "/admin-media/" => var.web_root + "/projects/admin-media/test1/",
  )

url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^(/admin-media.*)$" => "$1",
    "^/favicon.ico$" => "/media/favicon.ico",
    "^(/.*)$" => "/test1.fcgi$1",
  )
}

Run your python project with python manage.py runfcgi daemonize=false socket=/var/www/sockets/germ/test1.sock

And point your browser to http://test1.localhost/ and BAM!

Dojo is so nice and easy. I finished what I thought was going to be a very difficult drag and drop task today. It doesn't work in IE, though, so I need to check into that. My next step is to integrate it with the django app I'm going to start working on tomorrow — and I'm excited about django's m-r merge into the main trunk. Getting dojo to work with django should be interesting, but not too difficult as some work has already been done with this. Getting dojo to work with ajax and django should be more difficult. Moreover, I think I'll be using JSON instead of XML (no standard, no foul).

Do I pick Dojo?

May 1, 2006

I am in need of Ajax and DnD for my latest Django project (which has not yet been implemented — only laid out), thus I am in need of a JavaScript toolkit to assist me. I looked at scriptalicious (prototype), Yahoo's Design Pattern Library (though, only briefly), and Dojo. I chose Dojo. But it was not an easy decision. The main reasons: their packaging system and Django's decision to back them. But, the biggest thing that was driving me away was their lack of examples and documentation.

This should be an interesting ride. Here's what one of the main Dojo Developers, Alex Russell, has to say about Dojo:

The main argument presented against Dojo here is that we're not driven by the design community, and it's true. We are trying to provide a solid engineering foundation for you to build on. We excel in giving good designers good tools, not in imposing our sensibility onto your projects.

Influential reads:
dojo.io.bind(): baking usability into XMLHTTP
Why I Don't Use The prototype.js JavaScript Library

Ok, while I'm all jacked up on coffee and am in the blogging mood…

Here is how I have setup my django development environment (inspired by http://e-scribe.com/news/212):

I have a script called django_project, which creates a screen session if one does not exist; if one does exist it will then just attach to the session. django_project takes in the following args when a screen session does not exist: django_project projectname /path/to/project/home /path/to/template/home; when a screen session does exist, just django_project projectname.

here's the django_project code:


#!/bin/bash
CONFIG_FILE='/home/germ/.screenrc.django'
E_BADARGS=65
if [ ! -n "$1" ]; then
echo "Usage: `basename $0` name_of_screen [project_home_dir template_dir]"
exit $E_BADARGS
fi
name=`echo $1 | tr '[:upper:]' '[:lower:]'`
if screen -ls | egrep '^[[:space:]]+[^[:space:]]' | awk '{print $1}' | egrep ".$name$"; then
screen -x $name
else
if [ ! -n "$2" ] && [ ! -n "$3" ]; then
echo "Usage (new screen): `basename $0` name_of_screen project_home_dir template_dir"
exit $E_BADARGS
fi
export SCREEN_DP_HOME=$2
export SCREEN_DP_TEMPLATES=$3
screen -c $CONFIG_FILE -S $name
fi

And here is .screenrc.django (what sets up the environment):


# detach on hangup
autodetach on
# multiple users
multiuser on
# annoying!
vbell off
# turn off copyright notice at startup
startup_message off
# remove the following bindings
bind k #kill
bind ^k #kill
bind . #dump termcap
bind ^h #hardcopy
bind h #hardcopy
bind A #title
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= mw}%-Lw%{= KW}%50>%n%f* %t%{= mw}%+Lw%<'
# keep the screen around when its process terminates
# k to kill; r to resurrect
zombie kr
# load the following screens
# $DJANGO_PROJECT_HOME and $DJANGO_PROJECT_TEMPLATES are used by the script
# which will prompt you for their values
chdir $SCREEN_DP_HOME
screen -t runserver     0   python manage.py runserver
chdir $SCREEN_DP_TEMPLATES
screen -t templates     1
chdir $SCREEN_DP_HOME
screen -t models        2
screen -t views         3
screen -t urls          4
screen -t d_shell       5   python manage.py shell
screen -t mysql         6   mysql -u django -p
screen -t misc          7

Django Development Screenshot

I learned a valuable lesson today:  before you start a project that relies on some hardware, price the hardware first.  I've completed all of the django code to track the amount of time spent on tasks (where each RFID Tag represents a task), but I cannot complete the project because it's going to cost over $400 in hardware.  Hmm… Xbox 360 or complete the project?

So, if anyone is feeling philanthropic, I need a 13.56 MHz RFID read/write module that interfaces over RS-232 (don't feel like spending the time on USB) and the Feig 13.56 MHz pad antenna.