Convert the API to use viewsets. The search function is now a service of the search model resource. The simple and advance search are now the same service. The difference is determined by the URL query. A ?q= means a simple search. For advanced search pass the search model fields in the URL query, example: ?q=document_type__label= Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
18 lines
473 B
Python
18 lines
473 B
Python
from __future__ import unicode_literals
|
|
|
|
from django.http import Http404
|
|
from django.utils.encoding import force_text
|
|
|
|
from .classes import SearchModel
|
|
|
|
|
|
class SearchModelMixin(object):
|
|
def get_search_model_name(self):
|
|
return self.kwargs.get('search_model')
|
|
|
|
def get_search_model(self):
|
|
try:
|
|
return SearchModel.get(name=self.get_search_model_name())
|
|
except KeyError as exception:
|
|
raise Http404(force_text(exception))
|