Adding a Chat application to pinax

Tuesday, 13th October, 2009

How do you add a Django application to Pinax? Below is my experience with one Django app. For some related reading see Fernando Correia’s series on Exploring Pinax and Greg Allard’s How to Write Reusable Apps for Pinax and Django.

Here I want to separate the two issues of (a) developing a Django app and (b) integrating a Django app into Pinax. This post will look at Pinax integration only, the only Django app “development” will be making sure the app is ready for integration. I am using a third-party Django application, namely jchat by Federico Cáceres, covered in his blog posts on his Django powered AJAX Chat project.

Prepare the application for integration

Really there is no specal preparation for Pinax per se: Pinax uses just ordinary Django apps. The main thing is that the app should live outside of the Pinax application itself, and in your system’s normal Python Path (or your pinax-env’s Python Path if that’s different). If you’ve developed (or are working with) a Django app that has been written to live inside Django (e.g., in the same folder as manage.py, settings.py, etc.), some minor re-organisation may be necessary.

I looked at the Django apps in my Python installation’s site-packages directory and followed their conventions, settling on a directory structure like this:

jchat/
jchat/media/ # static content in here, e.g. css/, img/, js/
jchat/templates/jchat/ # templates here
jchat/__init__.py
jchat/models.py
jchat/urls.py
jchat/views.py

Pinax integration

Only three small changes are necessary to the Pinax installation to integrate the new app. In the following I assume the Pinax installation is at pinax_app/:

1. Tell Pinax where to find your application

Add the name of your application (i.e., the name of the top-level directory with containing __init__.py) to the list of INSTALLED_APPS in pinax_app/settings.py:

INSTALLED_APPS = (
    # ...
    'jchat',
)

2. Tell Pinax where to find your application’s urls

Add a line for the new app to the urlpatterns list in pinax_app/urls.py:

urlpatterns = patterns('',
    # ...
    (r'^jchat/', include('jchat.urls')),
)

3. Add a tab for the new app

If your Pinax installation is using the default templates with its tab bar, you can add the following line to the right_tabs block in templates/site_base.html (depending on your version of Pinax the block could be a table or a ul):

  • earlier versions? # tested by me
    <td class="tab rtab_jchat"><div><a href="{% url jchat %}">{% trans "Chat" %}</a></div></td>
  • Pinax 0.7.1 # not tested by me
    <li id="tab_jchat"><a href="{% url jchat %}">{% trans "Chat" %}</a></li>

Run a test

Run python manage.py syncdb to add any new models to the database, then python manage.py runserver to run the test server. The new application should be integrated with your Pinax application and working as expected.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: