Revision 40b118d3
b/lib/query.py | ||
---|---|---|
977 | 977 |
return lambda _, item: getter(item) |
978 | 978 |
|
979 | 979 |
|
980 |
def _GetItemMaybeAttr(attr): |
|
981 |
"""Returns a field function to return a not-None attribute of the item. |
|
982 |
|
|
983 |
If the value is None, then C{_FS_UNAVAIL} will be returned instead. |
|
984 |
|
|
985 |
@param attr: Attribute name |
|
986 |
|
|
987 |
""" |
|
988 |
def _helper(_, obj): |
|
989 |
val = getattr(obj, attr) |
|
990 |
if val is None: |
|
991 |
return _FS_UNAVAIL |
|
992 |
else: |
|
993 |
return val |
|
994 |
return _helper |
|
995 |
|
|
996 |
|
|
980 | 997 |
def _GetNDParam(name): |
981 | 998 |
"""Return a field function to return an ND parameter out of the context. |
982 | 999 |
|
... | ... | |
2614 | 2631 |
# Add simple fields |
2615 | 2632 |
fields.extend([ |
2616 | 2633 |
(_MakeField(name, title, kind, doc), |
2617 |
NETQ_CONFIG, 0, _GetItemAttr(name)) |
|
2634 |
NETQ_CONFIG, 0, _GetItemMaybeAttr(name))
|
|
2618 | 2635 |
for (name, (title, kind, _, doc)) in _NETWORK_SIMPLE_FIELDS.items()]) |
2619 | 2636 |
|
2620 | 2637 |
def _GetLength(getter): |
Also available in: Unified diff