Skip to content

Commit

Permalink
Added SWID tag view and template
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Furrer authored and dbrgn committed May 3, 2014
1 parent 009d6eb commit 7419011
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 11 deletions.
11 changes: 11 additions & 0 deletions apps/swid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class EntityRole(models.Model):
entity = models.ForeignKey('Entity')
role = models.PositiveSmallIntegerField(choices=ROLE_CHOICES)

def get_software_id(self):
"""
Returns the software_id of the tag.
The software_id consists of the regid and the unique_id.
Returns:
software_id (str)
"""
return '%s_%s' % (self.entity.regid, self.tag.unique_id)

class Meta:
db_table = TABLE_PREFIX + 'entityroles'

Expand Down
139 changes: 139 additions & 0 deletions apps/swid/templates/swid/tags_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{% extends 'swid/tags_list.html' %}

{% load i18n %}

{% block title %}{{ object.unique_id }}{% endblock %}

{% block hero %}
<h1>{{ object.unique_id }}</h1>
{% endblock %}

{% block detail %}
<div class="container-fluid">
<div class="row-fluid">
{% if object %}
<h4>Tag Info</h4>
<div class="row-fluid">
<div class="span8">
<table class="table" border="0">
<tbody>
<tr>
<td><strong>{% trans 'Name' %}</strong></td>
<td>{{ object.package_name }}</td>
</tr>
<tr>
<td><strong>{% trans 'Version' %}</strong></td>
<td>{{ object.version }}</td>
</tr>
<tr>
<td><strong>{% trans 'Unique ID' %}</strong></td>
<td>{{ object.unique_id }}</td>
</tr>
<tr>
<td><strong>{% trans 'Entities' %}</strong></td>
<td>
{% for er in entityroles %}
{{ er.entity.name }} ({{ er.get_role_display }})
{% if not forloop.last %}
<br/>
{% endif %}
{% endfor %}
</td>
</tr>
<tr>
<td><strong>{% trans 'Regids' %}</strong></td>
<td>
{% for er in entityroles %}
{{ er.entity.regid }}
{% if not forloop.last %}
<br/>
{% endif %}
{% endfor %}
</td>
</tr>
<tr>
<td><strong>{% trans 'Software IDs' %}</strong></td>
<td>
{% for er in entityroles %}
{{ er.get_software_id }}
{% if not forloop.last %}
<br/>
{% endif %}
{% endfor %}
</td>
</tr>
</tbody>
</table>
<a class="btn btn-primary" href="#swidTagXmlModal" data-toggle="modal">
<i class="icon-file icon-white"></i>{% trans 'View raw SWID tag' %}
</a>
</div>
</div>
<hr>

