From 7f04768c19127e71851541d94abbef60137952e8 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 29 Aug 2023 18:27:22 +0200 Subject: [PATCH] add on hold attribute to prod streams --- .../0009_productionstream_on_hold.py | 18 +++++++ scipost_django/production/models.py | 4 +- ..._hx_productionstream_details_contents.html | 32 ++++++++----- ...uctionstream_summary_assignees_status.html | 17 +++++-- scipost_django/production/urls.py | 5 ++ scipost_django/production/views.py | 47 +++++++++++++++++++ 6 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 scipost_django/production/migrations/0009_productionstream_on_hold.py diff --git a/scipost_django/production/migrations/0009_productionstream_on_hold.py b/scipost_django/production/migrations/0009_productionstream_on_hold.py new file mode 100644 index 000000000..98f305700 --- /dev/null +++ b/scipost_django/production/migrations/0009_productionstream_on_hold.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.18 on 2023-08-29 13:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('production', '0008_alter_productionstream_status'), + ] + + operations = [ + migrations.AddField( + model_name='productionstream', + name='on_hold', + field=models.BooleanField(default=False), + ), + ] diff --git a/scipost_django/production/models.py b/scipost_django/production/models.py index 2f36ed8cd..983954692 100644 --- a/scipost_django/production/models.py +++ b/scipost_django/production/models.py @@ -101,6 +101,8 @@ class ProductionStream(models.Model): related_name="invitations_officer_streams", ) + on_hold = models.BooleanField(default=False) + work_logs = GenericRelation(WorkLog, related_query_name="streams") objects = ProductionStreamQuerySet.as_manager() @@ -131,7 +133,7 @@ class ProductionStream(models.Model): @cached_property def in_stasis(self): - return ( + return self.on_hold or ( self.submission.editorial_decision.status == EditorialDecision.AWAITING_PUBOFFER_ACCEPTANCE ) 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 63294a87c..b6a627a66 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html +++ b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html @@ -167,23 +167,21 @@ </div> - {% if perms.scipost.can_draft_publication or perms.scipost.can_publish_accepted_submission %} <div class="mb-2 mb-md-0 mt-md-auto px-2"> - <div class="row mb-0 mt-2 g-2"> - {% if perms.scipost.can_publish_accepted_submission %} + <div class="row mb-0 mt-2 g-2"> + {% if "can_work_for_stream" in sub_perms and perms.scipost.can_assign_production_officer %} <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"> <div class="row m-0 d-none-empty"> - <button class="btn btn-warning text-white" - hx-get="{% url 'production:_hx_mark_as_completed' stream_id=productionstream.id %}" - {% if productionstream.status != 'published' %}hx-confirm="Are you sure you want to mark this unpublished stream as completed?"{% endif %} - hx-target="#productionstream-{{ productionstream.id }}-details"> - Mark this stream as completed - </button> + <a class="btn btn-warning text-white" role="button" + hx-get="{% url 'production:_hx_toggle_on_hold' stream_id=productionstream.id %}" + hx-target="#productionstream-{{productionstream.id}}-details" + hx-confirm="Are you sure you wish to put this stream on hold?" + hx-swap="outerHTML">Put stream on hold</a> </div> </div> {% endif %} - + {% if perms.scipost.can_draft_publication and productionstream.status == 'accepted' %} <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"> <div class="row m-0 d-none-empty"> @@ -194,10 +192,22 @@ </div> </div> {% endif %} + + {% if perms.scipost.can_publish_accepted_submission %} + <div class="col-12 col-sm-auto col-md-12 col-lg-auto h-100 d-none-empty"> + <div class="row m-0 d-none-empty"> + <a class="btn btn-warning text-white" role="button" + hx-get="{% url 'production:_hx_mark_as_completed' stream_id=productionstream.id %}" + {% if productionstream.status != 'published' %}hx-confirm="Are you sure you want to mark this unpublished stream as completed?"{% endif %} + hx-target="#productionstream-{{ productionstream.id }}-details"> + Mark this stream as completed + </a> + </div> + </div> + {% endif %} </div> </div> - {% endif %} {% endif %} </div> diff --git a/scipost_django/production/templates/production/_hx_productionstream_summary_assignees_status.html b/scipost_django/production/templates/production/_hx_productionstream_summary_assignees_status.html index 96a9c7fe7..12984e28b 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_summary_assignees_status.html +++ b/scipost_django/production/templates/production/_hx_productionstream_summary_assignees_status.html @@ -43,9 +43,20 @@ <div class="row mb-0 justify-content-between align-items-center"> <small class="col text-muted text-nowrap">Stream Status</small> <div class="col-auto"> - <div class="p-2 badge bg-{% if productionstream.status == 'initiated' %}danger{% else %}primary{% endif %}"> - {{ productionstream.status|readable_str|title }} - </div> + {% if productionstream.on_hold %} + <div class="p-2 badge bg-warning pe-auto" + title="Click to remove from 'On Hold'" + hx-get="{% url 'production:_hx_toggle_on_hold' stream_id=productionstream.id %}" + hx-target="#productionstream-{{productionstream.id}}-details" + hx-swap="outerHTML" hx-confirm="Are you sure the issues in this stream have been resolved?"> + <span class="text-white justify-self-start">{% include 'bi/exclamation-triangle-fill.html' %}</span> + On Hold + </div> + {% else %} + <div class="p-2 badge bg-{% if productionstream.status == 'initiated' %}danger{% else %}primary{% endif %}"> + {{ productionstream.status|readable_str|title }} + </div> + {% endif %} </div> </div> </div> diff --git a/scipost_django/production/urls.py b/scipost_django/production/urls.py index 54b32e500..691e16c4f 100644 --- a/scipost_django/production/urls.py +++ b/scipost_django/production/urls.py @@ -279,6 +279,11 @@ urlpatterns = [ production_views._hx_mark_as_completed, name="_hx_mark_as_completed", ), + path( + "_hx_toggle_on_hold", + production_views._hx_toggle_on_hold, + name="_hx_toggle_on_hold", + ), path( "mark_completed", production_views.mark_as_completed, diff --git a/scipost_django/production/views.py b/scipost_django/production/views.py index a3b7189d3..8a4e7e4d6 100644 --- a/scipost_django/production/views.py +++ b/scipost_django/production/views.py @@ -1024,6 +1024,53 @@ def _hx_mark_as_completed(request, stream_id): ) +@is_production_user() +@permission_required("scipost.can_assign_production_officer", raise_exception=True) +@transaction.atomic +def _hx_toggle_on_hold(request, stream_id): + productionstream = get_object_or_404( + ProductionStream.objects.ongoing(), pk=stream_id + ) + + checker = ObjectPermissionChecker(request.user) + if not checker.has_perm("can_work_for_stream", productionstream): + return HTMXPermissionsDenied("You cannot work in this stream.") + + productionstream.on_hold = not productionstream.on_hold + productionstream.save() + + if productionstream.on_hold: + production_event = ProductionEvent( + stream=productionstream, + event="status", + comments=" marked the Production Stream as on hold.", + noted_by=request.user.production_user, + ) + messages.success( + request, + "Production Stream has been marked as on hold.", + ) + else: + production_event = ProductionEvent( + stream=productionstream, + event="status", + comments=" unmarked the Production Stream as on hold.", + noted_by=request.user.production_user, + ) + messages.success( + request, + "Production Stream has been unmarked as on hold.", + ) + + production_event.save() + + return render( + request, + "production/_hx_productionstream_details.html", + {"productionstream": productionstream}, + ) + + @is_production_user() @permission_required("scipost.can_publish_accepted_submission", raise_exception=True) @transaction.atomic -- GitLab