From ced39139f02661034aa63eefa79527d7ba7b6179 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Wed, 17 Jul 2024 15:55:55 +0300
Subject: [PATCH] create referee indications formset view

---
 .../submissions/referee_indications.html      | 35 ++++++++++
 .../submissions/submit_indicate_referees.html | 70 +++++++++++++++++++
 scipost_django/submissions/urls/__init__.py   | 12 ++++
 scipost_django/submissions/views/__init__.py  | 51 ++++++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 scipost_django/submissions/templates/submissions/referee_indications.html
 create mode 100644 scipost_django/submissions/templates/submissions/submit_indicate_referees.html

diff --git a/scipost_django/submissions/templates/submissions/referee_indications.html b/scipost_django/submissions/templates/submissions/referee_indications.html
new file mode 100644
index 000000000..379187b88
--- /dev/null
+++ b/scipost_django/submissions/templates/submissions/referee_indications.html
@@ -0,0 +1,35 @@
+{% extends 'submissions/base.html' %}
+
+
+{% block meta_description %}
+  {{ block.super }} Submission Detail {{ submission.title }}
+{% endblock meta_description %}
+
+{% block pagetitle %}
+  Submission: {{ submission.title|truncatechars:40 }}
+{% endblock pagetitle %}
+
+{% block breadcrumb_items %}
+  {{ block.super }}
+  <span class="breadcrumb-item"><a href="{% url 'submissions:submission' submission.preprint.identifier_w_vn_nr %}">{{ submission.preprint.identifier_w_vn_nr }}</a></span>
+  <span class="breadcrumb-item active">Referee Indications</span>
+{% endblock %}
+
+
+{% block content %}
+  <h1>Referee Indications</h1>
+  <p>
+    Referee indications are used to suggest / advise against specific referees for the submission. Indications can be made by the authors of the submission, invited referees, or any other SciPost contributor.
+  </p>
+
+  <h2>Table</h2>
+  <p>Preview of referee indications for this submission visible to you.</p>
+  <div hx-get="{% url "submissions:_hx_referee_indication_table" identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr %}"
+       hx-trigger="load once, referee-indications-updated from:body delay:1s"></div>
+
+  <h2>Indicate Referees</h2>
+  <p>View the refereeing indications you have made for this submission and add new ones.</p>
+  <div hx-get="{% url "submissions:_hx_referee_indication_formset" identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr %}"
+       hx-trigger="load once, referee-indications-updated from:body delay:1s"></div>
+
+{% endblock content %}
diff --git a/scipost_django/submissions/templates/submissions/submit_indicate_referees.html b/scipost_django/submissions/templates/submissions/submit_indicate_referees.html
new file mode 100644
index 000000000..cae1a43d3
--- /dev/null
+++ b/scipost_django/submissions/templates/submissions/submit_indicate_referees.html
@@ -0,0 +1,70 @@
+{% extends 'submissions/base.html' %}
+
+{% load static %}
+{% load bootstrap %}
+{% load journals_extras %}
+{% load automarkup %}
+
+{% block headsup %}
+  <style>{% for journal in journals %}{% if journal.style %}{{ journal.style }}{% endif %}{% endfor %}</style>
+{% endblock headsup %}
+
+{% block pagetitle %}
+  : submit manuscript
+{% endblock pagetitle %}
+
+{% block breadcrumb_items %}
+  {{ block.super }}
+  <span class="breadcrumb-item">Submit a manuscript</span>
+{% endblock %}
+
+{% block content %}
+  <div class="row">
+    <div class="col-12">
+      <h1 class="highlight">Indicate (potential) referees for your manuscript</h1>
+    </div>
+  </div>
+
+  {% if perms.scipost.can_submit_manuscript %}
+    <div class="row">
+      <div class="col-md-6">
+        <h2 class=highlight>Step 5</h2>
+        <h3>Suggest or advise against referees reviewing your manuscript</h3>
+      </div>
+      <div class="col-md-6">{% include 'submissions/submit_steps.html' with step=5 %}</div>
+    </div>
+
+    <div class="row">
+      <div class="col-12">
+
+        <h4>SciPost refereeing system</h4>
+        <p>
+          SciPost relies on a unique refereeing system, where editors are responsible for the selection of manuscripts at a voluntary basis.
+          Therefore, <strong>SciPost does not guarantee that all manuscripts will be picked up for refereeing</strong> by an editor.
+          Most often, editors selecting a manuscript do so on the basis of their expertise, the novelty / interest of the manuscript and the availability of referees.
+        </p>
+        <p>
+          You can help potential editors of your manuscript by suggesting referees that are experts in the field and are not in conflict of interest with the authors.
+          Furthermore, you can also advise against referees that you believe are not suitable for refereeing your manuscript, provided you have a valid reason for this.
+          The referees suggested by the authors are not automatically selected for refereeing, but can serve as a guide for the editors who ultimately decide who to invite for refereeing.
+        </p>
+
+        <h4>Indicate referees</h4>
+        <div hx-get="{% url "submissions:_hx_referee_indication_formset" identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr %}"
+             hx-trigger="load once, referee-indications-updated from:body delay:1s"></div>
+
+      </div>
+    </div>
+
+    <div>
+      <a class="btn btn-link"
+         href="{% url "submissions:submission" identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr %}">View submission page</a>
+    </div>
+
+  {% else %}
+    <h3>You are currently not allowed to submit a manuscript.</h3>
+  {% endif %}
+
+ 
+
+{% endblock content %}
diff --git a/scipost_django/submissions/urls/__init__.py b/scipost_django/submissions/urls/__init__.py
index c09872008..223b9d5d7 100644
--- a/scipost_django/submissions/urls/__init__.py
+++ b/scipost_django/submissions/urls/__init__.py
@@ -75,6 +75,18 @@ urlpatterns = [
                     views.submission_detail,
                     name="submission",
                 ),
