Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TP2000-1387 py312 async success page #1305

Merged
merged 30 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3e42c2c
Add confirmation page to sync route
LaurenMullally Sep 27, 2024
00cb172
Redirect async route to create success page
LaurenMullally Sep 27, 2024
81b9959
Make measures a small m
LaurenMullally Oct 4, 2024
de53aee
WIP- Make edit process queue page
LaurenMullally Oct 4, 2024
f8e2bde
add expected measures count property to bulk editor
marya-shariq Oct 10, 2024
bc66887
Create and apply bulk edit measures processing state filter
marya-shariq Oct 11, 2024
89855df
ran linter
marya-shariq Oct 11, 2024
47861c0
Pull combined measure create and edit process code into a base class
LaurenMullally Oct 16, 2024
ac86d1e
Refactor confirm edit sync template to show a number of measures not …
LaurenMullally Oct 16, 2024
0ed5fbc
Swap render for redirect in Sync done and create sync and async succe…
LaurenMullally Oct 16, 2024
925bc9c
Change processing queue url to include create
LaurenMullally Oct 17, 2024
95c8206
change create measures queue tab selected tab name, and page title
LaurenMullally Oct 17, 2024
005d237
Update tab titles and heading semantics and add main heading
LaurenMullally Oct 17, 2024
efb9ea2
lint
LaurenMullally Oct 17, 2024
ce3216c
Merge branch 'master' into TP2000-1387-py312-async-success-page
LaurenMullally Oct 17, 2024
277c32e
forgot h2 closing tags oops
LaurenMullally Oct 17, 2024
7266bd6
Fix broken test due to changed url
LaurenMullally Oct 17, 2024
5037398
add "unknown number" to tasks with failed counts within template
LaurenMullally Oct 18, 2024
2704ed8
Update headings from content guidance
LaurenMullally Oct 24, 2024
f19c284
Add edit link to the home page
LaurenMullally Oct 24, 2024
04f9674
Remove secondary styling on button
LaurenMullally Oct 24, 2024
c16689d
Refresh button to redirect to edit tab
LaurenMullally Oct 24, 2024
6590dbb
remove create from the no bulk edit copy
LaurenMullally Oct 24, 2024
f4613ef
Add doc strings to the sync and async confirm views
LaurenMullally Oct 24, 2024
0fe71c9
Hook up create sync to success view
LaurenMullally Oct 24, 2024
90a41ba
Lint
LaurenMullally Oct 25, 2024
1f74961
Fix test to accommodate sync create redirect
LaurenMullally Oct 25, 2024
79fbecf
Merge branch 'master' into TP2000-1387-py312-async-success-page
LaurenMullally Oct 25, 2024
773c125
Merge branch 'master' into TP2000-1387-py312-async-success-page
LaurenMullally Nov 4, 2024
a9d5798
Merge branch 'master' into TP2000-1387-py312-async-success-page
LaurenMullally Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/jinja2/common/celery_queues.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"href": url('measure-create-process-queue'),
"selected": selected_tab == "measure-process-queue"
},
{
"text": "Measure edit process queue",
"href": url('measure-edit-process-queue'),
"selected": selected_tab == "measure-edit-process-queue"
},
{
"text": "Rule check queue",
"href": url('workbaskets:rule-check-queue'),
Expand Down
2 changes: 1 addition & 1 deletion measures/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ def edit_measures(self) -> List["measure_models.Measure"]:
workbasket=self.workbasket,
)

edited_measures.append(new_measure.id)
edited_measures.append(new_measure)

return edited_measures
12 changes: 12 additions & 0 deletions measures/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from measures.models import MeasureCondition
from measures.models import MeasureType
from measures.models.bulk_processing import MeasuresBulkCreator
from measures.models.bulk_processing import MeasuresBulkEditor
from quotas.models import QuotaOrderNumber
from regulations.models import Regulation
from workbaskets.models import WorkBasket
Expand Down Expand Up @@ -302,3 +303,14 @@ class MeasureCreateTaskFilter(TamatoFilter):
class Meta:
model = MeasuresBulkCreator
fields = ["processing_state"]


class MeasureEditTaskFilter(TamatoFilter):
"""FilterSet for Bulk Measure Edit tasks."""

search_fields = "processing_state"
clear_url = reverse_lazy("measure-edit-process-queue")

class Meta:
model = MeasuresBulkEditor
fields = ["processing_state"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% endmacro %}

{% macro panel_subtitle(created_measures) %}
You can view {% if expected_measures_count > 1 %}their{% else %}its{% endif %} status on the Measures process queue page.
You can view {% if expected_measures_count > 1 %}their{% else %}its{% endif %} status on the measures process queue page.
{% endmacro %}

