From 4c0be637234e93088e682ef6dea79cb1bae6f999 Mon Sep 17 00:00:00 2001 From: Roman Prykhodchenko Date: Wed, 24 Jan 2018 15:07:05 +0100 Subject: [PATCH] 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. --- src/ralph/data_center/admin.py | 6 +++ .../datacenterasset/relations.html | 42 +++++++++++++++++++ src/ralph/data_center/views.py | 24 +++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/ralph/data_center/templates/data_center/datacenterasset/relations.html create mode 100644 src/ralph/data_center/views.py diff --git a/src/ralph/data_center/admin.py b/src/ralph/data_center/admin.py index ba75a9eadf..a25c67342d 100644 --- a/src/ralph/data_center/admin.py +++ b/src/ralph/data_center/admin.py @@ -56,6 +56,7 @@ Database, VIP ) +from ralph.data_center.views import RelationsView from ralph.data_importer import resources from ralph.deployment.mixins import ActiveDeploymentMessageMixin from ralph.lib.custom_fields.admin import CustomFieldValueAdminMixin @@ -330,6 +331,10 @@ class DataCenterAssetSCMInfo(SCMCheckInfo): url_name = 'datacenterasset_scm_info' +class DataCenterAssetRelationsView(RelationsView): + url = 'datacenterasset_relations' + + @register(DataCenterAsset) class DataCenterAssetAdmin( SCMStatusCheckInChangeListMixin, @@ -352,6 +357,7 @@ class DataCenterAssetAdmin( DataCenterAssetNetworkView, DataCenterAssetSecurityInfo, DataCenterAssetSCMInfo, + DataCenterAssetRelationsView, DataCenterAssetLicence, DataCenterAssetSupport, DataCenterAssetOperation, diff --git a/src/ralph/data_center/templates/data_center/datacenterasset/relations.html b/src/ralph/data_center/templates/data_center/datacenterasset/relations.html new file mode 100644 index 0000000000..32ada51e22 --- /dev/null +++ b/src/ralph/data_center/templates/data_center/datacenterasset/relations.html @@ -0,0 +1,42 @@ +{% extends BASE_TEMPLATE %} +{% load i18n %} + +{% block bodyclass %}relations-tab{% endblock%} + +{% block view_content %} + + +

{% trans "Related objects" %}

+ {% if related_objects %} + {% for rel_obj_type, objects in related_objects.items %} + {% if rel_obj_type == "cloud_hosts" %} +

{% trans "Cloud hosts" %}

+ + + + + + + + {% for cloud_host in objects %} + + + + + + + {% endfor %} +
{% trans "Hostname" %}{% trans "IP Address" %}{% trans "Cloud project" %}{% trans "Cloud provider" %}
{{ cloud_host.hostname }} + {% for addr in cloud_host.ip_addresses %} + {{ addr }}
+ {% endfor %} +
{{ cloud_host.cloudproject.name }}{{ cloud_host.cloudprovider.name }}
+ {% endif %} + {% endfor %} + + {% else %} +

{% trans "No related objects found." %}

+ {% endif %} + + +{% endblock %} diff --git a/src/ralph/data_center/views.py b/src/ralph/data_center/views.py new file mode 100644 index 0000000000..14efa7c373 --- /dev/null +++ b/src/ralph/data_center/views.py @@ -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