Autumn 0.4 Released

Posted by: Jared · Jun 24, 2008

There are a few bugfixes and updates to Autumn in this release. The most prominent bug fixes:

  • Default Meta class is no longer an instance
  • Relations no longer require an instance to be accessed

Thanks to the semi-anonymous Mark who reported these bugs in the old blog post announcement.

Validators

The next big thing in Autumn 0.4 are built-in validators, callable classes that validate the data in your models. The validators included in this version:

Length

The Length validator tests against the string value of the field. Accepts two arguments, min_length (default: 1) and max_length. If max_length is omitted it is not checked against.

An example:

from autumn.model import Model
from autumn import validators
class Person(Model):
    class Meta:
        validations = {'first_name': validators.Length(5),
                       'last_name':  validators.Length(5, 30)}

The validators supplied to the Person model require that the first_name field be at least 5 characters long, while last_name must be at least 5 characters long, but no longer than 30.

Email

The Email validator is a subclass of the Regex validator class that enforces valid email addresses.

Custom Validators

It’s easy to create a validator, which is a callable that accepts the value of the field. The validator’s return value is evaluated as a boolean so each of these validators is valid:

def foo(value):
    return value == 'foo'

def bar(value):
    return int(value)

class FooBar(object):
    def __call__(self, value):
        return value in ('foo', 'bar', 'foobar')

The Regex Validator Class

The validators included with Autumn are subclasses of the Validator class (which is a blank class for now). Probably the most useful validator class included is Regex, which is a base class that allows the creation of a validator based on a regular expression. Creation is simple as you simply setup a compiled regular expression object:

import re
from autumn.validators import Regex

class Foo(Regex):
    regex = re.compile(r'^myregularexpression$')

Validator Chains

Previously, validation only worked as a single callable. Now you may also pass a tuple to create a Validator Chain.

class Person(Model):
    class Meta:
        validations = {'first_name': (foo, bar, FooBar())}

The Future

Looking forward I will be working on this set of items:

  • Query.exclude (the opposite of Query.filter)
  • Cleanup of various parts inside Autumn, especially Query
  • Postgres Support
  • ManyToMany relation
  • Allow non-primary-keyed tables
  • Better documentation

I’m looking for feedback for additional features, bugfixes, etc. Please let me know your thoughts in the mailing list.