From e4b855a4567e3ce67db85c0da706143c202a0ffe Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 30 May 2023 12:00:28 +0200 Subject: [PATCH] differentiate form ids on production page update assignee status on form submission format html structure automatically --- ...hx_productionstream_change_invofficer.html | 29 +++++++++++-------- ...x_productionstream_change_prodofficer.html | 29 +++++++++++-------- .../_hx_productionstream_change_status.html | 26 ++++++++++------- ...hx_productionstream_change_supervisor.html | 29 +++++++++++-------- ..._hx_productionstream_details_contents.html | 2 +- .../production/_hx_productionstream_list.html | 17 +++++++---- ...uctionstream_details_summary_contents.html | 3 +- scipost_django/production/views.py | 20 ++++++++++--- 8 files changed, 97 insertions(+), 58 deletions(-) diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_invofficer.html b/scipost_django/production/templates/production/_hx_productionstream_change_invofficer.html index e97de052f..c8b688db5 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_invofficer.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_invofficer.html @@ -1,15 +1,20 @@ {% load bootstrap %} {% if perms.scipost.can_take_decisions_related_to_proofs and form.fields.invitations_officer.choices|length > 0 %} -<div id="productionstream-update-invitations_officer"> - <form hx-post="{% url 'production:update_invitations_officer' stream.id %}" hx-target="#productionstream-update-invitations_officer" hx-swap="outerHTML" class="row"> - {% csrf_token %} - <div class="col"> - {{form|bootstrap_purely_inline}} - </div> - <div class="col-auto h-100" hx-post="{% url 'production:render_action_buttons' stream.id 'invitations_officer' %}" hx-swap="innerHTML" class="col-auto" hx-trigger="change from:select#id_invitations_officer" hx-target="this"> - </div> - <div class="text-primary">{{message}}</div> - </form> -</div> -{% endif %} \ No newline at end of file + <div id="productionstream-update-invitations_officer"> + <form hx-post="{% url 'production:update_invitations_officer' stream.id %}" + hx-target="#productionstream-update-invitations_officer" + hx-swap="outerHTML" + class="row"> + {% csrf_token %} + <div class="col">{{ form|bootstrap_purely_inline }}</div> + <div class="col-auto h-100" + hx-post="{% url 'production:render_action_buttons' stream.id 'invitations_officer' %}" + hx-swap="innerHTML" + class="col-auto" + hx-trigger="change from:select#productionstream_{{ stream.id }}_id_invitations_officer" + hx-target="this"></div> + <div class="text-primary">{{ message }}</div> + </form> + </div> +{% endif %} diff --git a/scipost_django/production/templates/production/_hx_productionstream_change_prodofficer.html b/scipost_django/production/templates/production/_hx_productionstream_change_prodofficer.html index ea1d130cf..dbb665741 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_prodofficer.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_prodofficer.html @@ -1,15 +1,20 @@ {% load bootstrap %} {% if perms.scipost.can_take_decisions_related_to_proofs and form.fields.officer.choices|length > 0 %} -<div id="productionstream-update-officer"> - <form hx-post="{% url 'production:update_officer' stream.id %}" hx-target="#productionstream-update-officer" hx-swap="outerHTML" class="row"> - {% csrf_token %} - <div class="col"> - {{form|bootstrap_purely_inline}} - </div> - <div class="col-auto h-100" hx-post="{% url 'production:render_action_buttons' stream.id 'officer' %}" hx-swap="innerHTML" class="col-auto" hx-trigger="change from:select#id_officer" hx-target="this"> - </div> - <div class="text-primary">{{message}}</div> - </form> -</div> -{% endif %} \ No newline at end of file + <div id="productionstream-update-officer"> + <form hx-post="{% url 'production:update_officer' stream.id %}" + hx-target="#productionstream-update-officer" + hx-swap="outerHTML" + class="row"> + {% csrf_token %} + <div class="col">{{ form|bootstrap_purely_inline }}</div> + <div class="col-auto h-100" + hx-post="{% url 'production:render_action_buttons' stream.id 'officer' %}" + hx-swap="innerHTML" + class="col-auto" + hx-trigger="change from:select#productionstream_{{ stream.id }}_id_officer" + hx-target="this"></div> + <div class="text-primary">{{ message }}</div> + </form> + </div> +{% endif %} 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 4458c29f0..20e51ec58 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_status.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_status.html @@ -1,15 +1,21 @@ {% load bootstrap %} {% if perms.scipost.can_take_decisions_related_to_proofs and form.fields.status.choices|length > 0 %} -<div id="productionstream-update-status"> - <form hx-post="{% url 'production:update_status' stream.id %}" hx-target="#productionstream-update-status" hx-swap="outerHTML" class="row"> + + <form id="productionstream-update-status" + hx-post="{% url 'production:update_status' stream.id %}" + hx-target="this" + hx-swap="outerHTML" + class="row"> {% csrf_token %} - <div class="col"> - {{form|bootstrap_purely_inline}} - </div> - <div class="col-auto h-100" hx-post="{% url 'production:render_action_buttons' stream.id 'status' %}" hx-swap="innerHTML" class="col-auto" hx-trigger="load, change from:select#id_status" hx-target="this"> - </div> - <div class="text-primary">{{message}}</div> + <div class="col">{{ form|bootstrap_purely_inline }}</div> + <div class="col-auto h-100" + hx-post="{% url 'production:render_action_buttons' stream.id 'status' %}" + hx-swap="innerHTML" + class="col-auto" + hx-trigger="load, change from:select#productionstream_{{ stream.id }}_id_status" + hx-target="this"></div> + <div class="text-primary">{{ message }}</div> </form> -</div> -{% endif %} \ No newline at end of file + +{% endif %} 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 91a9c8cb3..bd472b676 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html @@ -1,15 +1,20 @@ {% load bootstrap %} {% if perms.scipost.can_take_decisions_related_to_proofs and form.fields.supervisor.choices|length > 0 %} -<div id="productionstream-update-supervisor"> - <form hx-post="{% url 'production:update_supervisor' stream.id %}" hx-target="#productionstream-update-supervisor" hx-swap="outerHTML" class="row"> - {% csrf_token %} - <div class="col"> - {{form|bootstrap_purely_inline}} - </div> - <div class="col-auto h-100" hx-post="{% url 'production:render_action_buttons' stream.id 'supervisor' %}" hx-swap="innerHTML" class="col-auto" hx-trigger="load, change from:select#id_supervisor" hx-target="this"> - </div> - <div class="text-primary">{{message}}</div> - </form> -</div> -{% endif %} \ No newline at end of file + <div id="productionstream-update-supervisor"> + <form hx-post="{% url 'production:update_supervisor' stream.id %}" + hx-target="#productionstream-update-supervisor" + hx-swap="outerHTML" + class="row"> + {% csrf_token %} + <div class="col">{{ form|bootstrap_purely_inline }}</div> + <div class="col-auto h-100" + hx-post="{% url 'production:render_action_buttons' stream.id 'supervisor' %}" + hx-swap="innerHTML" + class="col-auto" + hx-trigger="load, change from:select#productionstream_{{ stream.id }}_id_supervisor" + hx-target="this"></div> + <div class="text-primary">{{ message }}</div> + </form> + </div> +{% endif %} 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 4000c331b..a78693b5d 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html +++ b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html @@ -7,7 +7,7 @@ </p> <div class="row overflow-hidden" style="height: min(50vh, 40em)"> - <div class="col-lg-6"> + <div class="col-lg-6 h-100 overflow-scroll"> <h3>Actions</h3> {% if "can_perform_supervisory_actions" in sub_perms %} <div class="container"> diff --git a/scipost_django/production/templates/production/_hx_productionstream_list.html b/scipost_django/production/templates/production/_hx_productionstream_list.html index 4496009ec..daa14a268 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_list.html +++ b/scipost_django/production/templates/production/_hx_productionstream_list.html @@ -1,5 +1,7 @@ {% for productionstream in page_obj %} - <div class="ms-3 mt-3"><strong>{{ forloop.counter0|add:start_index }} of {{ count }}</strong></div> + <div class="ms-3 mt-3"> + <strong>{{ forloop.counter0|add:start_index }} of {{ count }}</strong> + </div> {% include 'production/_hx_productionstream_details.html' with productionstream=productionstream %} {% empty %} <strong>No Production Stream could be found</strong> @@ -9,12 +11,15 @@ hx-include="#search-productionstreams-form" hx-trigger="revealed" hx-swap="afterend" - hx-indicator="#indicator-search-page-{{ page_obj.number }}" - > - <div id="indicator-search-page-{{ page_obj.number }}" class="htmx-indicator p-2"> + hx-indicator="#indicator-search-page-{{ page_obj.number }}"> + <div id="indicator-search-page-{{ page_obj.number }}" + class="htmx-indicator p-2"> <button class="btn btn-warning" type="button" disabled> - <strong>Loading page {{ page_obj.next_page_number }} out of {{ page_obj.paginator.num_pages }}</strong> - <div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div> + <strong>Loading page {{ page_obj.next_page_number }} out of {{ page_obj.paginator.num_pages }}</strong> + + <div class="spinner-grow spinner-grow-sm ms-2" + role="status" + aria-hidden="true"></div> </button> </div> </div> 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 28f77eae8..f9152db56 100644 --- a/scipost_django/production/templates/production/_productionstream_details_summary_contents.html +++ b/scipost_django/production/templates/production/_productionstream_details_summary_contents.html @@ -50,5 +50,6 @@ <div id="productionstream-{{ productionstream.id }}-summary-assignees" class="col col-md-4 border-start" hx-get="{% url 'production:render_stream_assignees_status' productionstream.id %}" - hx-trigger="load"></div> + hx-trigger="load, submit from:#productionstream-{{ productionstream.id }}-details target:form delay:500"> + </div> </div> diff --git a/scipost_django/production/views.py b/scipost_django/production/views.py index b96f06fe7..757254ebd 100644 --- a/scipost_django/production/views.py +++ b/scipost_django/production/views.py @@ -87,16 +87,21 @@ def _hx_productionstream_list(request): def _hx_productionstream_details_contents(request, productionstream_id): productionstream = get_object_or_404(ProductionStream, pk=productionstream_id) status_form = StreamStatusForm( - instance=productionstream, production_user=request.user.production_user + instance=productionstream, + production_user=request.user.production_user, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) supervisor_form = AssignSupervisorForm( instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) inv_officer_form = AssignInvitationsOfficerForm( instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) prod_officer_form = AssignOfficerForm( instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) context = { @@ -361,6 +366,7 @@ def update_status(request, stream_id): request.POST or None, instance=productionstream, production_user=request.user.production_user, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) if status_form.is_valid(): @@ -460,7 +466,9 @@ def update_officer(request, stream_id): } else: prod_officer_form = AssignOfficerForm( - request.POST or None, instance=productionstream + request.POST or None, + instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) if prod_officer_form.is_valid(): prod_officer_form.save() @@ -601,7 +609,9 @@ def update_invitations_officer(request, stream_id): } else: inv_officer_form = AssignInvitationsOfficerForm( - request.POST or None, instance=productionstream + request.POST or None, + instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) if inv_officer_form.is_valid(): inv_officer_form.save() @@ -731,7 +741,9 @@ def update_supervisor(request, stream_id): ProductionStream.objects.ongoing(), pk=stream_id ) supervisor_form = AssignSupervisorForm( - request.POST or None, instance=productionstream + request.POST or None, + instance=productionstream, + auto_id=f"productionstream_{productionstream.id}_id_%s", ) prev_supervisor = productionstream.supervisor -- GitLab