From 7a086a8fb9d4553f354397d86e7037600a11a0fa Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Fri, 23 Feb 2024 16:41:38 +0100
Subject: [PATCH] add button to quickly add referee emails

fix #25
---
 .../_hx_select_referee_table_row.html         |  6 +++
 scipost_django/submissions/urls/__init__.py   |  5 +++
 scipost_django/submissions/views/__init__.py  | 39 ++++++++++++++++++-
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/scipost_django/submissions/templates/submissions/_hx_select_referee_table_row.html b/scipost_django/submissions/templates/submissions/_hx_select_referee_table_row.html
index 50012d20f..2b4731f2f 100644
--- a/scipost_django/submissions/templates/submissions/_hx_select_referee_table_row.html
+++ b/scipost_django/submissions/templates/submissions/_hx_select_referee_table_row.html
@@ -57,6 +57,12 @@
               hx-get="{% url 'submissions:_hx_configure_refereeing_invitation' identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr profile_id=profile.id %}"
               hx-target="closest tr"
               hx-swap="afterend">Select</button>
+      <button id="ref-inv-{{ profile.id }}-send-btn"
+              type="button"
+              class="btn btn-sm btn-light"
+              hx-get="{% url 'submissions:_hx_add_referee_profile_email' profile_id=profile.id %}"
+              hx-target="closest tr"
+              hx-swap="afterend">Add Email</button>
     {% endif %}
 
   </td>
diff --git a/scipost_django/submissions/urls/__init__.py b/scipost_django/submissions/urls/__init__.py
index 136c934d1..41a68e189 100644
--- a/scipost_django/submissions/urls/__init__.py
+++ b/scipost_django/submissions/urls/__init__.py
@@ -328,6 +328,11 @@ urlpatterns = [
         views._hx_configure_refereeing_invitation,
         name="_hx_configure_refereeing_invitation",
     ),
+    path(
+        "refereeing/_hx_add_referee_profile_email/<int:profile_id>",
+        views._hx_add_referee_profile_email,
+        name="_hx_add_referee_profile_email",
+    ),
     path(
         "set_refinv_auto_reminder/<int:invitation_id>/<int:auto_reminders>",
         views.set_refinv_auto_reminder,
diff --git a/scipost_django/submissions/views/__init__.py b/scipost_django/submissions/views/__init__.py
index 879604db3..5524a2b83 100644
--- a/scipost_django/submissions/views/__init__.py
+++ b/scipost_django/submissions/views/__init__.py
@@ -117,7 +117,7 @@ from preprints.models import Preprint
 from production.forms import ProofsDecisionForm
 from production.utils import get_or_create_production_stream
 from profiles.models import Profile, ProfileEmail
-from profiles.forms import SimpleProfileForm
+from profiles.forms import AddProfileEmailForm, SimpleProfileForm
 from scipost.constants import TITLE_DR, INVITATION_REFEREEING
 from scipost.decorators import is_contributor_user
 from scipost.forms import RemarkForm, SearchTextForm
@@ -1262,6 +1262,43 @@ def _hx_configure_refereeing_invitation(request, identifier_w_vn_nr, profile_id)
     )
 
 
+@permission_required_htmx("scipost.can_add_profile_emails")
+def _hx_add_referee_profile_email(request, profile_id):
+    """
+    Add an email address to a Profile from the select referee page.
+    """
+    profile = get_object_or_404(Profile, pk=profile_id)
+
+    form = AddProfileEmailForm(
+        request.POST or None,
+        profile=profile,
+        request=request,
+        hx_attrs={
+            "hx-post": reverse(
+                "submissions:_hx_add_referee_profile_email",
+                kwargs={"profile_id": profile.id},
+            ),
+            "hx-target": "previous tbody",
+            "hx-swap": "beforeend",
+        },
+        cancel_parent_tag="tr",
+    )
+
+    if form.is_valid():
+        profile_email = form.save()
+        response = TemplateResponse(
+            request,
+            "submissions/_hx_select_referee_email_table_row.html",
+            {"profile_email": profile_email},
+        )
+
+        return response
+
+    return render(
+        request, "submissions/_hx_configure_refereeing_invitation.html", {"form": form}
+    )
+
+
 @login_required
 @fellowship_or_admin_required()
 @transaction.atomic
-- 
GitLab