-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,081 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from django.http.response import JsonResponse | ||
from django.views import View | ||
from django.core.cache import cache | ||
|
||
import django_filters.rest_framework | ||
from rest_framework import filters, generics | ||
|
||
import db.models as db | ||
from api.dashboard import serializers | ||
from api.dashboard.permissions import ReadOnly | ||
from data_quality import quality_data | ||
|
||
|
||
class PublisherFilters(django_filters.rest_framework.FilterSet): | ||
quality__hasGrantProgrammeTitle = django_filters.CharFilter( | ||
method="hasGrantProgrammeTitle_filter", label="hasGrantProgrammeTitle" | ||
) | ||
|
||
def hasGrantProgrammeTitle_filter(self, queryset, name, value): | ||
return queryset.filter(quality__hasGrantProgrammeTitle__iexact=value) | ||
|
||
class Meta: | ||
model = db.Publisher | ||
fields = ["quality__hasGrantProgrammeTitle"] | ||
|
||
|
||
class Publishers(generics.ListAPIView): | ||
serializer_class = serializers.PublishersSerializer | ||
permission_classes = [ReadOnly] | ||
|
||
filter_backends = ( | ||
filters.SearchFilter, | ||
django_filters.rest_framework.DjangoFilterBackend, | ||
filters.OrderingFilter, | ||
) | ||
|
||
filterset_class = PublisherFilters | ||
search_fields = ("^data__name", "^prefix") | ||
ordering_fields = [ | ||
"data__name", | ||
] | ||
|
||
def get_queryset(self): | ||
return db.Publisher.objects.filter(getter_run=db.GetterRun.objects.last()) | ||
|
||
|
||
class Publisher(generics.RetrieveAPIView): | ||
lookup_field = "prefix" | ||
lookup_url_kwarg = "publisher_prefix" | ||
serializer_class = serializers.PublisherSerializer | ||
|
||
def get_queryset(self): | ||
return db.Publisher.objects.filter(getter_run=db.GetterRun.objects.last()) | ||
|
||
|
||
class Sources(generics.ListAPIView): | ||
serializer_class = serializers.SourcesSerializer | ||
# pagination_class = CurrentLatestGrantsPaginator | ||
|
||
def get_queryset(self): | ||
return db.SourceFile.objects.filter(getter_run=db.GetterRun.objects.last()) | ||
|
||
|
||
class Overview(View): | ||
def get(self, *args, **kwargs): | ||
# If we have a cache of this uri then return that. | ||
# All caches are cleared if the dataload happens | ||
full_request_uri = self.request.build_absolute_uri() | ||
|
||
# Don't cache if we have ?nocache in the query | ||
if not self.request.GET.get("nocache"): | ||
ret = cache.get(full_request_uri) | ||
if ret: | ||
return JsonResponse(ret, safe=False) | ||
|
||
mode = "overview_%s" % self.request.GET.get("mode") | ||
|
||
latest = db.Latest.objects.get(series=db.Latest.CURRENT) | ||
source_file_set = latest.sourcefile_set.all() | ||
|
||
ret = quality_data.aggregated_stats(source_file_set, mode) | ||
cache.set(full_request_uri, ret) | ||
|
||
return JsonResponse(ret, safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class ReadOnly(permissions.BasePermission): | ||
""" | ||
Always read-only even if authenticated | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): | ||
# we'll always allow GET, HEAD or OPTIONS requests. | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from rest_framework import serializers | ||
|
||
import db.models as db | ||
|
||
|
||
class SourcesSerializer(serializers.ModelSerializer): | ||
id = serializers.JSONField(source="data.identifier") | ||
datagetter_data = serializers.JSONField() | ||
modified = serializers.JSONField(source="data.modified") | ||
grants = serializers.IntegerField() | ||
distribution = serializers.JSONField(source="get_distribution") | ||
quality = serializers.JSONField() | ||
aggregate = serializers.JSONField() | ||
|
||
class Meta: | ||
model = db.SourceFile | ||
fields = ( | ||
"id", | ||
"datagetter_data", | ||
"grants", | ||
"distribution", | ||
"modified", | ||
"quality", | ||
"aggregate", | ||
) | ||
|
||
|
||
class PublishersSerializer(serializers.ModelSerializer): | ||
name = serializers.JSONField(source="data.name") | ||
logo = serializers.JSONField(source="data.logo") | ||
prefix = serializers.JSONField(source="data.prefix") | ||
website = serializers.JSONField(source="data.website") | ||
aggregate = serializers.JSONField() | ||
quality = serializers.JSONField() | ||
|
||
class Meta: | ||
model = db.Publisher | ||
fields = ( | ||
"name", | ||
"logo", | ||
"prefix", | ||
"website", | ||
"aggregate", | ||
"quality", | ||
) | ||
|
||
|
||
class PublisherSerializer(PublishersSerializer): | ||
|
||
# Same as Publishers but with added `files` | ||
files = SourcesSerializer(source="get_sourcefiles", many=True) | ||
|
||
class Meta: | ||
model = db.Publisher | ||
fields = ( | ||
"name", | ||
"logo", | ||
"prefix", | ||
"website", | ||
"aggregate", | ||
"quality", | ||
"files", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from lib360dataquality.cove.threesixtygiving import ( | ||
USEFULNESS_TEST_CLASS, | ||
common_checks_360, | ||
) | ||
from lib360dataquality.cove.schema import Schema360 | ||
|
||
schema = Schema360() | ||
|
||
|
||
def create(grants): | ||
"""grants: grants json""" | ||
|
||
result = {} | ||
|
||
common_checks_360(result, "/", grants, schema, test_classes=[USEFULNESS_TEST_CLASS]) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AdditionalDataConfig(AppConfig): | ||
name = "data_quality" |
Oops, something went wrong.