Login

Snippets by davepeck

Snippet List

ImageField for Google App Engine

This is a replacement for Django's built-in ImageField. It uses the Google AppEngine image APIs in order to validate. Notes: 1. Validation of the field counts against your App Engine transformations quota. 2. This code assumes you're only using the in-memory file upload handler. None of the other stock handlers work well on App Engine; you should probably disable them.

  • fields
  • imagefield
  • google
  • appengine
  • gae
Read More

UsernameField (for clean error messages)

This is a username field that matches (and slightly tightens) the constraints on usernames in Django's `User` model. Most people use RegexField, which is totally fine -- but it can't provide the fine-grained and user friendly messages that come from this field.

  • fields
  • forms
  • user
  • auth
  • form
  • field
  • username
  • users
  • authorization
Read More

SQL Log To Console Middleware

When running the Django development server, this middleware causes all executed SQL queries to get printed out to the console. This is based on [Snippet 161](http://www.djangosnippets.org/snippets/161/). The big difference is that 161 logs by adding stuff to your response text, which isn't very convenient IMO.

  • sql
  • middleware
  • log
  • debug
  • logging
  • console
Read More

@url decorator improvements

A slight modification (and, I think, improvement) of the URL decorator found in [snippet 395](http://www.djangosnippets.org/snippets/395/). What's different between this snippet and 395? 1. We use `django.conf.urls.defaults.url()` when adding patterns 2. We support arbitrary arguments to the `url()` method (like `name="foo"`) 3. We _do not_ support multiple url patterns (this didn't seem useful to me, but if it is I can add it back.)

  • urls
  • url
  • decorator
  • decorators
  • urlpatterns
Read More

davepeck has posted 4 snippets.