diff options
author | Rob Crittenden <rcritten@redhat.com> | 2007-12-04 13:18:37 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2007-12-04 13:18:37 -0500 |
commit | 2fbe5cbf492597a87427b61f1e470052b77465b2 (patch) | |
tree | 0a4bdf0cbd8068f7d2e33a9be7037b178ee7f378 /ipa-server/ipa-gui/ipagui/helpers/ipahelper.py | |
parent | 69765f52ce54eacb704b7ff1ee4287a3ed787371 (diff) | |
download | freeipa-2fbe5cbf492597a87427b61f1e470052b77465b2.tar.gz freeipa-2fbe5cbf492597a87427b61f1e470052b77465b2.tar.xz freeipa-2fbe5cbf492597a87427b61f1e470052b77465b2.zip |
Phase 1 of allowing admins to set the default object classes for users & groups
This adds the UI and does error checking of the selected object classes but
it doesn't actually use the values yet.
It also generalizes some functions for doing multi-valued fields.
Diffstat (limited to 'ipa-server/ipa-gui/ipagui/helpers/ipahelper.py')
-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 9ea6b48ab..e5c2bd378 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 |