I would have considered a separate function to do this task, seeing as it's being done 4 times exactly the same in the views. Chances are you might want to change them all if you start changing this anyway.