Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad0n20 committed Jan 9, 2025
1 parent 7b16120 commit beb68ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
35 changes: 33 additions & 2 deletions api/base/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,35 @@ def parse_query_params(self, query_params):
})
elif self.should_parse_special_query_params(field_name):
query = self.parse_special_query_params(field_name, key, value, query)
elif not isinstance(value, int) and source_field_name == 'target__guids___id':
base_guid, version = Guid.split_guid(value)
if base_guid is None and version is None:
raise InvalidFilterValue(
value=value,
field_type='guid',
)
guid_filters = {
field_name: {
'op': 'in',
'value': self.bulk_get_values(value, field),
'source_field_name': source_field_name,
},
}
if version is not None:
guid_filters = {
field_name: {
'op': 'eq',
'value': base_guid,
'source_field_name': 'target__guids___id',
},
'target__versioned_guids__version': {
'op': 'eq',
'value': version,
'source_field_name': 'target__versioned_guids__version',
},
}

query.get(key).update(guid_filters)
else:
query.get(key).update({
field_name: {
Expand Down Expand Up @@ -482,13 +511,15 @@ def param_queryset(self, query_params, default_queryset):
),
)
if not isinstance(queryset, list):
sub_query = functools.reduce(operator.or_, sub_query_parts)
if not list(filter(lambda x: 'versioned_guids' in x.children[0][0], sub_query_parts)):
sub_query = functools.reduce(operator.or_, sub_query_parts)
else:
sub_query = functools.reduce(operator.and_, sub_query_parts)
query_parts.append(sub_query)

if not isinstance(queryset, list):
for query in query_parts:
queryset = queryset.filter(query)

return queryset

def build_query_from_field(self, field_name, operation):
Expand Down
3 changes: 2 additions & 1 deletion api_tests/preprints/views/test_preprint_list_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def test_filter_published_false_admin(
res = app.get(
f'{url}filter[is_published]=false',
auth=user_admin_contrib.auth)
assert len(res.json['data']) == 0
assert len(res.json['data']) == 1
assert preprint_unpublished._id in [d['id'] for d in res.json['data']]


@pytest.mark.django_db
Expand Down

0 comments on commit beb68ee

Please sign in to comment.