Commit 689327cf by Kálmán Viktor

network: filter hosts by vlan

parent e743c410
......@@ -9,5 +9,13 @@
<h1>Hosts <small>list of all hosts</small></h1>
</div>
<ul class="nav nav-pills">
<li class="disabled"><a href="#">Filter by vlans</a></li>
<li {% if not request.GET.vlan %} class="active"{% endif %}><a href="{{ request.path }}">ALL</a></li>
{% for vlan in vlans %}
<li{% if request.GET.vlan|add:"0" == vlan.id %} class="active"{% endif %}><a href="?vlan={{ vlan.id }}">{{ vlan.name }}</a></li>
{% endfor %}
</ul>
{% render_table table %}
{% endblock %}
......@@ -34,6 +34,22 @@ class HostList(SingleTableView):
table_class = HostTable
template_name = "network/host-list.html"
def get_context_data(self, **kwargs):
context = super(HostList, self).get_context_data(**kwargs)
q = Vlan.objects.all().order_by("name")
context['vlans'] = q
return context
def get_table_data(self):
vlan_id = self.request.GET.get('vlan')
print vlan_id
if vlan_id:
data = Host.objects.filter(vlan=vlan_id).all()
else:
data = Host.objects.all()
return data
class HostDetail(UpdateView):
model = Host
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment