# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


from django.urls import resolve, reverse_lazy
from rest_framework.reverse import reverse
from django.utils.functional import curry
from django.views.defaults import *
from django.http import HttpResponseRedirect
from django.utils.deprecation import MiddlewareMixin
from accounts.utils import user_without_team





class FilterRequestMiddlewareMixin(MiddlewareMixin):
    redirect_url = ''

    allowed_paths = []
    allowed_views = []

    def base_filter(self, request):
        #return False
        return 'admin' not in request.path and \
               'accounts/registration' not in request.path and \
               request.path not in self.allowed_paths and \
               resolve(request.path_info).url_name not in self.allowed_views
               #(request.path not in self.allowed_paths and\
               # resolve(request.path_info).url_name not in self.allowed_views)

    def custom_filter(self, request):
        return True

    def filter(self, request):

# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


# Path: accounts/middleware.py
from django.urls import resolve, reverse_lazy
from rest_framework.reverse import reverse
from django.utils.functional import curry
from django.views.defaults import *
from django.http import HttpResponseRedirect
from django.utils.deprecation import MiddlewareMixin
from accounts.utils import user_without_team






class FilterRequestMiddlewareMixin(MiddlewareMixin):
    redirect_url = ''

    allowed_paths = []
    allowed_views = []

    def base_filter(self, request):
        #return False
        return 'admin' not in request.path and \
               'accounts/registration' not in request.path and \
               request.path not in self.allowed_paths and \
               resolve(request.path_info).url_name not in self.allowed_views
               #(request.path not in self.allowed_paths and\
               # resolve(request.path_info).url_name not in self.allowed_views)

    def custom_filter(self, request):
        return True

    def filter(self, request):

        return self.base_filter(request) and self.custom_filter(request)