from django.core.exceptions import ImproperlyConfigured
from django.contrib.auth.views import redirect_to_login

from .views import new_terms


class AcceptNewTermsMiddleware(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        if not hasattr(request, 'user'):
            raise ImproperlyConfigured(
                'AcceptNewTermsMiddleware depends on AuthenticationMiddleware')
        if not request.user.is_authenticated() or request.user.terms:
            return None
        if view_func == new_terms:
            return None
            request.path
        return redirect_to_login(request.path, login_url='account-new_terms')

from django.core.exceptions import ImproperlyConfigured
from django.contrib.auth.views import redirect_to_login

from froide.help_urls import help_view

from .views import new_terms


class AcceptNewTermsMiddleware(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        if not hasattr(request, 'user'):
            raise ImproperlyConfigured(
                'AcceptNewTermsMiddleware depends on AuthenticationMiddleware')
        if not request.user.is_authenticated() or request.user.terms:
            return None
        if view_func == new_terms or view_func == help_view:
            return None
            request.path
        return redirect_to_login(request.path, login_url='account-new_terms')

Allow help pages on new terms middleware