From 18198e8dcebe998aa5304ecf30b9a27878dfd9b6 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Sat, 24 Jun 2023 00:25:59 +0200
Subject: [PATCH] prefix htmx refactored views with  _hx_ change prod user
 assignment forms to filter groups

---
 scipost_django/production/forms.py            | 16 +++++++++-
 ...tionstream_change_invitations_officer.html |  2 +-
 .../_hx_productionstream_change_officer.html  |  2 +-
 .../_hx_productionstream_change_status.html   |  2 +-
 ...hx_productionstream_change_supervisor.html |  2 +-
 ..._hx_productionstream_details_contents.html |  2 +-
 ...uctionstream_details_summary_contents.html |  2 +-
 scipost_django/production/urls.py             | 30 +++++++++----------
 scipost_django/production/views.py            | 12 ++++----
 9 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/scipost_django/production/forms.py b/scipost_django/production/forms.py
index 979c19f2b..44af1bec6 100644
--- a/scipost_django/production/forms.py
+++ b/scipost_django/production/forms.py
@@ -82,12 +82,26 @@ class AssignOfficerForm(forms.ModelForm):
             stream.save()
         return stream
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.fields["officer"].queryset = ProductionUser.objects.active().filter(
+            user__groups__name="Production Officers"
+        )
+
 
 class AssignInvitationsOfficerForm(forms.ModelForm):
     class Meta:
         model = ProductionStream
         fields = ("invitations_officer",)
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.fields[
+            "invitations_officer"
+        ].queryset = ProductionUser.objects.active().filter(
+            user__groups__name="Production Officers"
+        )
+
 
 class AssignSupervisorForm(forms.ModelForm):
     class Meta:
