Extract code from django-viewflow