I find it hard to imagine where it is better to invoke operations from the template rather than from Python code; and I think as a general rule, we should advocate against invoking non-trivial operations (especially database queries) from the templates. This seems like a  direct violation of MVC principles.