Skip to content

Commit

Permalink
collection version references view
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 5, 2020
1 parent d6c7990 commit 306e591
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/collections/urls.py
Expand Up @@ -67,6 +67,11 @@
),
include('core.mappings.urls')
),
re_path(
r'^(?P<collection>{pattern})/(?P<version>{pattern})/references/$'.format(pattern=NAMESPACE_PATTERN),
views.CollectionVersionReferencesView.as_view(),
name='collectionversion-references'
),
re_path(
r'^(?P<collection>{pattern})/(?P<version>{pattern})/processing/$'.format(pattern=NAMESPACE_PATTERN),
views.CollectionVersionProcessingView.as_view(),
Expand Down
13 changes: 13 additions & 0 deletions core/collections/views.py
Expand Up @@ -326,6 +326,19 @@ def get_version_information_of_related_mappings(instance, related_mappings):
)


class CollectionVersionReferencesView(CollectionVersionBaseView, ListWithHeadersMixin):
serializer_class = CollectionReferenceSerializer

def get(self, request, *args, **kwargs):
query_params = self.request.query_params
search_query = query_params.get('q', '')
sort = query_params.get('search_sort', 'ASC')
object_version = self.get_queryset().first().head
references = object_version.references.filter(expression__icontains=search_query)
self.object_list = references if sort == 'ASC' else list(reversed(references))
return self.list(request, *args, **kwargs)


class CollectionVersionListView(CollectionVersionBaseView, mixins.CreateModelMixin, ListWithHeadersMixin):
released_filter = None
processing_filter = None
Expand Down

0 comments on commit 306e591

Please sign in to comment.