mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user