Added logic so that it can work with the new Class based views as well