From 4b2abd5d6c39087ff64ff9abf4a2d917e2d3f789 Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 18 Feb 2020 14:38:41 +0000 Subject: [PATCH] feat(people): Add detail views for Person and Relationship --- breccia_mapper/urls.py | 3 + people/models.py | 6 ++ people/templates/people/person/detail.html | 78 +++++++++++++++++++ .../templates/people/relationship/detail.html | 29 +++++++ people/urls.py | 20 +++++ people/views.py | 25 ++++++ 6 files changed, 161 insertions(+) create mode 100644 people/templates/people/person/detail.html create mode 100644 people/templates/people/relationship/detail.html create mode 100644 people/urls.py create mode 100644 people/views.py diff --git a/breccia_mapper/urls.py b/breccia_mapper/urls.py index c1eee42..8dc1fdc 100644 --- a/breccia_mapper/urls.py +++ b/breccia_mapper/urls.py @@ -27,4 +27,7 @@ urlpatterns = [ path('', views.IndexView.as_view(), name='index'), + + path('', + include('people.urls')), ] diff --git a/people/models.py b/people/models.py index fe48434..a14b68c 100644 --- a/people/models.py +++ b/people/models.py @@ -29,6 +29,12 @@ class Person(models.Model): through='Relationship', through_fields=('source', 'target'), symmetrical=False) + + @property + def relationships(self): + return self.relationships_as_source.all().union( + self.relationships_as_target.all() + ) def __str__(self) -> str: return self.name diff --git a/people/templates/people/person/detail.html b/people/templates/people/person/detail.html new file mode 100644 index 0000000..3a31ab4 --- /dev/null +++ b/people/templates/people/person/detail.html @@ -0,0 +1,78 @@ +{% extends 'base.html' %} + +{% block content %} +

+ People / + {{ object }} +

+ +
+ +

Relationships As Source

+ + + + + + + + + + + + {% for relationship in person.relationships_as_source.all %} + + + + + + + {% empty %} + + + + + {% endfor %} + +
Contact Name
{{ relationship.target }} + Profile + + Relationship Detail +
No known relationships
+ +

Relationships As Target

+ + + + + + + + + + + + {% for relationship in person.relationships_as_target.all %} + + + + + + + {% empty %} + + + + + {% endfor %} + +
Contact Name
{{ relationship.source }} + Profile + + Relationship Detail +
No known relationships
+{% endblock %} diff --git a/people/templates/people/relationship/detail.html b/people/templates/people/relationship/detail.html new file mode 100644 index 0000000..d91e956 --- /dev/null +++ b/people/templates/people/relationship/detail.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block content %} +

+ Relationships / + {{ object }} +

+ +
+ +
+
+

Source

+ {{ relationship.source }} + + Profile +
+ +
+

Target

+ {{ relationship.target }} + + Profile +
+
+ +{% endblock %} diff --git a/people/urls.py b/people/urls.py new file mode 100644 index 0000000..82aa305 --- /dev/null +++ b/people/urls.py @@ -0,0 +1,20 @@ +from django.urls import path + +from . import views + + +app_name = 'people' + +urlpatterns = [ + path('profile/', + views.ProfileView.as_view(), + name='person.profile'), + + path('people/', + views.ProfileView.as_view(), + name='person.detail'), + + path('relationships/', + views.RelationshipDetailView.as_view(), + name='relationship.detail'), +] diff --git a/people/views.py b/people/views.py new file mode 100644 index 0000000..a696824 --- /dev/null +++ b/people/views.py @@ -0,0 +1,25 @@ +""" +Views for displaying or manipulating models in the 'people' app. +""" + +from django.views.generic import DetailView + +from . import models + + +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' + context_object_name = 'person' + + +class RelationshipDetailView(DetailView): + """ + View displaying details of a :class:`Relationship`. + """ + model = models.Relationship + template_name = 'people/relationship/detail.html' + context_object_name = 'relationship'