summaryrefslogtreecommitdiffstats
path: root/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
diff options
context:
space:
mode:
authorKarl MacMillan <kmacmill@redhat.com>2007-12-06 17:21:48 -0500
committerKarl MacMillan <kmacmill@redhat.com>2007-12-06 17:21:48 -0500
commitca118de76cb036acb31eae41970b962497d18838 (patch)
tree90f82e999620ce23e944564d4a7e3e4f94cd9e72 /ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
parentcd93c81a13aefa75c778ea641c67c505a79ac8c1 (diff)
parent86d80f12ca6c0add3d19e8351633dbcfe3a62e9e (diff)
downloadfreeipa.git-ca118de76cb036acb31eae41970b962497d18838.tar.gz
freeipa.git-ca118de76cb036acb31eae41970b962497d18838.tar.xz
freeipa.git-ca118de76cb036acb31eae41970b962497d18838.zip
Merge.
Diffstat (limited to 'ipa-server/ipa-gui/ipagui/helpers/ipahelper.py')
-rw-r--r--ipa-server/ipa-gui/ipagui/helpers/ipahelper.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py b/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
index 9ea6b48a..e5c2bd37 100644
--- a/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
+++ b/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
@@ -7,3 +7,34 @@ def javascript_string_escape(input):
return re.sub(r'[\'\"\\]',
lambda match: "\\%s" % match.group(),
input)
+
+def setup_mv_fields(field, fieldname):
+ """Given a field (must be a list) and field name, convert that
+ field into a list of dictionaries of the form:
+ [ { fieldname : v1}, { fieldname : v2 }, .. ]
+
+ This is how we pre-fill values for multi-valued fields.
+ """
+ mvlist = []
+ if field:
+ for v in field:
+ if v:
+ mvlist.append({ fieldname : v } )
+ if len(mvlist) == 0:
+ # We need to return an empty value so something can be
+ # displayed on the edit page. Otherwise only an Add link
+ # will show, not an empty field.
+ mvlist.append({ fieldname : '' } )
+ return mvlist
+
+def fix_incoming_fields(fields, fieldname, multifieldname):
+ """This is called by the update() function. It takes the incoming
+ list of dictionaries and converts it into back into the original
+ field, then removes the multiple field.
+ """
+ fields[fieldname] = []
+ for i in range(len(fields[multifieldname])):
+ fields[fieldname].append(fields[multifieldname][i][fieldname])
+ del(fields[multifieldname])
+
+ return fields