<h4>Devices</h4>
<div class="row-fluid">
{% if object.sessions.count %}
<table class="table table-hover table-striped">
<thead>
<tr>
<td>{% trans 'Description' %}</td>
</tr>
</thead>
<tbody>
{% for session in object.sessions.all %}
<tr>
<td><a href="{% url 'device' session.device.pk %}">{{ session.device }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No files found</p>
{% endif %}
</div>
<hr>

<h4>Files</h4>
<div class="row-fluid">
{% if object.files.count %}
<table class="table table-hover table-striped">
<thead>
<tr>
<td>{% trans 'Name' %}</td>
</tr>
</thead>
<tbody>
{% for file in object.files.all %}
<tr>
<td><a href="{% url 'file' file.pk %}">{{ file.directory.path }}/{{ file.name }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No files found</p>
{% endif %}
</div>
<hr>

<div id="swidTagXmlModal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 id="deleteModalLabel">{% trans 'SWID tag' %}: {{ object.unique_id }}</h3>
</div>
<div class="modal-body">
<pre class="raw-xml">{{ object.swid_xml }}</pre>
</div>
<div class="modal-footer">
<a class="btn btn-info" data-dismiss="modal">Ok</a>
</div>
</div>
{% endif %}
</div>
</div>

{% endblock %}


74 changes: 74 additions & 0 deletions apps/swid/templates/swid/tags_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{% extends "tncapp/base.html" %}

{% load i18n %}

{% block title %}SWID tags{% endblock %}

{% block hero %}
<h1>SWID tags</h1>
{% endblock %}

{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span3" id="line">
<h4>{% trans "Tag" %}</h4>
<hr>
<div class="row-fluid">
{% if object_list.count %}
<form class="form-search pull-center" action="/tags/search" method="get">
<div class="input-append">
<input type="text" class="input input-small search-query" name="q" placeholder="Filter"
value="{{ query }}" autofocus>
<button type="submit" class="btn"><i class="icon-search"></i></button>
</div>
</form>

<table class="table table-hover">
<tbody>
{% for tag in object_list %}
<tr>
<td><a href="{% url 'swid_tag_detail' tag.pk %}">{{ tag.unique_id }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% comment %}
{% if tag|length >= 50 %}
{% if tags.paginator.num_pages > 1 %}
<div class="pagination pagination-mini pagination-centered">
<ul>
{% if tags.has_previous %}
<li><a
href="?{% if query %}q={{ query }}&{% endif %}page={{ tags.previous_page_number }}">&laquo;</a>
</li>
{% else %}
<li class="disabled"><a href="">&laquo;</a></li>
{% endif %}
<li><a
href="?{% if query %}q={{ query }}&{% endif %}page={{ tags.number }}">Page {{ tags.number }}
of {{ tags.paginator.num_pages }}</a></li>
{% if tags.has_next %}
<li><a
href="?{% if query %}q={{ query }}&{% endif %}page={{ tags.next_page_number }}">&raquo;</a>
</li>
{% else %}
<li class="disabled"><a href="">&raquo;</a></li>
{% endif %}
</ul>
</div>
{% endif %}
{% endif %}
{% endcomment %}
</div>
</div>

<div class="span9" id="content">
{% block detail %}{% endblock %}
</div>
</div>
</div>
{% endblock %}


9 changes: 5 additions & 4 deletions apps/swid/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from . import views

urlpatterns = patterns('',
url(r'^regids/$', views.RegidListView.as_view(), name='regid_list'),
url(r'^regids/(?P<pk>\d+)/$', views.RegidDetailView.as_view(), name='regid_detail'),
url(r'^swid-inventory/(?P<pk>\d+)/$', views.SwidInventoryView.as_view(), name='swid_inventory'),
)
url(r'^regids/$', views.RegidListView.as_view(), name='regid_list'),
url(r'^regids/(?P<pk>\d+)/$', views.RegidDetailView.as_view(), name='regid_detail'),
url(r'^swid-tags/$', views.SwidTagListView.as_view(), name='swid_tag_list'),
url(r'^swid-tags/(?P<pk>\d+)/$', views.SwidTagDetailView.as_view(), name='swid_tag_detail'),
)
16 changes: 11 additions & 5 deletions apps/swid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ def get_context_data(self, **kwargs):
return context


class SwidInventoryView(DetailView):
template_name = 'swid/swid_inventory.html'
model = tnc_models.Device
class SwidTagListView(ListView):
queryset = models.Tag.objects.order_by('unique_id')

This comment has been minimized.

Copy link
@tobiasbrunner

tobiasbrunner May 26, 2014

Does this load the raw XML tags? Since they are not displayed it would probably be a good idea to prevent Django from fetching them if they are not required to reduce memory usage.

This comment has been minimized.

Copy link
@dbrgn

dbrgn May 26, 2014

Member

Good point, we should use defer() here. Ticket added: #239

template_name = 'swid/tags_list.html'


class SwidTagDetailView(DetailView):
model = models.Tag
template_name = 'swid/tags_detail.html'

def get_context_data(self, **kwargs):
context = super(SwidInventoryView, self).get_context_data(**kwargs)
context['current_session'] = self.object.sessions.latest()
context = super(SwidTagDetailView, self).get_context_data(**kwargs)
context['object_list'] = self.model.objects.order_by('unique_id')
context['entityroles'] = self.object.entityrole_set.all()
return context
6 changes: 5 additions & 1 deletion tncapp/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ table.sortable th.sorter-false {

.sessions-dropdown {
width: 300px;
}
}

pre.raw-xml {
font-size: 10px;
}
2 changes: 1 addition & 1 deletion tncapp/templates/tncapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<tr><td><li{% if request.path|slice:":12" == '/directories' %} class="active"{% endif %}><a href="/directories"><i class="icon-folder-open"></i> {% trans 'Directories' %}</a></li></td></tr>
<tr><td><li{% if request.path|slice:":6" == '/files' %} class="active"{% endif %}><a href="/files"><i class="icon-file"></i> {% trans 'Files' %}</a></li></td></tr>
<tr><td><li{% if request.path|slice:":6" == '/regids' %} class="active"{% endif %}><a href="/regids"><i class="icon-barcode"></i> {% trans 'Regids' %}</a></li></td></tr>
<tr><td><li{% if request.path|slice:":4" == '/tags' %} class="active"{% endif %}><a href="/tags"><i class="icon-tag"></i> {% trans 'Tags' %}</a></li></td></tr>
<tr><td><li{% if request.path|slice:":4" == '/swid-tags' %} class="active"{% endif %}><a href="/swid-tags"><i class="icon-tag"></i> {% trans 'SWID tags' %}</a></li></td></tr>
<tr><td><li{% if request.path|slice:":11" == '/statistics' %} class="active"{% endif %}><a
href="/statistics"><i class="icon-tasks"></i> {% trans 'Statistics' %}</a></li></td></tr>
</tbody></table>
Expand Down

0 comments on commit 7419011

Please sign in to comment.