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 c2ec64a40630462d8040c40f4f7021840762f1b8..7f6e4df723aabca6a896dd1001af00c0b631ded9 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 @@ -16,10 +16,3 @@ </form> </div> {% endif %} - -{% if message %} - <div id="productionstream-{{ stream.id }}-actions-message" - class="alert alert-{{ message.type }}" - role="alert" - hx-swap-oob="true">{{ message.text }}</div> -{% endif %} 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 869ab3255b2b0a6cd7f56f9d16986ddf59bdd650..8a1c7d8dfe12422142021ca431f2d248b7cf3c08 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_officer.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_officer.html @@ -16,10 +16,3 @@ </form> </div> {% endif %} - -{% if message %} - <div id="productionstream-{{ stream.id }}-actions-message" - class="alert alert-{{ message.type }}" - role="alert" - hx-swap-oob="true">{{ message.text }}</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 c7bcde48f7f5dd09b73e374216777d08687a196f..59fd5c29d2c7a27f82a300429e8282b575b61801 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_status.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_status.html @@ -18,10 +18,3 @@ </div> </form> {% endif %} - -{% if message %} - <div id="productionstream-{{ stream.id }}-actions-message" - class="alert alert-{{ message.type }}" - role="alert" - hx-swap-oob="true">{{ message.text }}</div> -{% 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 e7c8743a7dd5063236dada698c9a3e4d61cf77e1..aa86793c1e8dff0a2436e7e39d729e30824761aa 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html +++ b/scipost_django/production/templates/production/_hx_productionstream_change_supervisor.html @@ -16,10 +16,3 @@ </form> </div> {% endif %} - -{% if message %} - <div id="productionstream-{{ stream.id }}-actions-message" - class="alert alert-{{ message.type }}" - role="alert" - hx-swap-oob="true">{{ message.text }}</div> -{% endif %} diff --git a/scipost_django/production/views.py b/scipost_django/production/views.py index 42db0e5c480dbc3961559eda5be1fbe6c0ed0124..88ed8b8ad4d591a6fc65fa826113d00abc4631b9 100644 --- a/scipost_django/production/views.py +++ b/scipost_django/production/views.py @@ -428,9 +428,7 @@ def _hx_productionstream_actions_work_log(request, productionstream_id): log.content = productionstream log.user = request.user log.save() - else: - # messages.warning(request, "The form was invalidly filled.") - pass + messages.success(request, "Work Log added to Stream.") context = { "productionstream": productionstream, @@ -469,25 +467,18 @@ def update_status(request, stream_id): auto_id=f"productionstream_{productionstream.id}_id_%s", ) - if status_form.is_valid(): - stream = status_form.save() - status_form.fields["status"].choices = status_form.get_available_statuses() - message = { - "type": "success", - "text": "Production Stream succesfully changed status.", - } + if status_form.is_valid(): + status_form.save() + status_form.fields["status"].choices = status_form.get_available_statuses() + messages.success(request, "Production Stream succesfully changed status.") - else: - message = { - "type": "danger", - "text": "\\n".join(status_form.errors.values()), - } + else: + messages.error(request, "\\n".join(status_form.errors.values())) - context = { - "stream": productionstream, - "form": status_form, - "message": message, - } + context = { + "stream": productionstream, + "form": status_form, + } return render( request, @@ -581,13 +572,10 @@ def update_officer(request, stream_id): officer_form.save() officer = officer_form.cleaned_data.get("officer") - # Add officer to stream if they exist. - if officer is not None: - assign_perm("can_work_for_stream", officer.user, productionstream) - message = { - "type": "success", - "text": f"Officer {officer} has been assigned.", - } + # Add officer to stream if they exist. + if officer is not None: + assign_perm("can_work_for_stream", officer.user, productionstream) + messages.success(request, f"Officer {officer} has been assigned.") event = ProductionEvent( stream=productionstream, @@ -603,24 +591,18 @@ def update_officer(request, stream_id): ProductionUtils.load({"request": request, "stream": productionstream}) ProductionUtils.email_assigned_production_officer() - # Remove old officer. - else: - remove_perm("can_work_for_stream", prev_officer.user, productionstream) - message = { - "type": "success", - "text": f"Officer {prev_officer} has been removed.", - } + # Remove old officer. else: - message = { - "type": "danger", - "text": "\\n".join(officer_form.errors.values()), - } + remove_perm("can_work_for_stream", prev_officer.user, productionstream) + messages.success(request, "Officer {prev_officer} has been removed.") - context = { - "stream": productionstream, - "form": officer_form, - "message": message, - } + else: + messages.error(request, "\\n".join(officer_form.errors.values())) + + context = { + "stream": productionstream, + "form": officer_form, + } return render( request, @@ -737,13 +719,12 @@ def update_invitations_officer(request, stream_id): "invitations_officer" ) - # Add invitations officer to stream if they exist. - if inv_officer is not None: - assign_perm("can_work_for_stream", inv_officer.user, productionstream) - message = { - "type": "success", - "text": f"Invitations Officer {inv_officer} has been assigned.", - } + # Add invitations officer to stream if they exist. + if inv_officer is not None: + assign_perm("can_work_for_stream", inv_officer.user, productionstream) + messages.success( + request, f"Invitations Officer {inv_officer} has been assigned." + ) event = ProductionEvent( stream=productionstream, @@ -759,27 +740,19 @@ def update_invitations_officer(request, stream_id): ProductionUtils.load({"request": request, "stream": productionstream}) ProductionUtils.email_assigned_invitation_officer() - # Remove old invitations officer. - else: - remove_perm( - "can_work_for_stream", prev_inv_officer.user, productionstream - ) - message = { - "type": "success", - "text": f"Invitations Officer {prev_inv_officer} has been removed.", - } - + # Remove old invitations officer. else: - message = { - "type": "danger", - "text": "\\n".join(invitations_officer_form.errors.values()), - } + remove_perm("can_work_for_stream", prev_inv_officer.user, productionstream) + messages.success( + request, f"Invitations Officer {prev_inv_officer} has been removed." + ) + else: + messages.error(request, "\\n".join(invitations_officer_form.errors.values())) - context = { - "stream": productionstream, - "form": invitations_officer_form, - "message": message, - } + context = { + "stream": productionstream, + "form": invitations_officer_form, + } return render( request, @@ -882,10 +855,7 @@ def update_supervisor(request, stream_id): # Add supervisor to stream if they exist. if supervisor is not None: - message = { - "type": "success", - "text": f"Supervisor {supervisor} has been assigned.", - } + messages.success(request, f"Supervisor {supervisor} has been assigned.") assign_perm("can_work_for_stream", supervisor.user, productionstream) assign_perm( @@ -914,21 +884,14 @@ def update_supervisor(request, stream_id): prev_supervisor.user, productionstream, ) - message = { - "type": "success", - "text": f"Supervisor {prev_supervisor} has been removed.", - } + messages.success(request, f"Supervisor {prev_supervisor} has been removed.") else: - message = { - "type": "danger", - "text": "\\n".join(supervisor_form.errors.values()), - } + messages.error(request, "\\n".join(supervisor_form.errors.values())) context = { "stream": productionstream, "form": supervisor_form, - "message": message, } return render(