Login

Snippets by gregb

Snippet List

Improved User Admin

Helper function which adds some niceties to the auth/user admin views. Needs django 1.2 to work. ### Usage Define a UserProfile class and set `AUTH_PROFILE_MODULE` as per the [django docs](http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users) In your admin.py file (or anywhere else) add the following: from models import UserProfile from [path to snippet] import upgrade_user_admin upgrade_user_admin(UserProfile)

  • admin
  • user
  • userprofile
Read More

Month / Year dropdown widget

This is an adaption of [django.forms.extras.widgets.SelectDateWidget](http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py#L16) which has no day dropdown - it still produces a date but with the day set to 1. Example use class myForm(forms.Form): # ... date = forms.DateField( required=False, widget=MonthYearWidget(years=xrange(2004,2010)) )

  • date
  • year
  • credit-card
  • month
Read More

Append paramaters to a GET querystring (template tag)

This tag is designed to facilitate pagination in the case where both the page number and other parameters (eg. search criteria) are passed via GET. It takes one argument - a dictionary of GET variables to be added to the current url Example usage: {% for page_num in results.paginator.page_range %} <a href="{% append_to_get p=page_num %}">{{ page_num }}</a> {% endfor %} Note that the passed arguments are evaluated within the template context.

  • get
  • pagination
  • request
Read More

Captcha without Freetype or the Python Imaging Library (PIL)

If, like me, you've had trouble installing the [Python Imaging Library](http://www.pythonware.com/products/pil/) or [FreeType](http://freetype.sourceforge.org), you may have also had trouble getting a captcha to work. Here's my quick and dirty workaround — be warned, this is _very_ low level security, and shouldn't be used on high-profile sites. Originally published at <http://gregbrown.co.nz/code/django-captcha-without-freetype-or-pil/> Credit to the author of [django-simple-captcha](http://code.google.com/p/django-simple-captcha/), from whom I borrowed most of this code. ### Usage from django import forms from ABOVE-FILE import CaptchaField class CaptchaTestForm(forms.Form): myfield = forms.TextField() security_check = CaptchaField()

  • captcha
Read More

gregb has posted 4 snippets.