Skip to content

Commit

Permalink
Merge pull request #1109 from quamilek/change-owners
Browse files Browse the repository at this point in the history
Rewrite owners table in device info view, add service owners
  • Loading branch information
xliiv committed Sep 26, 2014
2 parents 10da714 + f009421 commit 9a9c037
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 49 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
'ralph = ralph.__main__:main',
],
'ralph_extra_data': [
'ralph_obj_owner_table = ralph.cmdb.extra:ralph_obj_owner_table',
'ralph_device_owner_table = ralph.cmdb.extra:ralph_device_owner_table',
'ralph_obj_owner_column_factory = ralph.cmdb.extra:ralph_obj_owner_column_factory',
'ralph_obj_all_ownerships = ralph.cmdb.extra:ralph_obj_all_ownerships',
],
'django.pluggable_app': [
'cmdb = ralph.cmdb.app:Cmdb',
Expand Down
37 changes: 27 additions & 10 deletions src/ralph/cmdb/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,33 @@
from ralph.cmdb.models_ci import CI, CIOwner, CIOwnership, CIOwnershipType


def ralph_obj_owner_table(obj):
"""Renders a table containing owners of a given ralph object."""
ci = CI.get_by_content_object(obj)
ownerships = CIOwnership.objects.filter(ci=ci)
if not ci:
return ''
return render_to_string(
'cmdb/ralph_obj_owner_table.html',
{'ownerships': ownerships},
)
def ralph_device_owner_table(device):
"""Renders a table containing owners of a given ralph device object."""
context = {
'venture': device.venture,
'venture_business': [],
'venture_technical': [],
'service_business': [],
'service_technical': [],
}
if device.venture:
venture_ci = CI.get_by_content_object(device.venture)
venture_ownerships = CIOwnership.objects.filter(ci=venture_ci)
context['venture_business'] = venture_ownerships.filter(
type=CIOwnershipType.business,
)
context['venture_technical'] = venture_ownerships.filter(
type=CIOwnershipType.technical,
)
if device.service:
service_ownerships = CIOwnership.objects.filter(ci=device.service)
context['service_business'] = service_ownerships.filter(
type=CIOwnershipType.business,
)
context['service_technical'] = service_ownerships.filter(
type=CIOwnershipType.technical,
)
return render_to_string('cmdb/ralph_device_owner_table.html', context)


def ralph_obj_owner_column_factory(type_):
Expand Down
38 changes: 38 additions & 0 deletions src/ralph/cmdb/templates/cmdb/ralph_device_owner_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% load cmdb i18n icons %}

<table class="table table-striped table-bordered details-costs-owners">
<tbody>
<tr>
<th>{% trans "Department" %}</th>
<td colspan="2">
{% if venture %}{{ venture|venture_icon }} {{ venture.department }}<br>{% else %}-{%endif %}
</td>
</tr>
<tr>
<th rowspan="2">{% trans "Venture" %}</th>
<td>{% trans "business owners" %}</td>
<td>
{% for o in service_business %}{{ o|owner_icon }} {{ o.owner }}<br>{% empty %}-{% endfor %}
</td>
</tr>
<tr>
<td>{% trans "technical owners" %}</td>
<td>
{% for o in service_technical %}{{ o|owner_icon }} {{ o.owner }}<br>{% empty %}-{% endfor %}
</td>
</tr>
<tr>
<th rowspan="2">{% trans "Service" %}</th>
<td>{% trans "business owners" %}</td>
<td>
{% for o in venture_business %}{{ o|owner_icon }} {{ o.owner }}<br>{% empty %}-{% endfor %}
</td>
</tr>
<tr>
<td>{% trans "technical owners" %}</td>
<td>
{% for o in venture_technical %}{{ o|owner_icon }} {{ o.owner }}<br>{% empty %}-{% endfor %}
</td>
</tr>
</tbody>
</table>
16 changes: 0 additions & 16 deletions src/ralph/cmdb/templates/cmdb/ralph_obj_owner_table.html

This file was deleted.

24 changes: 2 additions & 22 deletions src/ralph/ui/templates/ui/device_info.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends "ui/base-devices.html" %}
{% load url from future %}
{% load icons %}
{% load cmdb %}
{% load di i18n icons cmdb query %}

{% block content %}
{% if deployment_status %}
Expand Down Expand Up @@ -44,26 +43,7 @@
{% include 'ui/device-properties.html' with form=property_form %}
{% endif %}

<table class="table table-striped table-bordered details-info-owners">
<thead><tr>
<th width="16"></th>
<th>Owner</th>
</tr></thead>
<tbody>
{% for o in device.venture.all_ownerships %}
<tr>
<td>{{ o|owner_icon }}</td>
<td>{{ o.owner }}</td>
</tr>
{% endfor %}
{% if device.venture.department %}
<tr>
<td>{{ device.venture|venture_icon }}</td>
<td>{{ device.venture.department }}</td>
</tr>
{% endif %}
</tbody>
</table>
{% extra_inclusion "ralph_device_owner_table" device %}

<table class="table table-striped table-bordered details-info-virtual">
<tbody>
Expand Down

0 comments on commit 9a9c037

Please sign in to comment.