Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add relations view for data center assets (#3220)
At the moment only related cloud hosts are shown. If the idea works in practice, more relations will be rendered.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/ralph/data_center/templates/data_center/datacenterasset/relations.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{% extends BASE_TEMPLATE %} | ||
{% load i18n %} | ||
|
||
{% block bodyclass %}relations-tab{% endblock%} | ||
|
||
{% block view_content %} | ||
|
||
|
||
<h1>{% trans "Related objects" %}</h1> | ||
{% if related_objects %} | ||
{% for rel_obj_type, objects in related_objects.items %} | ||
{% if rel_obj_type == "cloud_hosts" %} | ||
<h2>{% trans "Cloud hosts" %}</h2> | ||
<table> | ||
<tr> | ||
<th>{% trans "Hostname" %}</th> | ||
<th>{% trans "IP Address" %}</th> | ||
<th>{% trans "Cloud project" %}</th> | ||
<th>{% trans "Cloud provider" %}</th> | ||
</tr> | ||
{% for cloud_host in objects %} | ||
<tr> | ||
<td><a href="{{ cloud_host.get_absolute_url }}">{{ cloud_host.hostname }}</a></td> | ||
<td> | ||
{% for addr in cloud_host.ip_addresses %} | ||
{{ addr }}<br> | ||
{% endfor %} | ||
</td> | ||
<td><a href="{{ cloud_host.cloudproject.get_absolute_url }}">{{ cloud_host.cloudproject.name }}</a></td> | ||
<td><a href="{{ cloud_host.cloudprovider.get_absolute_url }}">{{ cloud_host.cloudprovider.name }}</a></td> | ||
<tr> | ||
{% endfor %} | ||
</table> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% else %} | ||
<p>{% trans "No related objects found." %}</p> | ||
{% endif %} | ||
|
||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ralph.admin.views.extra import RalphDetailView | ||
|
||
|
||
class RelationsView(RalphDetailView): | ||
icon = 'shekel' | ||
label = 'Relations' | ||
name = 'relations' | ||
url_name = 'relations' | ||
template_name = 'data_center/datacenterasset/relations.html' | ||
|
||
def _add_cloud_hosts(self, related_objects): | ||
cloud_hosts = list(self.object.cloudhost_set.all()) | ||
|
||
if cloud_hosts: | ||
related_objects['cloud_hosts'] = cloud_hosts | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
|
||
related_objects = {} | ||
self._add_cloud_hosts(related_objects) | ||
context['related_objects'] = related_objects | ||
|
||
return context |