Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/status board #708

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
19 changes: 16 additions & 3 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from rest_framework_json_api import serializers

from share import models
from share.models import ProviderRegistration, SiteBanner, CeleryTaskResult

from api import fields

from share.models import ProviderRegistration, SiteBanner, CeleryTaskResult, HarvestLog, SourceConfig


from share.models import ProviderRegistration, SiteBanner, CeleryTaskResult, logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all the from share.models imports, just use from share import models (and update existing things to match)


from api import fields

class BaseShareSerializer(serializers.ModelSerializer):

Expand Down Expand Up @@ -132,12 +136,21 @@ class Meta:
'is_active', 'gravatar', 'locale', 'time_zone', 'is_trusted'
)


class SourceSerializer(ShareModelSerializer):
class Meta:
model = models.Source
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()
Expand Down
4 changes: 4 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from api.serializers import BaseShareSerializer
from api.views.share import ShareObjectViewSet



app_name = 'api'

router = DefaultRouter()
Expand Down Expand Up @@ -86,6 +88,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'HarvestLog', views.HarvestLogViewSet)
register_route(r'SourceConfig', views.SourceConfigViewSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these routes should be snake case and plural (harvest_logs, source_configs)


router.register(r'normalizeddata', views.NormalizedDataViewSet, base_name='normalizeddata')

Expand Down
2 changes: 2 additions & 0 deletions api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from .registration import * # noqa
from .schema import * # noqa
from .banner import * # noqa
from .harvestlogs import * # noqa
from .sourceConfig import * # noqa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename these files:
harvestlogs.py => harvest_logs.py
sourceConfig.py => source_config.py

23 changes: 23 additions & 0 deletions api/views/harvestlogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from rest_framework import viewsets
from rest_framework import filters
from django_filters.filters import MultipleChoiceFilter
from api.views import ShareObjectViewSet
from share.util import IDObfuscator

from api.serializers import HarvestLogSerializer
from share.models import HarvestLog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import ordering from most broadly available to most specific:

  • built-ins
  • 3rd-party imports
  • 2nd-party imports
  • 1st-party imports


class SourceConfigFilterBackend(MultipleChoiceFilter):
def filter_queryset(self, request, queryset, view, conjoined=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove conjoined

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',)
2 changes: 2 additions & 0 deletions api/views/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class ShareObjectViewSet(viewsets.ReadOnlyModelViewSet):

# Override get_queryset to handle items marked as deleted.
def get_queryset(self, list=True):
# import ipdb; ipdb.set_trace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

queryset = super().get_queryset()
if list and hasattr(queryset.model, 'is_deleted'):
return queryset.exclude(is_deleted=True)
return queryset

# Override to convert encoded pk to an actual pk
def get_object(self):
import ipdb; ipdb.set_trace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete delete

queryset = self.filter_queryset(self.get_queryset(False))

# Perform the lookup filtering.
Expand Down
18 changes: 18 additions & 0 deletions api/views/sourceConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from rest_framework import viewsets
from api.views import ShareObjectViewSet
from rest_framework import filters
from api.serializers import SourceConfigSerializer
from share.models import SourceConfig
from api.pagination import FuzzyPageNumberPagination
from django.db.models import Count
from django.db.models import Aggregate
from share.models import HarvestLog
from django.db.models import OuterRef, Subquery
from django.db.models import IntegerField

class SourceConfigViewSet(ShareObjectViewSet):
serializer_class = SourceConfigSerializer
pagination_class = FuzzyPageNumberPagination
queryset = SourceConfig.objects.all()


6 changes: 4 additions & 2 deletions api/views/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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 api.serializers import FullNormalizedDataSerializer, BasicNormalizedDataSerializer,RawDatumSerializer, ShareUserSerializer, SourceSerializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space!


from share.models import RawDatum, NormalizedData, Source, SourceConfig, Transformer, ShareUser
from share.tasks import disambiguate
from share.harvest.serialization import DictSerializer
Expand Down Expand Up @@ -56,6 +56,7 @@ class SourceViewSet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
return Source.objects.exclude(icon='').exclude(is_deleted=True)


def create(self, request, *args, **kwargs):
try:
long_title = request.data['long_title']
Expand Down Expand Up @@ -129,6 +130,7 @@ def create(self, request, *args, **kwargs):
)



class NormalizedDataViewSet(viewsets.ModelViewSet):
"""View showing all normalized data in the SHARE Dataset.

Expand Down
1 change: 1 addition & 0 deletions docs/elasticsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down