diff --git a/api/serializers.py b/api/serializers.py index 1eaf5f3f0..2851a6a8d 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,5 +1,4 @@ from collections import OrderedDict - from django.contrib.auth.models import AnonymousUser from rest_framework_json_api import serializers @@ -139,6 +138,18 @@ class Meta: fields = ('name', 'home_page', 'long_title', 'icon') +class HarvestLogSerializer(ShareModelSerializer): + class Meta: + model = models.HarvestLog + fields = '__all__' + + +class SourceConfigSerializer(ShareModelSerializer): + class Meta: + model = models.SourceConfig + fields = '__all__' + + class SiteBannerSerializer(ShareModelSerializer): color = serializers.SerializerMethodField() diff --git a/api/urls.py b/api/urls.py index ec60b1804..bfa7e8a61 100644 --- a/api/urls.py +++ b/api/urls.py @@ -86,6 +86,8 @@ def register_url(self, subclass, viewset): register_route(r'rawdata', views.RawDatumViewSet) register_route(r'user', views.ShareUserViewSet) register_route(r'sources', views.SourceViewSet) +register_route(r'harvest_logs', views.HarvestLogViewSet) +register_route(r'source_configs', views.SourceConfigViewSet) router.register(r'normalizeddata', views.NormalizedDataViewSet, base_name='normalizeddata') diff --git a/api/views/__init__.py b/api/views/__init__.py index 68bec4096..dc1df2245 100644 --- a/api/views/__init__.py +++ b/api/views/__init__.py @@ -5,3 +5,5 @@ from .registration import * # noqa from .schema import * # noqa from .banner import * # noqa +from .harvest_logs import * # noqa +from .source_config import * # noqa diff --git a/api/views/harvest_logs.py b/api/views/harvest_logs.py new file mode 100644 index 000000000..46c0e6754 --- /dev/null +++ b/api/views/harvest_logs.py @@ -0,0 +1,24 @@ +from django_filters.filters import MultipleChoiceFilter + +from share.models import HarvestLog +from share.util import IDObfuscator + +from api.serializers import HarvestLogSerializer +# from api.views import ShareObjectViewSet + + +class SourceConfigFilterBackend(MultipleChoiceFilter): + def filter_queryset(self, request, queryset, view): + if 'source_config_id' in request.GET: + decoded = IDObfuscator.decode_id(request.GET['source_config_id']) + queryset = queryset.filter(source_config_id=decoded) + if 'status' in request.GET: + queryset = queryset.filter(status__in=request.GET.getlist('status')) + return queryset + + +class HarvestLogViewSet(ShareObjectViewSet): + serializer_class = HarvestLogSerializer + queryset = HarvestLog.objects.all() + filter_backends = (SourceConfigFilterBackend, ) + filter_fields = ('source_config_id', 'status',) diff --git a/api/views/share.py b/api/views/share.py index 798762c2a..a76566e26 100644 --- a/api/views/share.py +++ b/api/views/share.py @@ -9,13 +9,13 @@ from django.views.decorators.http import require_GET from django.views.generic.base import RedirectView +from share.util import IDObfuscator, InvalidID +from share.models import Source + from api.pagination import CursorPagination from api.permissions import IsDeletedPremissions from api import serializers as api_serializers -from share.util import IDObfuscator, InvalidID -from share.models import Source - class ShareObjectViewSet(viewsets.ReadOnlyModelViewSet): ordering = ('-id', ) diff --git a/api/views/source_config.py b/api/views/source_config.py new file mode 100644 index 000000000..e634ee94b --- /dev/null +++ b/api/views/source_config.py @@ -0,0 +1,11 @@ +from share.models import SourceConfig + +from api.pagination import FuzzyPageNumberPagination +from api.serializers import SourceConfigSerializer +from api.views import ShareObjectViewSet + + +class SourceConfigViewSet(ShareObjectViewSet): + serializer_class = SourceConfigSerializer + pagination_class = FuzzyPageNumberPagination + queryset = SourceConfig.objects.all() diff --git a/api/views/workflow.py b/api/views/workflow.py index 30e1c906c..b48df7216 100644 --- a/api/views/workflow.py +++ b/api/views/workflow.py @@ -16,18 +16,19 @@ from rest_framework.serializers import ValidationError from rest_framework.permissions import DjangoModelPermissionsOrAnonReadOnly -from api import schemas -from api.pagination import CursorPagination -from api.authentication import APIV1TokenBackPortAuthentication -from api.permissions import ReadOnlyOrTokenHasScopeOrIsAuthenticated -from api.serializers import FullNormalizedDataSerializer, BasicNormalizedDataSerializer, \ - RawDatumSerializer, ShareUserSerializer, SourceSerializer from share.models import RawDatum, NormalizedData, Source, SourceConfig, Transformer, ShareUser from share.tasks import disambiguate from share.harvest.serialization import DictSerializer from share.harvest.base import FetchResult from share.util import IDObfuscator +from api import schemas +from api.pagination import CursorPagination +from api.authentication import APIV1TokenBackPortAuthentication +from api.permissions import ReadOnlyOrTokenHasScopeOrIsAuthenticated +from api.serializers import FullNormalizedDataSerializer, BasicNormalizedDataSerializer, RawDatumSerializer, ShareUserSerializer, SourceSerializer + + logger = logging.getLogger(__name__) __all__ = ('NormalizedDataViewSet', 'RawDatumViewSet', 'ShareUserViewSet', 'SourceViewSet', 'V1DataView') diff --git a/docs/elasticsearch.rst b/docs/elasticsearch.rst index 5c6f59b37..3d0645b25 100644 --- a/docs/elasticsearch.rst +++ b/docs/elasticsearch.rst @@ -26,6 +26,7 @@ Elasticsearch can be used to search the following fields in the normalized data: 'contributors' 'funders' 'publishers' + 'id' Accessing the Search API