@@ 86-103 (lines=18) @@ | ||
83 | value = super(ResultsRangesField, self)._to_dict(value) |
|
84 | return map(self.resolve_uid, value) |
|
85 | ||
86 | def resolve_uid(self, raw_dict): |
|
87 | """Returns a copy of the raw dictionary passed in, but with additional |
|
88 | key "uid". It's value is inferred from "keyword" if present |
|
89 | """ |
|
90 | value = raw_dict.copy() |
|
91 | uid = value.get("uid") |
|
92 | if api.is_uid(uid) and uid != "0": |
|
93 | return value |
|
94 | ||
95 | # uid key does not exist or is not valid, try to infere from keyword |
|
96 | keyword = value.get("keyword") |
|
97 | if keyword: |
|
98 | query = dict(portal_type="AnalysisService", getKeyword=keyword) |
|
99 | brains = api.search(query, SETUP_CATALOG) |
|
100 | if len(brains) == 1: |
|
101 | uid = api.get_uid(brains[0]) |
|
102 | value["uid"] = uid |
|
103 | return value |
|
104 | ||
105 | ||
106 | registerField(ResultsRangesField, title="ResultsRanges", |
@@ 179-196 (lines=18) @@ | ||
176 | # Return the original with no changes |
|
177 | return rrs |
|
178 | ||
179 | def resolve_uid(self, result_range): |
|
180 | """Resolves the uid key for the result_range passed in if it does not |
|
181 | exist when contains a keyword |
|
182 | """ |
|
183 | value = result_range.copy() |
|
184 | uid = value.get("uid") |
|
185 | if api.is_uid(uid) and uid != "0": |
|
186 | return value |
|
187 | ||
188 | # uid key does not exist or is not valid, try to infere from keyword |
|
189 | keyword = value.get("keyword") |
|
190 | if keyword: |
|
191 | query = dict(portal_type="AnalysisService", getKeyword=keyword) |
|
192 | brains = api.search(query, SETUP_CATALOG) |
|
193 | if len(brains) == 1: |
|
194 | uid = api.get_uid(brains[0]) |
|
195 | value["uid"] = uid |
|
196 | return value |
|
197 | ||
198 | def resolve_conditions(self, analysis): |
|
199 | """Returns the conditions to be applied to this analysis by merging |