| @@ 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", |
|
| @@ 198-215 (lines=18) @@ | ||
| 195 | # Return the original with no changes |
|
| 196 | return rrs |
|
| 197 | ||
| 198 | def resolve_uid(self, result_range): |
|
| 199 | """Resolves the uid key for the result_range passed in if it does not |
|
| 200 | exist when contains a keyword |
|
| 201 | """ |
|
| 202 | value = result_range.copy() |
|
| 203 | uid = value.get("uid") |
|
| 204 | if api.is_uid(uid) and uid != "0": |
|
| 205 | return value |
|
| 206 | ||
| 207 | # uid key does not exist or is not valid, try to infere from keyword |
|
| 208 | keyword = value.get("keyword") |
|
| 209 | if keyword: |
|
| 210 | query = dict(portal_type="AnalysisService", getKeyword=keyword) |
|
| 211 | brains = api.search(query, SETUP_CATALOG) |
|
| 212 | if len(brains) == 1: |
|
| 213 | uid = api.get_uid(brains[0]) |
|
| 214 | value["uid"] = uid |
|
| 215 | return value |
|
| 216 | ||
| 217 | def add_analysis(self, instance, service, **kwargs): |
|
| 218 | service_uid = api.get_uid(service) |
|