Thursday, September 3, 2009

Pyjamas vs. Django

My hobby project is to create a website for my girlfriend's business. I don't want to reveal too much but the website will need to display the usual corporate information like services available, contact details, previous client testimonials etc. There will also need to be a section where potential clients can view available timeslots and apply for a booking with a consultant at any of those timeslots. This will be the hard part.

I don't want a username login sorta thing as that's too complicated. I think it will be enough to show an Outlook-style date/time calendar showing what times are available and allowing the user to select from the remaining timeslots, providing their name and contact details so a consultant can call them back and arrange the booking. Once the booking is arranged, the consultant will have to update the system so that the timeslot is shown as unavailable.

As these is a certain amount of dynamic data involved in the site, I'll use Python and a web framework to make serialisation to a database easier. After shopping around I have found many people happy with Django. The needs of this website are very modest so when people complain about Django not holding up under heavy load those arguments don't really apply here. I'm all about building this site rapidly and robustly.

The other side of the fence is Pyjamas which is a Python port of Google Web Toolkit (GWT) which allows you to write code in Python (originally in Java) which will be automagically converted to HTML and JavaScript when you compile using the GWT/Pyjamas toolset.

I have decided that Django is the tool for the job as I have no need to AJAX functionality, just basic client/server communication with a little pizazz on the client end to make it look nice.

(edit) In further reading it appears these are pretty different tools- Pyjamas is a front end development and Django is a total solution. All the better for me.

First step: Django Tutorial
I installed Django 1.0.2 from the Ubuntu repo and some of the other Django related bits and pieces that sounded interesting. I'll stick with SQLite for now until I need a proper RDBMS. I see that Django is dependent on JQuery which is good- I was intending to use that to flash up the site.

I have set up a Pydev project and tried to run the command to create a Django site in that location but it can't find the file First I had to find out how to search the filesystem for a file (find -iname "filename") then I had to find out how to add that location to the system path.

Now the file is on the system path but when I cd to the project folder and run the command I get access denied. Next I sudo the command and it says it can't find the command. WTF?

So I find the file and edit it and the first line (which I believe indicates which binary should execute it) says "#!/usr/bin/env python". I had a look and /usr/bin/env doesn't exist! No idea why the default installation of Django would reference Python from a location that doesn't exist. Maybe I'm supposed to make a symlink there that points to my Python interpreter of choice? I'll learn how to create symlinks then try it out.

I don't have to create a symlink, it turns out that /usr/bin/env is some sort of environment variable list allowing me to change the location of the Python executable easily. It's a level of indirection so that the location of Python doesn't have to be hardcoded into .py files.

After much toiling around I have found that I can get it to work by running "/usr/bin/python createsite xxx". Not sure why I have to manually invoke Python, I would have thought it would automatically be associated with .py files? Anyway, that was needlessly difficult but I finally have a site up. I'll continue the Django tutorial and get started on the real work.

Second Time's a Charm

With my renewed vigor to get my hobby project off the ground, I've wiped my Ubuntu install, re-installed it from scratch and updated it via Synaptic. This time I'll draw on my previous experience and install the correct version of Subversion.

1. Eclipse
Eclipse install went smoothly. I won't upgrade it to 3.2.2 as that seemed to cause problems last time.

2. Subversion
I'm aware now that I need version 1.4.x of Subclipse to integrate with version 1.5.4 of Subversion that's available in the Ubuntu repository.
Subversion installed fine. Again I get the "No features available" message from the Subclipse 1.4.x update site. I will try downloading the site package but if that doesn't work I'm giving up on Subclipse.

This seems to be working- now it shows me the contents of the archive site on my local machine. Selecting to install Subclipse indicated that I need Draw2D dependency so I cancel out and request new features again, this time selecting the Callisto Discovery Site and Eclipse Update Site hoping the dependencies will be resolved automatically. It didn't resolve automatically but I found online that I need to manually select the Eclipse Graphical Editing Framework which has solved the issue. This step could definitely be made easier.

I choose to install Subclipse and Subclipse SVNKit Option. The Mylyn integration package sounds good but has dependencies that I can't find so it's not getting installed.

Great! Subclipse is installed and I can open a project from SVN. Better than last time already.

3. Pydev
I've elected to install Pydev + Extensions via the Eclipse update site. While this is proceeding I've had a look at what Mylyn is and it looks fantastic. Pity it appears to only be available in Eclipse 3.3+. Once I've got this version stable I might upgrade.

Right, Pydev installed fine and I'm ready to go! Woooot! Much easier this time around.

I still wonder why Help->About in Eclipse shows me that the version is 3.2.2 but when I look at the updates section it shows me Eclipse 3.2, Eclipse 3.2 Updates, Eclipse 3.2.1, Eclipse 3.2.1 Updates, Eclipse 3.2.2, Eclipse 3.2.2 Updates. I assume I should be installing the last one but the fact that displays old updates makes me apprehensive to install anything. I'll leave it alone for now as it's all stable and working.