diff --git a/swh/web/add_forge_now/views.py b/swh/web/add_forge_now/views.py index 1d9a2f07..eb18ae6d 100644 --- a/swh/web/add_forge_now/views.py +++ b/swh/web/add_forge_now/views.py @@ -1,127 +1,125 @@ # Copyright (C) 2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information from typing import Any, Dict, List from django.conf.urls import url from django.core.paginator import Paginator from django.db.models import Q from django.http.request import HttpRequest from django.http.response import HttpResponse, JsonResponse from django.shortcuts import render from swh.web.add_forge_now.models import Request as AddForgeRequest from swh.web.api.views.add_forge_now import ( AddForgeNowRequestPublicSerializer, AddForgeNowRequestSerializer, ) from swh.web.common.utils import has_add_forge_now_permission def add_forge_request_list_datatables(request: HttpRequest) -> HttpResponse: """Dedicated endpoint used by datatables to display the add-forge requests in the Web UI. """ draw = int(request.GET.get("draw", 0)) add_forge_requests = AddForgeRequest.objects.all() table_data: Dict[str, Any] = { "recordsTotal": add_forge_requests.count(), "draw": draw, } search_value = request.GET.get("search[value]") column_order = request.GET.get("order[0][column]") field_order = request.GET.get(f"columns[{column_order}][name]", "id") order_dir = request.GET.get("order[0][dir]", "desc") if field_order: if order_dir == "desc": field_order = "-" + field_order add_forge_requests = add_forge_requests.order_by(field_order) per_page = int(request.GET.get("length", 10)) page_num = int(request.GET.get("start", 0)) // per_page + 1 if search_value: add_forge_requests = add_forge_requests.filter( Q(forge_type__icontains=search_value) | Q(forge_url__icontains=search_value) | Q(status__icontains=search_value) ) if ( int(request.GET.get("user_requests_only", "0")) and request.user.is_authenticated ): add_forge_requests = add_forge_requests.filter( submitter_name=request.user.username ) paginator = Paginator(add_forge_requests, per_page) page = paginator.page(page_num) if has_add_forge_now_permission(request.user): requests = AddForgeNowRequestSerializer(page.object_list, many=True).data else: requests = AddForgeNowRequestPublicSerializer(page.object_list, many=True).data results = [dict(request) for request in requests] table_data["recordsFiltered"] = add_forge_requests.count() table_data["data"] = results return JsonResponse(table_data) FORGE_TYPES: List[str] = [ "bitbucket", "cgit", "gitlab", "gitea", "heptapod", ] def create_request_create(request): """View to create a new 'add_forge_now' request. """ return render( - request, - "add_forge_now/create-request-create.html", - {"forge_types": FORGE_TYPES}, + request, "add_forge_now/creation_form.html", {"forge_types": FORGE_TYPES}, ) def create_request_list(request): """View to list existing 'add_forge_now' requests. """ - return render(request, "add_forge_now/create-request-list.html",) + return render(request, "add_forge_now/list.html",) def create_request_help(request): """View to explain 'add_forge_now'. """ - return render(request, "add_forge_now/create-request-help.html",) + return render(request, "add_forge_now/help.html",) urlpatterns = [ url( r"^add-forge/request/list/datatables/$", add_forge_request_list_datatables, name="add-forge-request-list-datatables", ), url(r"^add-forge/request/create/$", create_request_create, name="forge-add-create"), url(r"^add-forge/request/list/$", create_request_list, name="forge-add-list"), url(r"^add-forge/request/help/$", create_request_help, name="forge-add-help"), ] diff --git a/swh/web/templates/add_forge_now/create-request.html b/swh/web/templates/add_forge_now/common.html similarity index 100% rename from swh/web/templates/add_forge_now/create-request.html rename to swh/web/templates/add_forge_now/common.html diff --git a/swh/web/templates/add_forge_now/create-request-create.html b/swh/web/templates/add_forge_now/creation_form.html similarity index 99% rename from swh/web/templates/add_forge_now/create-request-create.html rename to swh/web/templates/add_forge_now/creation_form.html index 661b81b5..f4e152e2 100644 --- a/swh/web/templates/add_forge_now/create-request-create.html +++ b/swh/web/templates/add_forge_now/creation_form.html @@ -1,116 +1,116 @@ -{% extends "./create-request.html" %} +{% extends "./common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} {% block tab_content %}
{% if not user.is_authenticated %}

You must be logged in to submit an add forge request. Please log in

{% else %}
{% csrf_token %}
Supported forge types in software archive.
Remote URL of the forge.
Name of the forge administrator.
Email of the forge administrator. The given email address will not be used for any purpose outside the “add forge now” process.
Optionally, leave a comment to the moderator regarding your request.

Once an add-forge-request is submitted, its status can be viewed in the submitted requests list. This process involves a moderator approval and might take a few days to handle (it primarily depends on the response time from the forge).

{% endif %}
{% endblock %} diff --git a/swh/web/templates/add_forge_now/create-request-help.html b/swh/web/templates/add_forge_now/help.html similarity index 98% rename from swh/web/templates/add_forge_now/create-request-help.html rename to swh/web/templates/add_forge_now/help.html index 82550f0c..75ec00f1 100644 --- a/swh/web/templates/add_forge_now/create-request-help.html +++ b/swh/web/templates/add_forge_now/help.html @@ -1,89 +1,89 @@ -{% extends "./create-request.html" %} +{% extends "./common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} {% block tab_content %}

For submitting an "Add forge now" request", you have to provide the following details:

Once submitted, your "add forge" request can be in one of the following states

{% endblock %} diff --git a/swh/web/templates/add_forge_now/create-request-list.html b/swh/web/templates/add_forge_now/list.html similarity index 95% rename from swh/web/templates/add_forge_now/create-request-list.html rename to swh/web/templates/add_forge_now/list.html index 142fa523..3b40653e 100644 --- a/swh/web/templates/add_forge_now/create-request-list.html +++ b/swh/web/templates/add_forge_now/list.html @@ -1,24 +1,24 @@ -{% extends "./create-request.html" %} +{% extends "./common.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} {% block tab_content %}
Submission date Forge type Forge URL Status
{% endblock %}