| @@ 158-175 (lines=18) @@ | ||
| 155 | # Return the original with no changes |
|
| 156 | return rrs |
|
| 157 | ||
| 158 | def resolve_uid(self, result_range): |
|
| 159 | """Resolves the uid key for the result_range passed in if it does not |
|
| 160 | exist when contains a keyword |
|
| 161 | """ |
|
| 162 | value = result_range.copy() |
|
| 163 | uid = value.get("uid") |
|
| 164 | if api.is_uid(uid) and uid != "0": |
|
| 165 | return value |
|
| 166 | ||
| 167 | # uid key does not exist or is not valid, try to infere from keyword |
|
| 168 | keyword = value.get("keyword") |
|
| 169 | if keyword: |
|
| 170 | query = dict(portal_type="AnalysisService", getKeyword=keyword) |
|
| 171 | brains = api.search(query, SETUP_CATALOG) |
|
| 172 | if len(brains) == 1: |
|
| 173 | uid = api.get_uid(brains[0]) |
|
| 174 | value["uid"] = uid |
|
| 175 | return value |
|
| 176 | ||
| 177 | def resolve_conditions(self, analysis): |
|
| 178 | """Returns the conditions to be applied to this analysis by merging |
|
| @@ 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", |
|