[1.7.x] Corrected many style guide violations that the newest version of flake8 catches

Backport of 778ce245dd466bce1b19f89e52cf9ed8f1b46513 from master
[1.7.x] Appeased flake8 2.1.0.

Backport of 428c0bbe1bcd303560d7e96d7d2721ff3fdc0e3f from master
[1.7.x] Fixed monkeypatching in a staticfiles test.

Backport of a4553e0510 from master