Sandbox calls to TemplateHook.applies_to()

Extensions that create a TemplateHook subclass with a new applies_to function
can throw an exception inside Djblets. The part of Djblets that calls that
method has been sandboxed.

Now when a TemplateHook subclass's applies_to() function from an extension
throws an exception, the error is caught and logged.

Testing Done:
Unit test has been written to make sure that applies_to() from a TemplateHook
subclass has been called, and when an exception is thrown it gets logged.

The test fails without the sandboxing, and succeeds with it.

Reviewed at https://reviews.reviewboard.org/r/6545/