Skip to content

Commit

Permalink
#11517: Standardize display of contact assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Feb 20, 2023
1 parent 7d64167 commit 80fab0c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

* [#11517](https://github.com/netbox-community/netbox/issues/11517) - Standardize the inclusion of related objects across the entire UI
* [#11584](https://github.com/netbox-community/netbox/issues/11584) - Add a list view for contact assignments
* [#11254](https://github.com/netbox-community/netbox/issues/11254) - Introduce the `X-Request-ID` HTTP header to annotate the unique ID of each request for change logging
* [#11440](https://github.com/netbox-community/netbox/issues/11440) - Add an `enabled` field for device type interfaces
Expand Down
16 changes: 6 additions & 10 deletions netbox/templates/tenancy/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,26 @@ <h5 class="card-header">Contact</h5>
<th scope="row">Description</th>
<td>{{ object.description|placeholder }}</td>
</tr>
<tr>
<th scope="row">Assignments</th>
<td>{{ assignment_count }}</td>
</tr>
</table>
</div>
</div>
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_left_page object %}
</div>
<div class="col col-md-5">
{% include 'inc/panels/comments.html' %}
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
</div>
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">Assignments</h5>
<div class="card-body table-responsive">
{% render_table assignments_table 'inc/table.html' %}
{% include 'inc/paginator.html' with paginator=assignments_table.paginator page=assignments_table.page %}
</div>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'tenancy:contactassignment_list' %}?contact_id={{ object.pk }}"
hx-trigger="load"
></div>
</div>
{% plugin_full_width_page object %}
</div>
Expand Down
14 changes: 1 addition & 13 deletions netbox/templates/tenancy/contactrole.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,20 @@ <h5 class="card-header">Contact Role</h5>
<th scope="row">Description</th>
<td>{{ object.description|placeholder }}</td>
</tr>
<tr>
<th scope="row">Assignments</th>
<td>
{{ assignment_count }}
</td>
</tr>
</table>
</div>
</div>
{% include 'inc/panels/tags.html' %}
{% plugin_left_page object %}
</div>
<div class="col col-md-6">
{% include 'inc/panels/related_objects.html' %}
{% include 'inc/panels/custom_fields.html' %}
{% plugin_right_page object %}
</div>
</div>
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">Assigned Contacts</h5>
<div class="card-body table-responsive">
{% render_table contacts_table 'inc/table.html' %}
{% include 'inc/paginator.html' with paginator=contacts_table.paginator page=contacts_table.page %}
</div>
</div>
{% plugin_full_width_page object %}
</div>
</div>
Expand Down
23 changes: 3 additions & 20 deletions netbox/tenancy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,12 @@ class ContactRoleView(generic.ObjectView):
queryset = ContactRole.objects.all()

def get_extra_context(self, request, instance):
contact_assignments = ContactAssignment.objects.restrict(request.user, 'view').filter(
role=instance
related_models = (
(ContactAssignment.objects.restrict(request.user, 'view').filter(role=instance), 'role_id'),
)
contacts_table = tables.ContactAssignmentTable(contact_assignments, user=request.user)
contacts_table.columns.hide('role')
contacts_table.configure(request)

return {
'contacts_table': contacts_table,
'assignment_count': ContactAssignment.objects.filter(role=instance).count(),
'related_models': related_models,
}


Expand Down Expand Up @@ -314,19 +310,6 @@ class ContactListView(generic.ObjectListView):
class ContactView(generic.ObjectView):
queryset = Contact.objects.all()

def get_extra_context(self, request, instance):
contact_assignments = ContactAssignment.objects.restrict(request.user, 'view').filter(
contact=instance
)
assignments_table = tables.ContactAssignmentTable(contact_assignments, user=request.user)
assignments_table.columns.hide('contact')
assignments_table.configure(request)

return {
'assignments_table': assignments_table,
'assignment_count': ContactAssignment.objects.filter(contact=instance).count(),
}


@register_model_view(Contact, 'edit')
class ContactEditView(generic.ObjectEditView):
Expand Down

0 comments on commit 80fab0c

Please sign in to comment.