Improve the performance of directory listing.

Performance is improved by no loger executing a query for each file and
folder. Now a single query is executed for gathering all of a user's
permitted ids.

The folder_qs and file_qs QuerySets filter on the user's permitted ids
=> just 3 queries required (instead of one for each file/folder)
Remove useless nested functions and unused functions
Removed another redundant function and made the code more readable
Added unit tests for the directory listing permission filtering
Made assertions and test names more readable
Fix the encoding directive (which I accidentally messed up in my prev commit)
Added a SettingsOverride context manager for easily switching different filer settings during tests
Test when permissions are granted on the parent folder
Merge pull request #330 from pbs/perms-performance

Improve the performance of directory listing.