Fix TemplateSyntaxError in the server-side filetring of node list views

The server-side filtering had two bugs:
* the ip_address is not always available for all nodes
* the fileds used for filtering were not always strings

In addition, I replaced the obsolete glyphicons icon with a Font
Awesome icon for filter.

Change-Id: I21f4ba835b536d1a179d1af696c2619f25692cc7
This commit is contained in:
Radomir Dopieralski 2014-12-18 15:14:36 +01:00
parent dd674afa1a
commit d4fb80f500
3 changed files with 13 additions and 8 deletions

View File

@ -652,8 +652,12 @@ class Node(base.APIResourceWrapper):
@cached_property
def ip_address(self):
return (self.instance._apiresource.addresses['ctlplane'][0]
['addr'])
try:
apiresource = self.instace._apiresource
except AttributeError:
LOG.error("Couldn't obtain IP address")
return None
return apiresource.addresses['ctlplane'][0]['addr']
@cached_property
def image_name(self):

View File

@ -111,11 +111,12 @@ class NodeFilterAction(tables.FilterAction):
q = filter_string.lower()
def comp(node):
return any(q in attr for attr in
(node.ip_address,
node.cpus,
node.memory_mb,
node.local_gb,))
return any(q in unicode(value).lower() for value in (
node.ip_address,
node.cpus,
node.memory_mb,
node.local_gb,
))
return filter(comp, nodes)

View File

@ -13,7 +13,7 @@
<input class="form-control" value="{{ filter.filter_string|default:'' }}" type="text" name="{{ filter.get_param_name }}" />
<span class="input-group-btn">
<button class="btn btn-default" type="submit" {{ filter.attr_string|safe }}>
<span class="glyphicon glyphicon-search"></span>
<span class="fa fa-lg fa-filter"></span>
</button>
</span>
</div>