fix: redirect to index if no profile exists

New users were sent to profile page before they had a profile
This commit is contained in:
James Graham
2021-03-10 15:40:10 +00:00
parent 3ad8d4a5c9
commit 87e5e6cbf3

View File

@@ -5,6 +5,9 @@ Views for displaying or manipulating instances of :class:`Person`.
import typing
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.utils import timezone
from django.views.generic import CreateView, DetailView, ListView, UpdateView
@@ -51,6 +54,14 @@ class ProfileView(LoginRequiredMixin, DetailView):
"""
model = models.Person
def get(self, request: HttpRequest, *args: typing.Any, **kwargs: typing.Any) -> HttpResponse:
try:
return super().get(request, *args, **kwargs)
except ObjectDoesNotExist:
# User has no linked Person yet
return redirect('index')
def get_template_names(self) -> typing.List[str]:
"""Return template depending on level of access."""
if (self.object.user == self.request.user) or self.request.user.is_superuser: