EmailListField for Django

Posted by sciyoshi on August 8th, 2009

Here's a simple Django form field which validates a list of email addresses:

from email.utils import getaddresses, formataddr

from django import forms
from django.utils.translation import ugettext_lazy as _

class EmailListField(forms.CharField):
    """
    A Django form field which validates a list of email addresses.

    >>> EmailListField().clean('user1@example.com')
    [u'user1@example.com']

    >>> EmailListField().clean('User 1 ...

Read full entry and comments

Prevent Django newcomments spam with Akismet (reloaded)

Posted by sciyoshi on July 17th, 2009

This is a rewrite of my previous post about preventing spam for Django's new comments framework. By using the moderation features that are available, the spam prevention can be done in a much nicer and robust way. Assuming you have an Entry model representing blog posts, you can paste the following below it in your models.py file:

from ...

Read full entry and comments

import antigravity

Posted by sciyoshi on December 30th, 2008

I was looking through Python 3.0's standard library today (/usr/lib/python30/) to see what had changed, and found this interesting tidbit: apparently, "import antigravity" now works, and opens up a web browser pointing to the classic XKCD comic. Doesn't seem like this has been backported to 2.6 yet :-). I guess that's another nice easter ...

Read full entry and comments

Fixing moved subversion repositories when using git-svn

Posted by sciyoshi on December 18th, 2008

This is mostly for my own later reference, and in case anybody finds this of use.

The instructions are based off ones I found here and here, and are simply modified for people who are using the noMetadata option for git-svn. This is useful for one-shot importing from svn to git.

Suppose that the files were moved in revision 100 ...

Read full entry and comments

Rails-like MVC Controllers for Django

Posted by sciyoshi on November 18th, 2008

One thing that sometimes annoys me about Django is how views inside an application are simply top-level functions inside the views.py module. This is fine for simple applications, but if you're trying to make anything more complicated this can become a burden. Suppose that a view needs some logic to decide whether or not the logged-in user can ...

Read full entry and comments