mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
User profile nav directs to create new Person for user if there is not one currently associated resolves issue #4
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""
|
|
Views for displaying or manipulating models in the 'people' app.
|
|
"""
|
|
|
|
from django.views.generic import CreateView, DetailView, ListView
|
|
|
|
from . import forms, models
|
|
|
|
|
|
class PersonCreateView(CreateView):
|
|
"""
|
|
View to create a new instance of :class:`Person`.
|
|
|
|
If 'user' is passed as a URL parameter - link the new person to the current user.
|
|
"""
|
|
model = models.Person
|
|
template_name = 'people/person/create.html'
|
|
form_class = forms.PersonForm
|
|
|
|
def form_valid(self, form):
|
|
if 'user' in self.request.GET:
|
|
form.instance.user = self.request.user
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PersonListView(ListView):
|
|
"""
|
|
View displaying a list of :class:`Person` objects - searchable.
|
|
"""
|
|
model = models.Person
|
|
template_name = 'people/person/list.html'
|
|
|
|
|
|
class ProfileView(DetailView):
|
|
"""
|
|
View displaying the profile of a :class:`Person` - who may be a user.
|
|
"""
|
|
model = models.Person
|
|
template_name = 'people/person/detail.html'
|
|
|
|
def get_object(self, queryset=None) -> models.Person:
|
|
"""
|
|
Get the :class:`Person` object to be represented by this page.
|
|
|
|
If not determined from url get current user.
|
|
"""
|
|
try:
|
|
return super().get_object(queryset)
|
|
|
|
except AttributeError:
|
|
return self.request.user.person
|
|
|
|
|
|
class RelationshipDetailView(DetailView):
|
|
"""
|
|
View displaying details of a :class:`Relationship`.
|
|
"""
|
|
model = models.Relationship
|
|
template_name = 'people/relationship/detail.html'
|