Django Quickies

Debugging in templates

<pre>{% debug %}</pre>

{{ form.error_dict|pprint }}</pre>

{{|pprint }}</pre>

Example of Edit Inline

class Poll(models.Model):
    question = models.CharField(maxlength = 200)

class Choice(models.Model):
    poll = models.ForeignKey(Poll, edit_inline=models.STACKED, num_in_admin=3)
    choice = models.CharField(maxlength = 200, core = True)
    votes = models.IntegerField(core = True)

urlpatterns = patterns('',
    (r'^poll_update/(?P<object_id>d+)/$', 'django.views.generic.create_update.update_object', {'model': Poll})


{% extends "base.html" %}
{% block content %}

{{ form.error_dict|pprint }}</pre>
{{|pprint }}</pre>

<p>Today's question is: <em>{{ object.question }}</em></p>

<form method="POST" action="./">

     <label for="id_question">Question:</label>{{ form.question }}

       {% for the_choice in form.choice %}
        {{ }}

        <TH><label for="id_choice.{{ forloop.counter0 }}.choice">Choice
        <TD>{{ the_choice.choice }}
        <TH><label for="id_votes.{{ forloop.counter0 }}.votes">Votes
        <TD>{{ the_choice.votes }}
   {% endfor %}

    <input type="submit" />

{% endblock %}

Send Emails

from django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', '',
    [''], fail_silently=False)

EMAIL_HOST_USER = 'username'

Generate RSS

from django.conf import settings
from django.utils import feedgenerator
from nm.models import Newsitem
import os

