Changeset View
Changeset View
Standalone View
Standalone View
swh/web/misc/origin_save.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2021 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 | ||||
from django.conf.urls import url | from django.conf.urls import url | ||||
from django.core.paginator import Paginator | from django.core.paginator import Paginator | ||||
from django.db.models import Q | from django.db.models import Q | ||||
from django.http import JsonResponse | from django.http import JsonResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from rest_framework.decorators import api_view, authentication_classes | from rest_framework.decorators import api_view, authentication_classes | ||||
from swh.web.api.throttling import throttle_scope | from swh.web.api.throttling import throttle_scope | ||||
from swh.web.common.exc import ForbiddenExc | from swh.web.common.exc import ForbiddenExc | ||||
from swh.web.common.models import SaveOriginRequest | from swh.web.common.models import SaveOriginRequest | ||||
from swh.web.common.origin_save import ( | from swh.web.common.origin_save import ( | ||||
create_save_origin_request, | create_save_origin_request, | ||||
get_savable_visit_types, | get_savable_visit_types, | ||||
get_save_origin_requests_from_queryset, | |||||
get_save_origin_task_info, | get_save_origin_task_info, | ||||
to_save_request_info, | |||||
) | ) | ||||
from swh.web.common.utils import EnforceCSRFAuthentication | from swh.web.common.utils import EnforceCSRFAuthentication | ||||
def _origin_save_view(request): | def _origin_save_view(request): | ||||
return render( | return render( | ||||
request, | request, | ||||
"misc/origin-save.html", | "misc/origin-save.html", | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if search_value: | ||||
Q(status__icontains=search_value) | Q(status__icontains=search_value) | ||||
| Q(loading_task_status__icontains=search_value) | | Q(loading_task_status__icontains=search_value) | ||||
| Q(visit_type__icontains=search_value) | | Q(visit_type__icontains=search_value) | ||||
| Q(origin_url__icontains=search_value) | | Q(origin_url__icontains=search_value) | ||||
) | ) | ||||
table_data["recordsFiltered"] = save_requests.count() | table_data["recordsFiltered"] = save_requests.count() | ||||
paginator = Paginator(save_requests, length) | paginator = Paginator(save_requests, length) | ||||
table_data["data"] = get_save_origin_requests_from_queryset( | table_data["data"] = [ | ||||
paginator.page(page).object_list | to_save_request_info(sor) for sor in paginator.page(page).object_list | ||||
) | ] | ||||
return JsonResponse(table_data) | return JsonResponse(table_data) | ||||
def _save_origin_task_info(request, save_request_id): | def _save_origin_task_info(request, save_request_id): | ||||
request_info = get_save_origin_task_info( | request_info = get_save_origin_task_info( | ||||
save_request_id, full_info=request.user.is_staff | save_request_id, full_info=request.user.is_staff | ||||
) | ) | ||||
for date_field in ("scheduled", "started", "ended"): | for date_field in ("scheduled", "started", "ended"): | ||||
Show All 24 Lines |