Changeset View
Changeset View
Standalone View
Standalone View
swh/web/misc/coverage.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import json | |||||
from django.conf.urls import url | from django.conf.urls import url | ||||
from django.core.cache import caches | from django.core.cache import caches | ||||
from django.http import HttpResponse | from django.http import JsonResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.views.decorators.cache import never_cache | from django.views.decorators.cache import never_cache | ||||
from django.views.decorators.clickjacking import xframe_options_exempt | from django.views.decorators.clickjacking import xframe_options_exempt | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.exc import handle_view_exception | from swh.web.common.exc import handle_view_exception | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | try: | ||||
origin_count = cache.get(prev_cache_key, -1) | origin_count = cache.get(prev_cache_key, -1) | ||||
results.append( | results.append( | ||||
{ | { | ||||
"provider_id": provider_id, | "provider_id": provider_id, | ||||
"origin_count": origin_count, | "origin_count": origin_count, | ||||
"origin_types": code_provider["origin_types"], | "origin_types": code_provider["origin_types"], | ||||
} | } | ||||
) | ) | ||||
results = json.dumps(results) | |||||
except Exception as exc: | except Exception as exc: | ||||
return handle_view_exception(request, exc, html_response=False) | return handle_view_exception(request, exc, html_response=False) | ||||
return HttpResponse(results, content_type="application/json") | return JsonResponse(results) | ||||
urlpatterns = [ | urlpatterns = [ | ||||
url(r"^coverage/$", _swh_coverage, name="swh-coverage"), | url(r"^coverage/$", _swh_coverage, name="swh-coverage"), | ||||
url(r"^coverage/count/$", _swh_coverage_count, name="swh-coverage-count"), | url(r"^coverage/count/$", _swh_coverage_count, name="swh-coverage-count"), | ||||
] | ] |