Move more logic into the views

Also includes some tests

Story: LMS-1127