The following repository contains all the code to power the Open Transit Data web site.
It is an AppEngine application running Django 1.1.
If you want to run this application locally, follow these easy steps:
-
Make sure you have Python 2.5 installed
If you use a Mac with MacPorts, you can use python_select to choose python 2.5. Unforuntately, as of this writing, AppEngine does not support Python 2.6.
-
Install Django 1.1.
Unfortunately, the AppEngine development server does not like virtualenv, etc. So you'll have to install django 1.1 as a major package. easy_install is a good way to go.
-
Install the App Engine Python SDK.
-
cd
into this directory and rundev_appserver.py .
to get the local server running. -
Test by visiting
http://localhost:8080/
If you look at bootstrap.py
you'll see that it loads the Django 1.1 library (which is pre-installed on the AppEngine servers) and does a few things to load in settings.py
.
The opentransit
directory is the django "application." It is where all the real work of this application is going to get done. Chances are, if you want to write some code, you want to write it here.
The top-level urls.py
file simply loads URLs from opentransit/urls.py
. Any time you add a view (in opentransit/views.py
) you should also add a new url in opentransit/urls.py
.
We also have top-level static
and templates
directories. The static
directory is for truly static files, like images, javascript, and CSS. You can reference these cleanly in your django templates with {% static_url /images/foo.png %}
. The templates
directory contains Django 1.1-syntax templates. I put in an example base.html
and home.html
file which makes use of Django's {% extends ... %}
template tag. This is the way most people do things with Django but it is by no means required. These are example files only!
So, again, everything interesting code-wise is going to be under the opentransit/
subdirectory. Most interesting are views.py
, where you put your view functions, and models.py
, where you put your AppEngine model classes. Easy, right? forms.py
might also be interesting if we decide to use Django forms to handle our petition, etc. Django forms are not required, but they're easy to work with. I already added a petition example just to get us going.
I have also added a bunch of "helper" code in case we want to do more interesting things. Included in the opentransit
directory are:
-
Some new template tags:
static_url
makes it easy to reference stuff in ourstatic
top level directorypartial
is just like Django 1.1's include, except you can pass a state dictionary down to the included file. -
Some code to help us with login/logout of users.
My guess is that we will not need this code, which is spread across
utils.py
,middleware.py
andcontext.py
. You can happily ignore these files unless we decide we want users on AppEngine. -
A simple, example Django form.
Again, we don't have to use Django forms. But it may be nice to do so. So I put an example in
forms.py
-
A simple, example AppEngine mdoel.
This really is an AppEngine model, not a Django model. We can't use Django models when running on AppEngine.
-
Two simple, example views.
The corresponding templates link to one another using the
{% url ... %}
template tag.
Let me know if you have any questions. -- Dave