+                path(
+                    "referee_indications/",
+                    include(
+                        [
+                            path(
+                                "_hx_formset",
+                                views.HXRefereeIndicationFormSetView.as_view(),
+                                name="_hx_referee_indication_formset",
+                            ),
+                        ]
+                    ),
+                ),
                 # Topics
                 path(
                     "_hx_submission_topics/",
diff --git a/scipost_django/submissions/views/__init__.py b/scipost_django/submissions/views/__init__.py
index ccb80f184..db7b27184 100644
--- a/scipost_django/submissions/views/__init__.py
+++ b/scipost_django/submissions/views/__init__.py
@@ -37,6 +37,7 @@ from django.views.generic.list import ListView
 from dal import autocomplete
 import sentry_sdk
 
+from common.views import HXFormSetView
 from scipost.permissions import (
     HTMXPermissionsDenied,
     HTMXResponse,
@@ -69,6 +70,7 @@ from ..models import (
 from ..mixins import SubmissionMixin, SubmissionAdminViewMixin
 from ..forms import (
     InviteRefereeSearchFrom,
+    RefereeIndicationForm,
     SciPostPrefillForm,
     ArXivPrefillForm,
     ChemRxivPrefillForm,
@@ -3492,3 +3494,52 @@ def monitor(request):
         ),
     }
     return render(request, "submissions/monitor.html", context)
+
+
+class HXRefereeIndicationFormSetView(HXFormSetView):
+    form_class = RefereeIndicationForm
+
+    def formset_valid(self):
+        response = HTMXResponse("Referee indications saved successfully", tag="success")
+        response.headers["HX-Trigger"] = "referee-indications-updated"
+        return response
+
+    def get_factory_kwargs(self):
+
+        #! Improvement: Kind of a hacky way to reuse the same decorator code
+        def save_profile(request, **kwargs):
+            # Create a dummy view that saves the profile kwarg on self
+            setattr(kwargs.pop("self"), "profile", kwargs.pop("profile"))
+
+        resolve_profile(save_profile)(self.request, self=self)
+
+        identifier_w_vn_nr = self.kwargs.get("identifier_w_vn_nr")
+        self.submission = Submission.objects.get(
+            preprint__identifier_w_vn_nr=identifier_w_vn_nr
+        )
+
+        kwargs = super().get_factory_kwargs()
+        kwargs.update({"can_delete": True})
+
+        return kwargs
+
+    def get_formset_kwargs(self):
+        kwargs = super().get_formset_kwargs()
+
+        kwargs.update(
+            {
+                "queryset": RefereeIndication.objects.all()
+                .for_submission(self.submission)
+                .by_profile(self.profile),
+            }
+        )
+
+        return kwargs
+
+    def get_form_kwargs(self):
+        kwargs = super().get_form_kwargs()
+
+        kwargs.update({"submission": self.submission, "profile": self.profile})
+
+        return kwargs
+
-- 
GitLab