@@ -96,7 +110,7 @@ class AssignSupervisorForm(forms.ModelForm):
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
-        self.fields["supervisor"].queryset = self.fields["supervisor"].queryset.filter(
+        self.fields["supervisor"].queryset = ProductionUser.objects.active().filter(
             user__groups__name="Production Supervisor"
         )
 
diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_invitations_officer.html b/scipost_django/production/templates/production/_hx_productionstream_change_invitations_officer.html
index f4c7284ff..ac9e3efc8 100644
--- a/scipost_django/production/templates/production/_hx_productionstream_change_invitations_officer.html
+++ b/scipost_django/production/templates/production/_hx_productionstream_change_invitations_officer.html
@@ -9,7 +9,7 @@
             {% csrf_token %}
             <div class="col">{{ form|bootstrap_purely_inline }}</div>
             <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"
-                 hx-post="{% url 'production:render_action_buttons' stream.id 'invitations_officer' %}"
+                 hx-post="{% url 'production:_hx_productionstream_change_action_buttons' stream.id 'invitations_officer' %}"
                  hx-swap="innerHTML"
                  hx-trigger="change from:select#productionstream_{{ stream.id }}_id_invitations_officer"
                  hx-target="this"></div>
diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_officer.html b/scipost_django/production/templates/production/_hx_productionstream_change_officer.html
index 8a1c7d8df..2efbd7f2e 100644
--- a/scipost_django/production/templates/production/_hx_productionstream_change_officer.html
+++ b/scipost_django/production/templates/production/_hx_productionstream_change_officer.html
@@ -9,7 +9,7 @@
             {% csrf_token %}
             <div class="col">{{ form|bootstrap_purely_inline }}</div>
             <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"
-                 hx-post="{% url 'production:render_action_buttons' stream.id 'officer' %}"
+                 hx-post="{% url 'production:_hx_productionstream_change_action_buttons' stream.id 'officer' %}"
                  hx-swap="innerHTML"
                  hx-trigger="change from:select#productionstream_{{ stream.id }}_id_officer"
                  hx-target="this"></div>
diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_status.html b/scipost_django/production/templates/production/_hx_productionstream_change_status.html
index 59fd5c29d..874111480 100644
--- a/scipost_django/production/templates/production/_hx_productionstream_change_status.html
+++ b/scipost_django/production/templates/production/_hx_productionstream_change_status.html
@@ -11,7 +11,7 @@
         <div class="row">
             <div class="col">{{ form|bootstrap_purely_inline }}</div>
             <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"
-                 hx-post="{% url 'production:render_action_buttons' stream.id 'status' %}"
+                 hx-post="{% url 'production:_hx_productionstream_change_action_buttons' stream.id 'status' %}"
                  hx-swap="innerHTML"
                  hx-trigger="load, change from:select#productionstream_{{ stream.id }}_id_status"
                  hx-target="this"></div>
diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html b/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html
index aa86793c1..4ce3afd86 100644
--- a/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html
+++ b/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html
@@ -9,7 +9,7 @@
             {% csrf_token %}
             <div class="col">{{ form|bootstrap_purely_inline }}</div>
             <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"
-                 hx-post="{% url 'production:render_action_buttons' stream.id 'supervisor' %}"
+                 hx-post="{% url 'production:_hx_productionstream_change_action_buttons' stream.id 'supervisor' %}"
                  hx-swap="innerHTML"
                  hx-trigger="load, change from:select#productionstream_{{ stream.id }}_id_supervisor"
                  hx-target="this"></div>
diff --git a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html
index 5b98feb1d..2fdf85f4f 100644
--- a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html
+++ b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html
@@ -208,7 +208,7 @@
     <div id="productionstream-{{ productionstream.id }}-event-list"
          class="overflow-scroll mb-4"
          style="max-height: max(50vh, 40em)"
-         hx-get="{% url 'production:render_stream_events' productionstream.id %}"
+         hx-get="{% url 'production:_hx_event_list' productionstream.id %}"
          hx-trigger="intersect once, submit from:#productionstream-{{ productionstream.id }}-details target:form delay:500,  click from:#productionstream-{{ productionstream.id }}-details target:.proof-action-button delay:500">
 
       {% comment %} Placeholder before HTMX content loads {% endcomment %}
diff --git a/scipost_django/production/templates/production/_productionstream_details_summary_contents.html b/scipost_django/production/templates/production/_productionstream_details_summary_contents.html
index 402f43922..6fb15371a 100644
--- a/scipost_django/production/templates/production/_productionstream_details_summary_contents.html
+++ b/scipost_django/production/templates/production/_productionstream_details_summary_contents.html
@@ -93,7 +93,7 @@
 
     <div id="productionstream-{{ productionstream.id }}-summary-assignees"
          class="col-md-6"
-         hx-get="{% url 'production:render_stream_assignees_status' productionstream.id %}"
+         hx-get="{% url 'production:_hx_productionstream_summary_assignees_status' productionstream.id %}"
          hx-trigger="intersect once, submit from:#productionstream-{{ productionstream.id }}-details target:form delay:500, click from:#productionstream-{{ productionstream.id }}-details target:.proof-action-button delay:500, submit from:#productionstreams-filter-details target:#productionstreams-bulk-action-form delay:500">
 
         {% comment %} Placeholder while HTMX is loading {% endcomment %}
diff --git a/scipost_django/production/urls.py b/scipost_django/production/urls.py
index 23963b08e..81e04bc2e 100644
--- a/scipost_django/production/urls.py
+++ b/scipost_django/production/urls.py
@@ -71,6 +71,16 @@ urlpatterns = [
                     production_views._hx_productionstream_actions_work_log,
                     name="_hx_productionstream_actions_work_log",
                 ),
+                path(
+                    "_hx_productionstream_change_action_buttons/<str:key>",
+                    production_views._hx_productionstream_change_action_buttons,
+                    name="_hx_productionstream_change_action_buttons",
+                ),
+                path(
+                    "_hx_productionstream_summary_assignees_status",
+                    production_views._hx_productionstream_summary_assignees_status,
+                    name="_hx_productionstream_summary_assignees_status",
+                ),
                 path(
                     "events/",
                     include(
@@ -80,6 +90,11 @@ urlpatterns = [
                                 production_views._hx_event_form,
                                 name="_hx_event_form",
                             ),
+                            path(
+                                "list",
+                                production_views._hx_event_list,
+                                name="_hx_event_list",
+                            ),
                             path(
                                 "<int:event_id>/",
                                 include(
@@ -249,21 +264,6 @@ urlpatterns = [
                     production_views.mark_as_completed,
                     name="mark_as_completed",
                 ),
-                path(
-                    "render_action_buttons/<str:key>",
-                    production_views.render_action_buttons,
-                    name="render_action_buttons",
-                ),
-                path(
-                    "render_stream_assignees_status",
-                    production_views.render_stream_assignees_status,
-                    name="render_stream_assignees_status",
-                ),
-                path(
-                    "render_stream_events",
-                    production_views.render_stream_events,
-                    name="render_stream_events",
-                ),
             ]
         ),
     ),
diff --git a/scipost_django/production/views.py b/scipost_django/production/views.py
index bbb973b9a..679b57708 100644
--- a/scipost_django/production/views.py
+++ b/scipost_django/production/views.py
@@ -1443,8 +1443,8 @@ def _hx_send_proofs(request, stream_id, version):
         )
 
 
-def render_action_buttons(request, stream_id, key):
-    productionstream = get_object_or_404(ProductionStream, pk=stream_id)
+def _hx_productionstream_change_action_buttons(request, productionstream_id, key):
+    productionstream = get_object_or_404(ProductionStream, pk=productionstream_id)
 
     # Get either the id, or the id of the object and convert it to a string
     # If this fails, set to "None"
@@ -1467,8 +1467,8 @@ def render_action_buttons(request, stream_id, key):
     )
 
 
-def render_stream_assignees_status(request, stream_id):
-    productionstream = get_object_or_404(ProductionStream, pk=stream_id)
+def _hx_productionstream_summary_assignees_status(request, productionstream_id):
+    productionstream = get_object_or_404(ProductionStream, pk=productionstream_id)
 
     context = {
         "productionstream": productionstream,
@@ -1481,8 +1481,8 @@ def render_stream_assignees_status(request, stream_id):
     )
 
 
-def render_stream_events(request, stream_id):
-    productionstream = get_object_or_404(ProductionStream, pk=stream_id)
+def _hx_event_list(request, productionstream_id):
+    productionstream = get_object_or_404(ProductionStream, pk=productionstream_id)
 
     context = {
         "productionstream": productionstream,
-- 
GitLab