feat: add relationship buttons on person list

Resolves #63
This commit is contained in:
James Graham
2021-02-01 15:47:51 +00:00
parent 4bbe4eac3a
commit afae0fd943
2 changed files with 25 additions and 4 deletions

View File

@@ -28,6 +28,19 @@
<td> <td>
<a class="btn btn-sm btn-info" <a class="btn btn-sm btn-info"
href="{% url 'people:person.detail' pk=person.pk %}">Profile</a> href="{% url 'people:person.detail' pk=person.pk %}">Profile</a>
{% if person.pk in existing_relationships %}
<a class="btn btn-sm btn-warning"
style="width: 10rem"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">Update Relationship
</a>
{% else %}
<a class="btn btn-sm btn-success"
style="width: 10rem"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">New Relationship
</a>
{% endif %}
</td> </td>
</tr> </tr>

View File

@@ -30,12 +30,20 @@ class PersonCreateView(LoginRequiredMixin, CreateView):
class PersonListView(LoginRequiredMixin, ListView): class PersonListView(LoginRequiredMixin, ListView):
""" """View displaying a list of :class:`Person` objects - searchable."""
View displaying a list of :class:`Person` objects - searchable.
"""
model = models.Person model = models.Person
template_name = 'people/person/list.html' template_name = 'people/person/list.html'
def get_context_data(self,
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
context = super().get_context_data(**kwargs)
context['existing_relationships'] = set(
self.request.user.person.relationship_targets.values_list(
'pk', flat=True))
return context
class ProfileView(LoginRequiredMixin, DetailView): class ProfileView(LoginRequiredMixin, DetailView):
""" """
@@ -45,7 +53,7 @@ class ProfileView(LoginRequiredMixin, DetailView):
def get_template_names(self) -> typing.List[str]: def get_template_names(self) -> typing.List[str]:
"""Return template depending on level of access.""" """Return template depending on level of access."""
if (self.object.user == self.request.user): # or self.request.user.is_superuser: if (self.object.user == self.request.user) or self.request.user.is_superuser:
return ['people/person/detail_full.html'] return ['people/person/detail_full.html']
return ['people/person/detail_partial.html'] return ['people/person/detail_partial.html']