Move logic out from views.py.