{% block breadcrumb %}
Expand Down Expand Up @@ -37,6 +37,11 @@
"href": url("home"),
"classes": "govuk-button--secondary"
}) }}
{{ govukButton({
"text": "Return to workbasket",
"href": url("workbaskets:current-workbasket"),
"classes": "govuk-button--secondary"
}) }}
</div>
</div>
</div>
Expand Down
42 changes: 42 additions & 0 deletions measures/jinja2/measures/confirm-edit-multiple.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends "layouts/confirm.jinja" %}
{% from "components/breadcrumbs.jinja" import breadcrumbs %}

{% set page_title = "Edit measure details" %}

{% macro panel_title(edited_measures) %}
{% if edited_measures|length > 1 %}
{{ edited_measures.0._meta.verbose_name_plural|title }} {% for m in edited_measures %}{% if not loop.last %}{{ m|string }}, {% else %}{{ m|string }} {% endif %}{% endfor %}have been edited
{% else %}
{{ edited_measures.0._meta.verbose_name|title }} {{ edited_measures.0|string }} has been edited
{% endif %}
{% endmacro %}

{% macro panel_subtitle(created_measures) %}
This change has been added to your workbasket
{% endmacro %}

{% block breadcrumb %}
{{ breadcrumbs(request, [
{"text": page_title },
])
}}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
"titleText": panel_title(edited_measures),
"text": panel_subtitle(edited_measures),
"classes": "govuk-!-margin-bottom-7"
}) }}
<h2 class="govuk-heading-m">Next steps</h2>
<p class="govuk-body">To complete your task you must publish your change. </p>
{{ govukButton({
"text": "Go to workbasket summary",
"href": url("workbaskets:current-workbasket"),
"classes": "govuk-button--secondary"
}) }}
LaurenMullally marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
{% endblock %}
86 changes: 86 additions & 0 deletions measures/jinja2/measures/edit-process-queue.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{% extends "common/celery_queues.jinja" %}

{% from "macros/inline_filter_links.jinja" import inline_filter_links %}
{% from "components/table/macro.njk" import govukTable %}
{% from "components/button/macro.njk" import govukButton %}

{% set list_include = "includes/measures/create-task-list.jinja"%}
{# Might wanna make an edit one or make this one useable by both #}

{% set page_title = "Measures process queue" %}


{% block breadcrumb %}
{{ breadcrumbs(
request,
[ {"text": page_title} ],
with_workbasket=False,
) }}
{% endblock %}

{% set filter_links_list = [
{
"text": "All",
"href": "?processing_state=",
"selected": selected_link == "all",
},
{
"text": "Processing",
"href": "?processing_state=PROCESSING",
"selected": selected_link == "processing",
},
{
"text": "Completed",
"href": "?processing_state=SUCCESSFULLY_PROCESSED",
"selected": selected_link == "completed",
},
{
"text": "Failed",
"href": "?processing_state=FAILED_PROCESSING",
"selected": selected_link == "failed",
},
{
"text": "Terminated",
"href": "?processing_state=CANCELLED",
"selected": selected_link == "terminated",
},
]%}

{% block tab_content %}
<div class="govuk-grid-row">

<div class="govuk-grid-column-full">
<h1 class="govuk-heading-xl">{{ page_title }}</h1>

<nav class="workbasket-filters">
<p class="govuk-body govuk-!-font-weight-bold">Filter results:</p>
<div class="govuk-!-margin-top-2">
{{ inline_filter_links(filter_links_list) }}
</div>

{{ govukButton({
"html": refresh_button_content,
"href": url("measure-create-process-queue"),
LaurenMullally marked this conversation as resolved.
Show resolved Hide resolved
"classes": "govuk-button--primary align-right govuk-!-margin-bottom-0 refresh-button",
}) }}
</nav>
</div>

<div class="govuk-grid-column-full govuk-!-margin-bottom-3">
<hr class="govuk-section-break govuk-section-break--visible">
</div>

<div class="govuk-grid-column-full">
{% if object_list %}
{% include list_include%}
{% else %}
<p class="govuk-body">No bulk create/edit tasks with this status</p>
LaurenMullally marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
</div>

<div class="govuk-grid-column-full">
{% include "includes/common/pagination.jinja" %}
</div>

</div>
{% endblock %}
4 changes: 4 additions & 0 deletions measures/models/bulk_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ class MeasuresBulkEditor(BulkProcessor):
)
"""The user who submitted the task to create measures."""

@property
def expected_measures_count(self) -> int:
return len(self.selected_measures)

def schedule_task(self) -> AsyncResult:
"""Implementation of base class method."""

