mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
feat(people): Add detail views for Person and Relationship
This commit is contained in:
@@ -27,4 +27,7 @@ urlpatterns = [
|
||||
path('',
|
||||
views.IndexView.as_view(),
|
||||
name='index'),
|
||||
|
||||
path('',
|
||||
include('people.urls')),
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
78
people/templates/people/person/detail.html
Normal file
78
people/templates/people/person/detail.html
Normal file
@@ -0,0 +1,78 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>
|
||||
<a href="#">People</a> /
|
||||
{{ object }}
|
||||
</h1>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2>Relationships As Source</h2>
|
||||
|
||||
<table class="table table-borderless">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Contact Name</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for relationship in person.relationships_as_source.all %}
|
||||
<tr>
|
||||
<td>{{ relationship.target }}</td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:person.detail' pk=relationship.target.pk %}">Profile</a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:relationship.detail' pk=relationship.pk %}">Relationship Detail</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="2">No known relationships</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>Relationships As Target</h2>
|
||||
|
||||
<table class="table table-borderless">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Contact Name</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for relationship in person.relationships_as_target.all %}
|
||||
<tr>
|
||||
<td>{{ relationship.source }}</td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:person.detail' pk=relationship.source.pk %}">Profile</a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:relationship.detail' pk=relationship.pk %}">Relationship Detail</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="2">No known relationships</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
29
people/templates/people/relationship/detail.html
Normal file
29
people/templates/people/relationship/detail.html
Normal file
@@ -0,0 +1,29 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>
|
||||
<a href="#">Relationships</a> /
|
||||
{{ object }}
|
||||
</h1>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="row align-content-center">
|
||||
<div class="col-md-6">
|
||||
<h2>Source</h2>
|
||||
{{ relationship.source }}
|
||||
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:person.detail' pk=relationship.source.pk %}">Profile</a>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h2>Target</h2>
|
||||
{{ relationship.target }}
|
||||
|
||||
<a class="btn btn-sm btn-info"
|
||||
href="{% url 'people:person.detail' pk=relationship.target.pk %}">Profile</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
20
people/urls.py
Normal file
20
people/urls.py
Normal file
@@ -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/<int:pk>',
|
||||
views.ProfileView.as_view(),
|
||||
name='person.detail'),
|
||||
|
||||
path('relationships/<int:pk>',
|
||||
views.RelationshipDetailView.as_view(),
|
||||
name='relationship.detail'),
|
||||
]
|
||||
25
people/views.py
Normal file
25
people/views.py
Normal file
@@ -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'
|
||||
Reference in New Issue
Block a user