Only use WorkflowState's from latest revision when reporting progress

Also, annotate status_display so we don't use slugs
pull/6257/head
Karl Hobley 2020-02-14 10:22:07 +00:00 zatwierdzone przez Matt Westcott
rodzic 8487742df8
commit ab101f3503
3 zmienionych plików z 24 dodań i 13 usunięć

Wyświetl plik

@ -7,7 +7,7 @@
<h2>{{ workflow.name }}</h2> <h2>{{ workflow.name }}</h2>
{% if current_task_number %} {% if current_task_number %}
{% blocktrans %} Task {{ current_task_number }} of {{ workflow_tasks.count }}{% endblocktrans %}: {{ task.name }} {% blocktrans with workflow_tasks|length as total_tasks %} Task {{ current_task_number }} of {{ total_tasks }}{% endblocktrans %}: {{ task.name }}
{% else %} {% else %}
{% trans 'Task' %}: {{ task.name }} {% trans 'Task' %}: {{ task.name }}
{% endif %} {% endif %}

Wyświetl plik

@ -426,7 +426,7 @@ def edit(request, page_id):
workflow_tasks = workflow_state.all_tasks_with_status() workflow_tasks = workflow_state.all_tasks_with_status()
# add a warning message if tasks have been approved and may need to be re-approved # add a warning message if tasks have been approved and may need to be re-approved
task_has_been_approved = workflow_tasks.filter(status='approved').exists() task_has_been_approved = any(filter(lambda task: task.status == 'approved', workflow_tasks))
# TODO: add icon to message when we have added a workflows icon # TODO: add icon to message when we have added a workflows icon
if request.method == 'GET': if request.method == 'GET':
@ -439,13 +439,13 @@ def edit(request, page_id):
)) ))
# Check for revisions still undergoing moderation and warn # Check for revisions still undergoing moderation and warn
if workflow_tasks.count() == 1: if len(workflow_tasks) == 1:
# If only one task in workflow, show simple message # If only one task in workflow, show simple message
workflow_info = _("This page is currently awaiting moderation") workflow_info = _("This page is currently awaiting moderation")
elif current_task_number: elif current_task_number:
workflow_info = format_html(_("<b>Page '{}'</b> is on <b>Task {} of {}: '{}'</b> in <b>Workflow '{}'</b>. "), page.get_admin_display_title(), current_task_number, workflow_tasks.count(), task.name, workflow.name) workflow_info = format_html(_("<b>Page '{}'</b> is on <b>Task {} of {}: '{}'</b> in <b>Workflow '{}'</b>. "), page.get_admin_display_title(), current_task_number, len(workflow_tasks), task.name, workflow.name)
else: else:
workflow_info = format_html(_("<b>Page '{}'</b> is on <b>Task '{}'</b> in <b>Workflow '{}'</b>. "), page.get_admin_display_title(), current_task_number, workflow_tasks.count(), task.name, workflow.name) workflow_info = format_html(_("<b>Page '{}'</b> is on <b>Task '{}'</b> in <b>Workflow '{}'</b>. "), page.get_admin_display_title(), current_task_number, len(workflow_tasks), task.name, workflow.name)
if task_has_been_approved and getattr(settings, 'WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT', True): if task_has_been_approved and getattr(settings, 'WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT', True):
messages.warning(request, mark_safe(workflow_info + _("Editing this Page will cause completed Tasks to need re-approval.")), buttons=buttons, extra_tags="workflow") messages.warning(request, mark_safe(workflow_info + _("Editing this Page will cause completed Tasks to need re-approval.")), buttons=buttons, extra_tags="workflow")

Wyświetl plik

@ -2846,22 +2846,33 @@ class WorkflowState(models.Model):
def all_tasks_with_status(self): def all_tasks_with_status(self):
""" """
Returns a queryset of Task objects that are linked with this workflow state's Returns a list of Task objects that are linked with this workflow state's
workflow. The status of that task in this workflow state is annotated in the workflow. The status of that task in this workflow state is annotated in the
`.status` field. `.status` field. And a displayable version of that status is annotated in the
`.status_display` field.
This is different to querying TaskState as it also returns tasks that haven't This is different to querying TaskState as it also returns tasks that haven't
been started yet (so won't have a TaskState). been started yet (so won't have a TaskState).
""" """
return self.workflow.tasks.annotate( tasks = list(
status=Subquery( self.workflow.tasks.annotate(
TaskState.objects.filter( status=Subquery(
task_id=OuterRef('id'), TaskState.objects.filter(
workflow_state_id=self.id, task_id=OuterRef('id'),
).values('status') workflow_state_id=self.id,
page_revision_id=self.page.revisions.order_by('-created_at', '-id').values_list('id', flat=True).first()
).values('status')
),
) )
) )
# Manually annotate status_display
status_choices = dict(self.STATUS_CHOICES)
for task in tasks:
task.status_display = status_choices.get(task.status, _("Not started"))
return tasks
class Meta: class Meta:
verbose_name = _('Workflow state') verbose_name = _('Workflow state')
verbose_name_plural = _('Workflow states') verbose_name_plural = _('Workflow states')