summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-02-22 14:55:35 -0500
committerSimo Sorce <simo@redhat.com>2015-02-24 10:24:44 -0500
commit9309f2e568d33c0901d093f1afecc59c0b8aebc4 (patch)
tree89d1c8040a1415bde85a9f0926f8f5cb60cd161f
parent33ba04588e5866e8014b61d5a05da009a0581d93 (diff)
downloadipsilon-9309f2e568d33c0901d093f1afecc59c0b8aebc4.tar.gz
ipsilon-9309f2e568d33c0901d093f1afecc59c0b8aebc4.tar.xz
ipsilon-9309f2e568d33c0901d093f1afecc59c0b8aebc4.zip
Handle changing ComplexList options
Add admin function to handle getting a ComplexList object in form of key/value pair fields. Signed-off-by: Simo Sorce <simo@redhat.com>
-rw-r--r--ipsilon/admin/common.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py
index e1394e8..4e92d1f 100644
--- a/ipsilon/admin/common.py
+++ b/ipsilon/admin/common.py
@@ -66,6 +66,67 @@ class AdminPluginConfig(AdminPage):
self._po.name),
config=self._po.get_config_obj())
+ def get_complex_list_value(self, name, old_value, **kwargs):
+ delete = list()
+ change = dict()
+ for key, val in kwargs.iteritems():
+ if not key.startswith(name):
+ continue
+ n = key[len(name):]
+ if len(n) == 0 or n[0] != ' ':
+ continue
+ try:
+ index, field = n[1:].split('-')
+ except ValueError:
+ continue
+ if field == 'delete':
+ delete.append(int(index))
+ elif field == 'name':
+ change[int(index)] = val
+
+ if len(delete) == 0 and len(change) == 0:
+ return None
+
+ value = old_value
+
+ # remove unwanted changes
+ for i in delete:
+ if i in change:
+ del change[i]
+
+ # perform requested changes
+ for index, val in change.iteritems():
+ val_list = val.split('/')
+ stripped = list()
+ for v in val_list:
+ stripped.append(v.strip())
+ if len(stripped) == 1:
+ stripped = stripped[0]
+ if len(value) <= index:
+ value.extend([None]*(index + 1 - len(value)))
+ value[index] = stripped
+
+ if len(value[index]) == 0:
+ value[index] = None
+
+ # the previous loop may add 'None' entries
+ # if any still exists mark them to be deleted
+ for i in xrange(0, len(value)):
+ if value[i] is None:
+ delete.append(i)
+
+ # remove duplicates and set in reverse order
+ delete = list(set(delete))
+ delete.sort(reverse=True)
+
+ for i in delete:
+ if len(value) > i:
+ del value[i]
+
+ if len(value) == 0:
+ value = None
+ return value
+
@admin_protect
def GET(self, *args, **kwargs):
return self.root_with_msg()
@@ -100,6 +161,12 @@ class AdminPluginConfig(AdminPage):
aname = '%s_%s' % (name, a)
if aname in kwargs:
value.append(a)
+ elif type(option) is pconfig.ComplexList:
+ value = self.get_complex_list_value(name,
+ option.get_value(),
+ **kwargs)
+ if value is None:
+ continue
else:
continue