from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import View


class HomeView(View):

    def get(self, *args, **kwargs):
        if self.request.user.is_authenticated:
            return redirect(reverse('project_list'))
        else:
            return redirect(reverse('beta_token'))

from django.shortcuts import redirect
from django.urls import reverse

from accounts.views import BetaTokenView


class HomeView(BetaTokenView):
    """
    Home page view.

    Care needs to be taken that this view returns a 200 response (not a redirect)
    for unauthenticated users. This is because GCP load balancers ping the / path
    as a health check and will fail if anything other than a 200 is returned.
    """

    def get(self, *args, **kwargs):
        if self.request.user.is_authenticated:
            return redirect(reverse('project_list'))
        else:
            return super().get(*args, **kwargs)

Fix home view so it returns 200 for unauthenticated health check
Fix home view so it returns 200 for unauthenticated health check

  from django.shortcuts import redirect
  from django.urls import reverse
- from django.views.generic import View
+ 
+ from accounts.views import BetaTokenView
  
  
- class HomeView(View):
+ class HomeView(BetaTokenView):
+     """
+     Home page view.
+ 
+     Care needs to be taken that this view returns a 200 response (not a redirect)
+     for unauthenticated users. This is because GCP load balancers ping the / path
+     as a health check and will fail if anything other than a 200 is returned.
+     """
  
      def get(self, *args, **kwargs):
          if self.request.user.is_authenticated:
              return redirect(reverse('project_list'))
          else:
-             return redirect(reverse('beta_token'))
+             return super().get(*args, **kwargs)
  
Fix home view so it returns 200 for unauthenticated health check
## Code Before:
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import View


class HomeView(View):

    def get(self, *args, **kwargs):
        if self.request.user.is_authenticated:
            return redirect(reverse('project_list'))
        else:
            return redirect(reverse('beta_token'))

## Instruction:
Fix home view so it returns 200 for unauthenticated health check
## Code After:
from django.shortcuts import redirect
from django.urls import reverse

from accounts.views import BetaTokenView


class HomeView(BetaTokenView):
    """
    Home page view.

    Care needs to be taken that this view returns a 200 response (not a redirect)
    for unauthenticated users. This is because GCP load balancers ping the / path
    as a health check and will fail if anything other than a 200 is returned.
    """

    def get(self, *args, **kwargs):
        if self.request.user.is_authenticated:
            return redirect(reverse('project_list'))
        else:
            return super().get(*args, **kwargs)
