mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
feat(people): Allow people to describe relationships
Creating a relationship requires answering each of the relationship questions resolve #2 partial #5
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
Views for displaying or manipulating models in the 'people' app.
|
||||
"""
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.generic import CreateView, DetailView, ListView
|
||||
|
||||
from . import forms, models
|
||||
@@ -58,3 +59,48 @@ class RelationshipDetailView(DetailView):
|
||||
"""
|
||||
model = models.Relationship
|
||||
template_name = 'people/relationship/detail.html'
|
||||
|
||||
|
||||
class RelationshipCreateView(CreateView):
|
||||
"""
|
||||
View for creating a :class:`Relationship`.
|
||||
|
||||
Displays / processes a form containing the :class:`RelationshipQuestion`s.
|
||||
"""
|
||||
model = models.Relationship
|
||||
template_name = 'people/relationship/create.html'
|
||||
form_class = forms.RelationshipForm
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.person = models.Person.objects.get(pk=self.kwargs.get('person_pk'))
|
||||
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
def get_initial(self):
|
||||
initial = super().get_initial()
|
||||
|
||||
initial['source'] = self.request.user.person
|
||||
initial['target'] = self.person
|
||||
|
||||
return initial
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['person'] = self.person
|
||||
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
Form is valid - create :class:`Relationship` and save answers to questions.
|
||||
"""
|
||||
self.object = form.save()
|
||||
|
||||
return HttpResponseRedirect(self.object.get_absolute_url())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user