Added code that formerly resided in django-libs