Integrating [reCAPTCHA](http://recaptcha.net/) with Django.
**Warning**: although *remoteip* is used as optional parameter in this snippet, it is likely to become mandatory in the future. Please see [the comment by Jim Garrison](http://www.marcofucci.com/tumblelog/26/jul/2009/integrating-recaptcha-with-django/#comment-262) for more detail.
Generic version of [this snippet](http://www.djangosnippets.org/snippets/433/).
1. Register on [reCAPTCHA](http://recaptcha.net/) to get your public/private key pair
2. Add your keys in settings.py
3. Add [recaptcha-client](http://pypi.python.org/pypi/recaptcha-client) to your project
4. Put ReCaptchaField and ReCaptcha widget somewhere (I've used a generic app `marcofucci_utils`)
5. Configure your form
More information on my website [marcofucci.com](http://www.marcofucci.com/tumblelog/26/jul/2009/integrating-recaptcha-with-django/).
I wanted to be able to limit which types of requests a view will accept. For instance, if a view only wants to deal with GET requests.
@methods(GET)
def index(request):
# do stuff
Now, calling this view with a non-GET request will cause a 403.
You can easily change this to a 404, by using a different return function: which you may wish to do with openly available sites, as a 403 indicates there is a resource present.
Based on [this snippet](http://www.djangosnippets.org/snippets/876/). More clean, with links to the related admin forms.
Nice example on customization of contributed django admin apps.
It adds the following to the user list interface: fields for is_superuser and is_staff, last login time; by default, short names of groups user is in (mousehover to see full names) It adds the following to the to group list interface: list of users in your groups.
To enable, just put it somewhere and import it from your main urls.py: import utils/admin_auth.py
This is a custom widget for displaying a view only date field in the django admin.
I used it to get around this ticket:
[http://code.djangoproject.com/ticket/342](http://code.djangoproject.com/ticket/342)
Provides a basic implementation of Yahoo's [MediaRSS](http://video.search.yahoo.com/mrss) format for [Photologue](http://code.google.com/p/django-photologue/) galleries
Simplest usage:
I have feedgenerator.py in a utils directory. Import photofeeds and hook up the feed url in your URLConf:
from utils.feedgenerator import photofeeds
urlpatterns += patterns('',
url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': photofeeds}),)
Without customization, this will generate a feed for the gallery archive at
`/feeds/gallery/`
It will contain a single photo per gallery, as returned by Gallery.sample()
Additionally, each gallery has a dynamic feed available at the url via Gallery.title_slug:
`/feeds/gallery/gallery-title-slug/`
This feed will contain an Item for each Photo in the Gallery
All that is left is to add an autodiscovery feed to your pages in <head>. An RSS agent like CoolIris can then parse your gallery and provide a slick view of your photos.
e.g Add something like this to gallery_detail.html:
`<link rel="alternate" href="/feeds/gallery/{{ object.title_slug }}/"
type="application/rss+xml" title="Photologue Gallery - {{ object.title }}" id="gallery_feed" />
`
We currently use two-level tuples to specify choices of a field in models or forms.
But, because it has only (value, verbose name) pair, the readability is bad whenever we indicate a specific choice value in our Python codes.
So I made a small class that does "magic" for this: A Named Enumeration.
Instead of `myobj.status == 0`, use `myobj.status == STATUS.UNREVIEWED`, for example.
This is a ModelAdmin base class you can use to make foreign key references to User a bit nicer in admin. In addition to showing a user's username, it also shows their full name too (if they have one and it differs from the username).
**2009-08-14**: updated to handle many to many fields and easily configure whether to always show the username (if it differs from full name)
TestableTemplate behaves just like django.template.Template, but you can give it a list of template.Libraries to load before parsing the template. This is equivalent to adding a bunch of {% load %} tags to the beginning of your template string, but you can use custom tag libraries which do not belong to Django applications' templatetags packages.
This is occasionally useful in testing.