Moved off macros to a jinja filter plugin

This filter allows us to pass the "heavy lifting" to python, and
remove the logic from the view.