Expand Down
10 changes: 10 additions & 0 deletions measures/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
),
name="measure-ui-edit-multiple",
),
path(
"edit/done-async/<int:expected_measures_count>/",
LaurenMullally marked this conversation as resolved.
Show resolved Hide resolved
views.MeasuresWizardCreateConfirm.as_view(),
name="measure-ui-edit-confirm",
),
path(
"delete-multiple-measures/",
views.MeasureMultipleDelete.as_view(),
Expand Down Expand Up @@ -71,6 +76,11 @@
views.MeasuresCreateProcessQueue.as_view(),
name="measure-create-process-queue",
),
path(
"edit-process-queue/",
views.MeasuresEditProcessQueue.as_view(),
name="measure-edit-process-queue",
),
path(
"cancel-bulk-processor-task/<int:pk>/",
views.CancelBulkProcessorTask.as_view(),
Expand Down
122 changes: 122 additions & 0 deletions measures/views/bulk_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from common.views import WithPaginationListView
from measures import models
from measures.filters import MeasureCreateTaskFilter
from measures.filters import MeasureEditTaskFilter
from measures.forms import CancelBulkProcessorTaskForm
from measures.models.bulk_processing import MeasuresBulkCreator
from measures.models.bulk_processing import ProcessingState
Expand Down Expand Up @@ -196,3 +197,124 @@ def status_tag_generator(self, task: models.MeasuresBulkCreator) -> dict:
"text": "",
"tag_class": "",
}


class MeasuresEditProcessQueue(
LaurenMullally marked this conversation as resolved.
Show resolved Hide resolved
PermissionRequiredMixin,
WithPaginationListView,
):
"""UI endpoint for bulk editing Measures process queue."""

permission_required = [
"common.add_trackedmodel",
"common.change_trackedmodel",
]
template_name = "measures/edit-process-queue.jinja"
model = models.MeasuresBulkEditor
queryset = models.MeasuresBulkEditor.objects.filter(
workbasket__status=WorkflowStatus.EDITING,
).order_by("-created_at")
filterset_class = MeasureEditTaskFilter

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["selected_link"] = "all"
context["selected_tab"] = "measure-edit-process-queue"
processing_state = self.request.GET.get("processing_state")

if processing_state == "PROCESSING":
context["selected_link"] = "processing"
elif processing_state == ProcessingState.CANCELLED:
context["selected_link"] = "terminated"
elif processing_state == ProcessingState.FAILED_PROCESSING:
context["selected_link"] = "failed"
elif processing_state == ProcessingState.SUCCESSFULLY_PROCESSED:
context["selected_link"] = "completed"
# Provide template access to some UI / view utility functions.
context["status_tag_generator"] = self.status_tag_generator
context["can_terminate_task"] = self.can_terminate_task
context["is_task_failed"] = self.is_task_failed
context["is_task_terminated"] = self.is_task_terminated
# Apply the TAP standard date format within the UI.
context["datetime_format"] = settings.DATETIME_FORMAT
if context["selected_link"] == "processing":
context["object_list"] = self.get_processing_queryset()
return context

def get_processing_queryset(self):
"""Returns a combined queryset of tasks either AWAITING_PROCESSING or
CURRENTLY_PROCESSING."""

return self.queryset.filter(
Q(processing_state=ProcessingState.AWAITING_PROCESSING)
| Q(processing_state=ProcessingState.CURRENTLY_PROCESSING),
)

def is_task_failed(self, task: models.MeasuresBulkCreator) -> bool:
"""
Return True if the task is in a failed state.

Return False otherwise.
"""

return task.processing_state == ProcessingState.FAILED_PROCESSING

def is_task_terminated(self, task: MeasuresBulkCreator) -> bool:
"""
Return True if the task is in a cancelled state. Cancelled tasks are
surfaced as 'terminated' in the UI.

Return False otherwise.
"""

return task.processing_state == ProcessingState.CANCELLED

def can_terminate_task(self, task: MeasuresBulkCreator) -> bool:
"""
Return True if a task is in a queued state and the current user is
permitted to terminate a task.

Return False otherwise.
"""

if (
self.request.user.is_superuser
and task.processing_state in ProcessingState.queued_states()
):
return True

return False

def status_tag_generator(self, task: models.MeasuresBulkCreator) -> dict:
"""Returns a dict with text and a CSS class for a UI-friendly label for
a bulk creation task."""

if task.processing_state in [
ProcessingState.CURRENTLY_PROCESSING,
ProcessingState.AWAITING_PROCESSING,
]:
return {
"text": "Processing",
"tag_class": "tamato-badge-light-blue",
}
elif task.processing_state == ProcessingState.SUCCESSFULLY_PROCESSED:
return {
"text": "Completed",
"tag_class": "tamato-badge-light-green",
}
elif task.processing_state == ProcessingState.FAILED_PROCESSING:
return {
"text": "Failed",
"tag_class": "tamato-badge-light-red",
}
elif task.processing_state == ProcessingState.CANCELLED:
return {
"text": "Terminated",
"tag_class": "tamato-badge-light-yellow",
}
else:
return {
"text": "",
"tag_class": "",
}
Loading
Loading