Backporting a bunch of tastypie issues to get pagination working

This makes the `next` and `previous` links in paged API output function correctly.

The underlying issue is that Tastypie does not really handle kwargs in the URL to an API. Most of this code is modified Tastypie code just backported (from a future not-yet-existent version of Tastypie) into our codebase (BSD-licensed) since they require changes in places that aren't really override hooks.

Tastypie will soon be coming out with 0.9.12 which still will not fix these issues, but I've left comments with links to the issues so we can wipe this code when upstream is fixed.