diff options
author | Karl MacMillan <kmacmill@redhat.com> | 2007-12-11 12:42:13 -0500 |
---|---|---|
committer | Karl MacMillan <kmacmill@redhat.com> | 2007-12-11 12:42:13 -0500 |
commit | d2378f13d0ce867175952346302d42c7a9a9fb2b (patch) | |
tree | adbff5e6e1715f855d08aea20e995c188dcdc248 /ipa-server/ipa-gui/ipagui/helpers | |
parent | d53915954e68ad2fa1625ed016e7e65cd6f4e4e0 (diff) | |
parent | b75d735b7e15198fbc0e7baad582696a97f0d5ec (diff) | |
download | freeipa.git-d2378f13d0ce867175952346302d42c7a9a9fb2b.tar.gz freeipa.git-d2378f13d0ce867175952346302d42c7a9a9fb2b.tar.xz freeipa.git-d2378f13d0ce867175952346302d42c7a9a9fb2b.zip |
Merge.
Diffstat (limited to 'ipa-server/ipa-gui/ipagui/helpers')
-rw-r--r-- | ipa-server/ipa-gui/ipagui/helpers/ipahelper.py | 31 |
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 |