from django.http import Http404
from django.shortcuts import get_object_or_404

from .models import Organization


class OrganizationMiddleware(object):

    def process_request(self, request):
        subdomain = request.subdomain
        user = request.user

        if subdomain is None:
            request.organization = None
            return

        organization = get_object_or_404(
            Organization, slug__iexact=subdomain.lower()
        )

        if user.is_authenticated() and organization != user.organization:
            raise Http404

        request.organization = organization

from django.http import Http404
from django.shortcuts import get_object_or_404

from .models import Organization


class OrganizationMiddleware(object):

    def process_request(self, request):
        subdomain = request.subdomain
        user = request.user
        request.organization = None

        if subdomain is None:
            request.organization = None
            return

        organization = get_object_or_404(
            Organization, slug__iexact=subdomain.lower()
        )

        if user.is_authenticated() and organization != user.organization:
            raise Http404

        request.organization = organization

Set requestion organization to none
Set requestion organization to none

  from django.http import Http404
  from django.shortcuts import get_object_or_404
  
  from .models import Organization
  
  
  class OrganizationMiddleware(object):
  
      def process_request(self, request):
          subdomain = request.subdomain
          user = request.user
+         request.organization = None
  
          if subdomain is None:
              request.organization = None
              return
  
          organization = get_object_or_404(
              Organization, slug__iexact=subdomain.lower()
          )
  
          if user.is_authenticated() and organization != user.organization:
              raise Http404
  
          request.organization = organization
  
Set requestion organization to none
## Code Before:
from django.http import Http404
from django.shortcuts import get_object_or_404

from .models import Organization


class OrganizationMiddleware(object):

    def process_request(self, request):
        subdomain = request.subdomain
        user = request.user

        if subdomain is None:
            request.organization = None
            return

        organization = get_object_or_404(
            Organization, slug__iexact=subdomain.lower()
        )

        if user.is_authenticated() and organization != user.organization:
            raise Http404

        request.organization = organization

## Instruction:
Set requestion organization to none
## Code After:
from django.http import Http404
from django.shortcuts import get_object_or_404

from .models import Organization


class OrganizationMiddleware(object):

    def process_request(self, request):
        subdomain = request.subdomain
        user = request.user
        request.organization = None

        if subdomain is None:
            request.organization = None
            return

        organization = get_object_or_404(
            Organization, slug__iexact=subdomain.lower()
        )

        if user.is_authenticated() and organization != user.organization:
            raise Http404

        request.organization = organization
