refactoring in views.py