~ubuntu-branches/ubuntu/raring/quantum/raring

« back to all changes in this revision

Viewing changes to quantum/api/v2/base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-09-21 13:01:18 UTC
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20120921130118-6x31znohp1psfc74
Tags: upstream-2012.2~rc2
ImportĀ upstreamĀ versionĀ 2012.2~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        if key == 'fields':
83
83
            continue
84
84
        values = [v for v in request.GET.getall(key) if v]
85
 
        if not attr_info.get(key) and values:
 
85
        key_attr_info = attr_info.get(key, {})
 
86
        if not key_attr_info and values:
86
87
            res[key] = values
87
88
            continue
88
 
        result_values = []
89
 
        convert_to = (attr_info.get(key) and attr_info[key].get('convert_to')
90
 
                      or None)
91
 
        for value in values:
 
89
        convert_list_to = key_attr_info.get('convert_list_to')
 
90
        if not convert_list_to:
 
91
            convert_to = key_attr_info.get('convert_to')
92
92
            if convert_to:
93
 
                try:
94
 
                    result_values.append(convert_to(value))
95
 
                except exceptions.InvalidInput as e:
96
 
                    raise webob.exc.HTTPBadRequest(str(e))
97
 
            else:
98
 
                result_values.append(value)
 
93
                convert_list_to = lambda values_: [convert_to(x)
 
94
                                                   for x in values_]
 
95
        if convert_list_to:
 
96
            try:
 
97
                result_values = convert_list_to(values)
 
98
            except exceptions.InvalidInput as e:
 
99
                raise webob.exc.HTTPBadRequest(str(e))
 
100
        else:
 
101
            result_values = values
99
102
        if result_values:
100
103
            res[key] = result_values
101
104
    return res