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:
parent
dd674afa1a
commit
d4fb80f500
@ -652,8 +652,12 @@ class Node(base.APIResourceWrapper):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def ip_address(self):
|
def ip_address(self):
|
||||||
return (self.instance._apiresource.addresses['ctlplane'][0]
|
try:
|
||||||
['addr'])
|
apiresource = self.instace._apiresource
|
||||||
|
except AttributeError:
|
||||||
|
LOG.error("Couldn't obtain IP address")
|
||||||
|
return None
|
||||||
|
return apiresource.addresses['ctlplane'][0]['addr']
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def image_name(self):
|
def image_name(self):
|
||||||
|
@ -111,11 +111,12 @@ class NodeFilterAction(tables.FilterAction):
|
|||||||
q = filter_string.lower()
|
q = filter_string.lower()
|
||||||
|
|
||||||
def comp(node):
|
def comp(node):
|
||||||
return any(q in attr for attr in
|
return any(q in unicode(value).lower() for value in (
|
||||||
(node.ip_address,
|
node.ip_address,
|
||||||
node.cpus,
|
node.cpus,
|
||||||
node.memory_mb,
|
node.memory_mb,
|
||||||
node.local_gb,))
|
node.local_gb,
|
||||||
|
))
|
||||||
|
|
||||||
return filter(comp, nodes)
|
return filter(comp, nodes)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<input class="form-control" value="{{ filter.filter_string|default:'' }}" type="text" name="{{ filter.get_param_name }}" />
|
<input class="form-control" value="{{ filter.filter_string|default:'' }}" type="text" name="{{ filter.get_param_name }}" />
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-default" type="submit" {{ filter.attr_string|safe }}>
|
<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>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user