Performs a filter with the OData 'iterable_name' keyword on the collection For example: q.iterable('any', collection='email_addresses', attribute='address', operation='eq', word='george@best.com') will transform to a filter such as: emailAddresses/a
(self, iterable_name, *, collection, word, attribute=None, func=None,
operation=None, negation=False)
| 1124 | |
| 1125 | @fluent |
| 1126 | def iterable(self, iterable_name, *, collection, word, attribute=None, func=None, |
| 1127 | operation=None, negation=False): |
| 1128 | """ Performs a filter with the OData 'iterable_name' keyword |
| 1129 | on the collection |
| 1130 | |
| 1131 | For example: |
| 1132 | q.iterable('any', collection='email_addresses', attribute='address', |
| 1133 | operation='eq', word='george@best.com') |
| 1134 | |
| 1135 | will transform to a filter such as: |
| 1136 | emailAddresses/any(a:a/address eq 'george@best.com') |
| 1137 | |
| 1138 | :param str iterable_name: the OData name of the iterable |
| 1139 | :param str collection: the collection to apply the any keyword on |
| 1140 | :param str word: the word to check |
| 1141 | :param str attribute: the attribute of the collection to check |
| 1142 | :param str func: the logical function to apply to the attribute inside |
| 1143 | the collection |
| 1144 | :param str operation: the logical operation to apply to the attribute |
| 1145 | inside the collection |
| 1146 | :param bool negation: negate the funcion or operation inside the iterable |
| 1147 | :rtype: Query |
| 1148 | """ |
| 1149 | |
| 1150 | if func is None and operation is None: |
| 1151 | raise ValueError('Provide a function or an operation to apply') |
| 1152 | elif func is not None and operation is not None: |
| 1153 | raise ValueError( |
| 1154 | 'Provide either a function or an operation but not both') |
| 1155 | |
| 1156 | current_att = self._attribute |
| 1157 | self._attribute = iterable_name |
| 1158 | |
| 1159 | word = self._parse_filter_word(word) |
| 1160 | collection = self._get_mapping(collection) |
| 1161 | attribute = self._get_mapping(attribute) |
| 1162 | |
| 1163 | if attribute is None: |
| 1164 | attribute = 'a' # it's the same iterated object |
| 1165 | else: |
| 1166 | attribute = 'a/{}'.format(attribute) |
| 1167 | |
| 1168 | if func is not None: |
| 1169 | sentence = self._prepare_function(func, attribute, word, negation) |
| 1170 | else: |
| 1171 | sentence = self._prepare_sentence(attribute, operation, word, negation) |
| 1172 | |
| 1173 | filter_str, attrs = sentence |
| 1174 | |
| 1175 | # consume negation |
| 1176 | negation = 'not' if self._negation else '' |
| 1177 | if self._negation: |
| 1178 | self._negation = False |
| 1179 | |
| 1180 | filter_data = '{} {}/{}(a:{})'.format(negation, collection, iterable_name, filter_str).strip(), attrs |
| 1181 | self._add_filter(*filter_data) |
| 1182 | |
| 1183 | self._attribute = current_att |
no test coverage detected