def generate_rss(self):

    file_name = "latest_news.rss"
    file_path = os.sep.join([settings.MEDIA_ROOT, file_name])
    file_url = os.sep.join([settings.MEDIA_URL, "site_media", file_name])

    feed = feedgenerator.Rss201rev2Feed(
        description=u"Dernières nouvelles",

    qs = Newsitem.objects.select_related().filter(...)[:50]

    for r in qs:
        text = "<br />".join([, "%s" % r.time, r.text])
        feed.add_item(title=r.title, link=r.get_absolute_url(), description="")

    fp = open(file_path, 'w')
    feed.write(fp, 'utf-8')

Reuse Login / Logout


 (r'^accounts/login/$', 'django.contrib.auth.views.login'),
 (r'^accounts/logout/$', 'django.contrib.auth.views.logout'),


(r'^accounts/profile/$', 'projectname.invoice.views.index'), # default page after login



{% block content %}

<div id="box"><h4>Login</h4></div>

{% if form.has_errors %}
<div id="alert">
    <p>Your username and password didn't match. Please try again.</p>
{% endif %}

{% if user.is_authenticated %}
<div id="alert">
    <p>You are already logged in as "{{ user }}".</p>
{% endif %}

<form method="post" action=".">
<tr><td><label for="id_username">Username:</label></td><td>{{ form.username }}</td></tr>
<tr><td><label for="id_password">Password:</label></td><td>{{ form.password }}</td></tr>
<input type="submit" value="Login" />
<input type="hidden" name="next" value="{{ next }}" />

{% endblock %}

Creating and Using Custom Filters



from django import template
from django.conf import settings

def nop(value):
    return value[3:-4]

register = template.Library()
register.filter('nop', nop)




{% load custom_filters %}
{{ object.address|linebreaks|nop }}

Reuse Django Admin Widgets and Graphics

urlpatterns = patterns('',
     (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': 'django.conf'}),


template file

<script type="text/javascript" src="/jsi18n/"></script>
<script type="text/javascript" src="/media/js/core.js"></script>
<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="/media/js/calendar.js"></script>
<script type="text/javascript" src="/media/js/admin/DateTimeShortcuts.js"></script>

<img src="/media/img/admin/icon_changelink.gif">

Comments off

wikiCalc goes 1.0

This might make sense to include within Potentially, we could make this available to teams so that they could post and keep track of scores or statistics. This might also be nice for Leagues to use to post standings, statistics or even a schedule. WikiCalc is written in Perl and released under the GPL 2.0 license.

Comments (1)

Online Learning

Taken from an article at

Managing Moodle

Moodle system administrators manage their CMS via a Web interface that includes control over nearly every aspect of the site. Site functionality includes a site-level calendar, emailing options, log and report analysis, and search engine interoperability. The interfaces are easy to use and generally come equipped with help buttons throughout the pages.

Moodle has addressed security issues as well, albeit in a minimalist fashion. Moodle uses SSL for logins; however, the sessions following the logins are not encrypted. Moodle also includes a GUI-based log viewing system as part of the administrator tools. It allows administrators to filter logs based on individual courses, users, activities, actions, and time. Filtered reports cannot be exported, but administrators can save or print the displayed HTML pages.

Tips for administering Moodle sites and courses

I have installed Moodle dozens of times and used it to teach language and technology courses. I also train teachers to use Moodle and assist them during their initial courses. Here are some tips for Moodle administrators and teachers.

As with all new applications, administrators should make preparations before installing Moodle. The following checklist might help:

1. Ensure the server on which you plan to install the software has all of the required and optional components installed. For example:

Verify the required server applications — Web, database, and messaging — are operational.

Install a spell checker (such as Aspell), a zip and unzip program, and an anti-virus utility (e.g. ClamAV) into the main server so Moodle can use them.

Install the mbstring and iconv PHP extensions, and set the maximum upload size in php.ini.

2. Set email policies. What mail router will this server use? Will Moodle users be required to use school email? What character set will outgoing mail use?

3. Select an authentication method. Current options include PAM, LDAP, POP3, IMAP, NNTP, CAS, and FirstClass servers. Email-based authentication is also available. If your school already has an existing authentication method for another system, Moodle may be able to tap into it.

4. Discuss and decide what Moodle options to turn on or off, such as RSS feeds, Google searchability, and podcasts.

5. Establish regulations regarding user authority.

Define system roles. Moodle defines users based on preset roles (system administrator, course creator, teacher, non-editing teacher, student, and guest) Decide the appropriate authority for each user.

Determine who is allowed to view personal profile data — anyone, guests, schoolmates, classmates, etc. Profile information includes basic information like name, email, and chat IDs. Privacy concerns may encourage schools to limit access.

6. Create usage, privacy, and security policies to protect the school and the users from inappropriate site activity.

7. Establish a system for uploading students and users. Moodle allows students to be uploaded via CSV files. The system administrator, working in conjunction with the academic office, can develop scripts to auto upload students and users from an existing school database to Moodle’s database. Instituting a script-based user upload will greatly reduce headaches.

Tips for e-learning course developers

Teachers new to e-learning and course development will find many tips online regarding e-learning course development and use. The following tips focus more on Moodle courses.

1. Plan before you build. After the creation of a default course, you can begin adding content. I recommend having a syllabus that includes objectives, a grade system, and a schedule. These three components of your paper-based syllabus are easily imported into your Moodle course.

2. Set up grade categories at the beginning of the course. Grade categories determine how grades are formulated. For example, I have a course that includes four areas of graded activities — homework (25%), quizzes (20%), tests (25%), and projects (30%). These areas are the categories into which I input the grades for my graded activities. Once the categories are created, any new activity I add to the course can automatically be placed in the proper category. Furthermore, students will be able to see their grades for each activity and see their total grade as the course progresses. If the categories are not set up in advance, students cannot determine their current grade status.

3. Start small and build up. Since Moodle has many functions, it is a good to begin with simple tools. For example, begin by uploading the syllabus, which Moodle calls a resource. Put all of your paper resources on your course schedule in the appropriate week you plan on using them. If you place resources in your course, students won’t need to come to you for a lost paper — they can get it for themselves.

Regarding resources, I recommend using platform-independent file formats, so that any user can open your resource. I recommend Adobe Acrobat files or HTML for text information, since every computer can read them. Avoid Microsoft Word and PowerPoint files. For presentations, convert the PowerPoint to HTML or Flash.

4. Begin by using tools that are easy to set up and can be used quickly. I recommend using the assignments, forums, and journals. Assignments can be files that are uploaded, such as a book report, or offline activities. For example, when I first started using Moodle, I gave quizzes on paper and made an offline assignment into which I placed the quiz results. Students could then see their quiz grades without having to wait until class time.

Forums allow students to post messages and respond to other posted messages. I use forums to extend a classroom discussion. Journals are comments that only the teacher can read. I use these for reports and some written homework.

5. Hide activities you are developing but not ready to present to your students. Each activity has an eye icon that closes when it is hidden.

Comments off

Web 2.0 Pessimism

Here’s a less glossy look at Web 2.0 for people thinking of getting into it.

Comments off

Linux and Ubuntu stuff

I found this very interesting blog (I guess it’s interesting if you’re using a Ubuntu desktop) and I was reading through many of the posts. Here are a few that I’d like to keep track of:

Comments (1)

Postgres Password change

Changing a password in PostgreSQL on Linux:

sudo su
su postgres
ALTER USER postgres WITH PASSWORD 'secret';

Comments (1)

Naming a new venture

I’ve been thinking a lot about names and new ventures.

It’s no longer reality that a “brand name” can be created and built up without major marketing efforts. The new businesses have to tie in their business name to their marketing efforts and to their web URLs (as part of the marketing effort). Short memorable names and domain names are very difficult to find.

One new venture that I’m involved in, and that I had a part in naming, is Passific ( It’s a web site that will let people safely manage all their passwords. It uses modern encryption techniques and a straightforward interface to let people create, save and even transfer passwords (and the information that goes with the password). As a web developer, I should have hundreds or even thousands of passwords but I don’t. I have a couple dozen (and I think this is pretty good) that I use depending on the situation. If I had a tool that would allow me create unique passwords without having to worry about remembering them, I could make every password unique. Anyway, back to the name thing… The name Passific sounds the same as the ocean and when we’re dealing with information on the Internet, the ocean is an appropriate metaphor. The letters, “pass,” refer to password and there’s also the suffix “ific” which I like to believe is the same as the end of “terrific”. All parts of the name of the product and URL make sense in some way to our customers. As well, there is a natural logo idea for it as well. An ocean wave seems natural.

Now, a second venture that I’m involved in is called Team Remind ( We’re still pre-beta here so there’s nothing to see except a temporary message. I’m still thinking about the name. While I like this name, I wonder if it’s doing enough to help our marketing. What does a “remind” look like? Both the words “team” and “remind” are concepts and have no immediately recognizable concrete image. We’re still thinking about that fact.

Comments off

NHL is getting new uniforms

Well, this isn’t huge news, there are a lot of sports fans out there that think this is bad news.

This may be very similar to what all NHL teams will have to change their uniforms to:

Notice the more streamlined shape.

While some people think this is a less masculine jersey, it will be good for the NHL if they change. First, new sales of jerseys. Second, when fans where the jersey, they won’t look as awkward. Third, fewer phantom penalties for hooking or holding because the refs will actually be able to see the contact with the player.

Comments off

Project Management Software

As many of you know, I work for SALEient and we sell a product called Conflux. Conflux comes in a couple different flavours (hosted by us at, your own server that you can put in your office or a dedicated server which is a server in our rack space that you have to your self but it’s on the Internet rather than on your network).

As well, many of you know I also do Internet software development through Sloan Consulting. As part of Sloan Consulting, I’ve worked on a lot of different and interesting projects over the past 6 or so years. Throughout my time developing, I’ve been adverse to using Project Management Software. Mainly, people wanted me to use Microsoft Project and I feel this isn’t a good product unless you have a formal project manager willing to make it work. As a result of my aversion, I’ve now finally chosen to write my own project management software for my consulting work. Conflux has a project management module (called Workflows) but I need something a bit more robust and flexible (and besides, a lot of my consulting clients aren’t using Conflux, yet…)

Here are the major premises of this software.

  1. It should be web-based and easy to use. I like the Basecamp model but I like a bit more information than they allow. As well, if I build it myself, I’ll be able to make changes. I’ve been working with the Python (programming language) Django Framework for the past year or so and I really enjoy it. It’s a great way to build web-based software.
  2. It should do what it is supposed to do and nothing more. I’m not trying to build a million features or move my accounting process onto the web. I just need to track and manage my projects. A project is a lot more than a simple to do list and it’s a lot more than a fancy gantt chart. My software should track what I’m doing and what I’ve done on a project and it should give me some insight into what I can do better. It also should help me communicate about my status to my clients. Lastly, people are people–we shouldn’t call them “resources.”
  3. It should be based on proven practices. Joel On Software has a great breakdown of how to painlessly schedule software development. I’m going to incorporate these ideas. Zel Nadal has some good ideas about why a project management database is a good idea. These ideas are going in as well. Also, this past summer, I worked with the Alberta Department of Agriculture (AAFRD) to scan the types of project management they’re currently using and to work with the Project Management support unit to recommend a more unified solution. It was a tough project to pull off but after many hours of interviews I got through a lot of people. Also, we eventually realized that a government department in Ontario was a leader in this field and we chose to piggy-back on what they are leading the way on. The Ontario Template and the wisdom within are also incorporated here. Lastly, the Getting Real book by 37 Signals has some more wisdom to incorporate.

Well, here goes. I’ll keep you posted. I’m hoping to complete this project in less than 25 hours.

Comments off

Web-developer goodies

Take any page that has some images on it, and paste the following into your URL/Address bar:

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i

Everyone needs a mod-rewrite generator, right?

Comments off