Add API endpoint to show all available search models.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
- Catch documents with not document version when displaying their thumbnails.
|
||||
- Document page navigation fix when using Mayan as a sub URL app.
|
||||
- Add support for indexing on workflow state changes.
|
||||
- Add search model list API endpoint.
|
||||
|
||||
2.2 (2017-04-26)
|
||||
================
|
||||
|
||||
@@ -38,6 +38,7 @@ Changes
|
||||
name `publish_workflow`, it will be accessible in the indexing template as
|
||||
{{ document.workflow.publish_workflow }}. The latest state of the workflow
|
||||
can be accessed using {{ document.workflow.publish_workflow.get_current_state }}.
|
||||
- Added a new API endpoint to display a list of all the available search models.
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
@@ -5,7 +5,9 @@ from rest_framework.exceptions import ParseError
|
||||
|
||||
from rest_api.filters import MayanObjectPermissionsFilter
|
||||
|
||||
from .classes import SearchModel
|
||||
from .mixins import SearchModelMixin
|
||||
from .serializers import SearchModelSerializer
|
||||
|
||||
|
||||
class APISearchView(SearchModelMixin, generics.ListAPIView):
|
||||
@@ -15,11 +17,6 @@ class APISearchView(SearchModelMixin, generics.ListAPIView):
|
||||
GET:
|
||||
omit_serializer: true
|
||||
parameters:
|
||||
- name: search_model
|
||||
paramType: path
|
||||
type: string
|
||||
required: true
|
||||
description: Possible values are "documents.Document" or "document.DocumentPageResult"
|
||||
- name: q
|
||||
paramType: query
|
||||
type: string
|
||||
@@ -55,11 +52,6 @@ class APIAdvancedSearchView(SearchModelMixin, generics.ListAPIView):
|
||||
GET:
|
||||
omit_serializer: true
|
||||
parameters:
|
||||
- name: search_model
|
||||
paramType: path
|
||||
type: string
|
||||
required: true
|
||||
description: Possible values are "documents.Document" or "document.DocumentPageResult"
|
||||
- name: _match_all
|
||||
paramType: query
|
||||
type: string
|
||||
@@ -94,3 +86,15 @@ class APIAdvancedSearchView(SearchModelMixin, generics.ListAPIView):
|
||||
raise ParseError(unicode(exception))
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
class APISearchModelList(generics.ListAPIView):
|
||||
serializer_class = SearchModelSerializer
|
||||
queryset = SearchModel.all()
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
"""
|
||||
Returns a list of all the available search models.
|
||||
"""
|
||||
|
||||
return super(APISearchModelList, self).get(*args, **kwargs)
|
||||
|
||||
@@ -47,6 +47,10 @@ class SearchModel(object):
|
||||
self.permission = permission
|
||||
self.__class__.registry[self.get_full_name()] = self
|
||||
|
||||
@property
|
||||
def pk(self):
|
||||
return self.get_full_name()
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
if not self._model:
|
||||
|
||||
11
mayan/apps/dynamic_search/serializers.py
Normal file
11
mayan/apps/dynamic_search/serializers.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from .classes import SearchModel
|
||||
|
||||
|
||||
class SearchModelSerializer(serializers.Serializer):
|
||||
app_label = serializers.CharField(read_only=True)
|
||||
model_name = serializers.CharField(read_only=True)
|
||||
pk = serializers.CharField(read_only=True)
|
||||
@@ -14,6 +14,8 @@ from user_management.tests import (
|
||||
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
|
||||
)
|
||||
|
||||
from ..classes import SearchModel
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class SearchAPITestCase(BaseAPITestCase):
|
||||
@@ -52,3 +54,13 @@ class SearchAPITestCase(BaseAPITestCase):
|
||||
content = loads(response.content)
|
||||
self.assertEqual(content['results'][0]['label'], document.label)
|
||||
self.assertEqual(content['count'], 1)
|
||||
|
||||
def test_search_models_view(self):
|
||||
response = self.client.get(
|
||||
reverse('rest_api:searchmodel-list')
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
[search_model['pk'] for search_model in response.data['results']],
|
||||
[search_model.pk for search_model in SearchModel.all()]
|
||||
)
|
||||
|
||||
@@ -2,7 +2,9 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .api_views import APIAdvancedSearchView, APISearchView
|
||||
from .api_views import (
|
||||
APIAdvancedSearchView, APISearchModelList, APISearchView
|
||||
)
|
||||
from .views import (
|
||||
AdvancedSearchView, ResultsView, SearchAgainView, SearchView
|
||||
)
|
||||
@@ -24,6 +26,10 @@ urlpatterns = [
|
||||
]
|
||||
|
||||
api_urls = [
|
||||
url(
|
||||
r'^search_models/$', APISearchModelList.as_view(),
|
||||
name='searchmodel-list'
|
||||
),
|
||||
url(
|
||||
r'^search/(?P<search_model>[\.\w]+)/$', APISearchView.as_view(),
|
||||
name='search-view'
|
||||
|
||||
Reference in New Issue
Block a user