Commit 69d7abf6 by Bence Dányi

firewall_gui: comments

parent 82514d62
...@@ -39,11 +39,12 @@ def map_rule_target(rule): ...@@ -39,11 +39,12 @@ def map_rule_target(rule):
def json_attr(entity, attr): def json_attr(entity, attr):
''' jsonify the `attr` attribute of `entity` ''' ''' jsonify the `attr` attribute of `entity` '''
# an objects name usually is in the `name` attribute, but not always, so put here the exceptions # an objects name usually is in the `name` attribute, but not always (thanks bd!), so put here the exceptions
common_names = { common_names = {
'host': 'hostname', 'host': 'hostname',
'owner': 'username',} 'owner': 'username',}
try: try:
# return something that can be converted to JSON, based on the `attr` field type
return { return {
# if `attr` is an entity, parse its name&id # if `attr` is an entity, parse its name&id
'ForeignKey': lambda entity: { 'ForeignKey': lambda entity: {
...@@ -72,7 +73,7 @@ def make_entity_lister(entity_type, mapping): ...@@ -72,7 +73,7 @@ def make_entity_lister(entity_type, mapping):
if type(attr) is tuple: if type(attr) is tuple:
result[attr[0]] = attr[1](entity) result[attr[0]] = attr[1](entity)
else: else:
# if `attr` is just a string, the try to jsonify it # if `attr` is just a string, the try to jsonify the corresponding model attribute
result[attr] = json_attr(entity, attr) result[attr] = json_attr(entity, attr)
return result return result
......
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