kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Rename `page_revision` to `revision` in `TaskState`
							rodzic
							
								
									c7da2988d5
								
							
						
					
					
						commit
						d8f9d9869a
					
				|  | @ -1050,11 +1050,11 @@ Task states store state information about the progress of a task on a particular | ||||||
| 
 | 
 | ||||||
|         The workflow state which started this task state. |         The workflow state which started this task state. | ||||||
| 
 | 
 | ||||||
|     .. attribute:: page_revision |     .. attribute:: revision | ||||||
| 
 | 
 | ||||||
|         (foreign key to ``Revision``) |         (foreign key to ``Revision``) | ||||||
| 
 | 
 | ||||||
|         The page revision this task state was created on. |         The revision this task state was created on. | ||||||
| 
 | 
 | ||||||
|     .. attribute:: task |     .. attribute:: task | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ | ||||||
|             </thead> |             </thead> | ||||||
|             <tbody> |             <tbody> | ||||||
|                 {% for workflow_state in workflow_states %} |                 {% for workflow_state in workflow_states %} | ||||||
|                     {% with workflow_state.current_task_state.page_revision as revision %} |                     {% with workflow_state.current_task_state.revision as revision %} | ||||||
|                         {% page_permissions workflow_state.page as page_perms %} |                         {% page_permissions workflow_state.page as page_perms %} | ||||||
|                         <tr> |                         <tr> | ||||||
|                             <td class="title" valign="top"> |                             <td class="title" valign="top"> | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ | ||||||
|             </thead> |             </thead> | ||||||
|             <tbody> |             <tbody> | ||||||
|                 {% for task_state, actions, workflow_tasks in states %} |                 {% for task_state, actions, workflow_tasks in states %} | ||||||
|                     {% with task_state.page_revision as revision %} |                     {% with task_state.revision as revision %} | ||||||
|                         {% page_permissions revision.content_object as page_perms %} |                         {% page_permissions revision.content_object as page_perms %} | ||||||
|                         <tr> |                         <tr> | ||||||
|                             <td class="title" valign="top"> |                             <td class="title" valign="top"> | ||||||
|  |  | ||||||
|  | @ -126,7 +126,7 @@ class UserPagesInWorkflowModerationPanel(Component): | ||||||
|                     "page", |                     "page", | ||||||
|                     "current_task_state", |                     "current_task_state", | ||||||
|                     "current_task_state__task", |                     "current_task_state__task", | ||||||
|                     "current_task_state__page_revision", |                     "current_task_state__revision", | ||||||
|                 ) |                 ) | ||||||
|                 .order_by("-current_task_state__started_at") |                 .order_by("-current_task_state__started_at") | ||||||
|             ) |             ) | ||||||
|  | @ -148,9 +148,9 @@ class WorkflowPagesToModeratePanel(Component): | ||||||
|             states = ( |             states = ( | ||||||
|                 TaskState.objects.reviewable_by(request.user) |                 TaskState.objects.reviewable_by(request.user) | ||||||
|                 .select_related( |                 .select_related( | ||||||
|                     "page_revision", |                     "revision", | ||||||
|                     "task", |                     "task", | ||||||
|                     "page_revision__user", |                     "revision__user", | ||||||
|                 ) |                 ) | ||||||
|                 .order_by("-started_at") |                 .order_by("-started_at") | ||||||
|             ) |             ) | ||||||
|  | @ -158,7 +158,7 @@ class WorkflowPagesToModeratePanel(Component): | ||||||
|                 ( |                 ( | ||||||
|                     state, |                     state, | ||||||
|                     state.task.specific.get_actions( |                     state.task.specific.get_actions( | ||||||
|                         page=state.page_revision.content_object, user=request.user |                         page=state.revision.content_object, user=request.user | ||||||
|                     ), |                     ), | ||||||
|                     state.workflow_state.all_tasks_with_status(), |                     state.workflow_state.all_tasks_with_status(), | ||||||
|                 ) |                 ) | ||||||
|  |  | ||||||
|  | @ -90,7 +90,7 @@ def workflow_history_detail(request, page_id, workflow_state_id): | ||||||
|     page_revisions = Revision.page_revisions.filter( |     page_revisions = Revision.page_revisions.filter( | ||||||
|         object_id=str(page.id), |         object_id=str(page.id), | ||||||
|         id__in=TaskState.objects.filter(workflow_state=workflow_state).values_list( |         id__in=TaskState.objects.filter(workflow_state=workflow_state).values_list( | ||||||
|             "page_revision_id", flat=True |             "revision_id", flat=True | ||||||
|         ), |         ), | ||||||
|     ).order_by("-created_at") |     ).order_by("-created_at") | ||||||
| 
 | 
 | ||||||
|  | @ -101,7 +101,7 @@ def workflow_history_detail(request, page_id, workflow_state_id): | ||||||
|             { |             { | ||||||
|                 task_state.task: task_state |                 task_state.task: task_state | ||||||
|                 for task_state in TaskState.objects.filter( |                 for task_state in TaskState.objects.filter( | ||||||
|                     workflow_state=workflow_state, page_revision=page_revision |                     workflow_state=workflow_state, revision=page_revision | ||||||
|                 ) |                 ) | ||||||
|             }, |             }, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  | @ -240,8 +240,8 @@ def preview_revision_for_task(request, page_id, task_id): | ||||||
|     task = get_object_or_404(Task, id=task_id).specific |     task = get_object_or_404(Task, id=task_id).specific | ||||||
|     try: |     try: | ||||||
|         task_state = TaskState.objects.get( |         task_state = TaskState.objects.get( | ||||||
|             page_revision__base_content_type=get_default_page_content_type(), |             revision__base_content_type=get_default_page_content_type(), | ||||||
|             page_revision__object_id=page.id, |             revision__object_id=page.id, | ||||||
|             task=task, |             task=task, | ||||||
|             status=TaskState.STATUS_IN_PROGRESS, |             status=TaskState.STATUS_IN_PROGRESS, | ||||||
|         ) |         ) | ||||||
|  | @ -255,7 +255,7 @@ def preview_revision_for_task(request, page_id, task_id): | ||||||
|         ) |         ) | ||||||
|         return redirect("wagtailadmin_home") |         return redirect("wagtailadmin_home") | ||||||
| 
 | 
 | ||||||
|     revision = task_state.page_revision |     revision = task_state.revision | ||||||
| 
 | 
 | ||||||
|     if not task.get_actions(page, request.user): |     if not task.get_actions(page, request.user): | ||||||
|         raise PermissionDenied |         raise PermissionDenied | ||||||
|  |  | ||||||
|  | @ -104,7 +104,7 @@ class Migration(migrations.Migration): | ||||||
|                         on_delete=django.db.models.deletion.CASCADE, |                         on_delete=django.db.models.deletion.CASCADE, | ||||||
|                         related_name="task_states", |                         related_name="task_states", | ||||||
|                         to="wagtailcore.PageRevision", |                         to="wagtailcore.PageRevision", | ||||||
|                         verbose_name="page revision", |                         verbose_name="revision", | ||||||
|                     ), |                     ), | ||||||
|                 ), |                 ), | ||||||
|                 ( |                 ( | ||||||
|  |  | ||||||
|  | @ -0,0 +1,18 @@ | ||||||
|  | # Generated by Django 4.2.dev20221212120043 on 2022-12-12 13:03 | ||||||
|  | 
 | ||||||
|  | from django.db import migrations | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  | 
 | ||||||
|  |     dependencies = [ | ||||||
|  |         ("wagtailcore", "0078_referenceindex"), | ||||||
|  |     ] | ||||||
|  | 
 | ||||||
|  |     operations = [ | ||||||
|  |         migrations.RenameField( | ||||||
|  |             model_name="taskstate", | ||||||
|  |             old_name="page_revision", | ||||||
|  |             new_name="revision", | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
|  | @ -3578,7 +3578,7 @@ class Task(models.Model): | ||||||
|         """Start this task on the provided workflow state by creating an instance of TaskState""" |         """Start this task on the provided workflow state by creating an instance of TaskState""" | ||||||
|         task_state = self.get_task_state_class()(workflow_state=workflow_state) |         task_state = self.get_task_state_class()(workflow_state=workflow_state) | ||||||
|         task_state.status = TaskState.STATUS_IN_PROGRESS |         task_state.status = TaskState.STATUS_IN_PROGRESS | ||||||
|         task_state.page_revision = workflow_state.page.get_latest_revision() |         task_state.revision = workflow_state.page.get_latest_revision() | ||||||
|         task_state.task = self |         task_state.task = self | ||||||
|         task_state.save() |         task_state.save() | ||||||
|         task_submitted.send( |         task_submitted.send( | ||||||
|  | @ -3925,7 +3925,7 @@ class WorkflowState(models.Model): | ||||||
|         """Put a STATUS_NEEDS_CHANGES workflow state back into STATUS_IN_PROGRESS, and restart the current task""" |         """Put a STATUS_NEEDS_CHANGES workflow state back into STATUS_IN_PROGRESS, and restart the current task""" | ||||||
|         if self.status != self.STATUS_NEEDS_CHANGES: |         if self.status != self.STATUS_NEEDS_CHANGES: | ||||||
|             raise PermissionDenied |             raise PermissionDenied | ||||||
|         revision = self.current_task_state.page_revision |         revision = self.current_task_state.revision | ||||||
|         current_task_state = self.current_task_state |         current_task_state = self.current_task_state | ||||||
|         self.current_task_state = None |         self.current_task_state = None | ||||||
|         self.status = self.STATUS_IN_PROGRESS |         self.status = self.STATUS_IN_PROGRESS | ||||||
|  | @ -4016,7 +4016,7 @@ class WorkflowState(models.Model): | ||||||
|         ) |         ) | ||||||
|         if getattr(settings, "WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT", False): |         if getattr(settings, "WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT", False): | ||||||
|             successful_task_states = successful_task_states.filter( |             successful_task_states = successful_task_states.filter( | ||||||
|                 page_revision=self.page.get_latest_revision() |                 revision=self.page.get_latest_revision() | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|         return successful_task_states |         return successful_task_states | ||||||
|  | @ -4053,7 +4053,7 @@ class WorkflowState(models.Model): | ||||||
|                     }, |                     }, | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             revision=self.current_task_state.page_revision, |             revision=self.current_task_state.revision, | ||||||
|             user=user, |             user=user, | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  | @ -4073,18 +4073,18 @@ class WorkflowState(models.Model): | ||||||
|         workflow_approved.send(sender=self.__class__, instance=self, user=user) |         workflow_approved.send(sender=self.__class__, instance=self, user=user) | ||||||
| 
 | 
 | ||||||
|     def copy_approved_task_states_to_revision(self, revision): |     def copy_approved_task_states_to_revision(self, revision): | ||||||
|         """This creates copies of previously approved task states with page_revision set to a different revision.""" |         """This creates copies of previously approved task states with revision set to a different revision.""" | ||||||
|         approved_states = TaskState.objects.filter( |         approved_states = TaskState.objects.filter( | ||||||
|             workflow_state=self, status=TaskState.STATUS_APPROVED |             workflow_state=self, status=TaskState.STATUS_APPROVED | ||||||
|         ) |         ) | ||||||
|         for state in approved_states: |         for state in approved_states: | ||||||
|             state.copy(update_attrs={"page_revision": revision}) |             state.copy(update_attrs={"revision": revision}) | ||||||
| 
 | 
 | ||||||
|     def revisions(self): |     def revisions(self): | ||||||
|         """Returns all page revisions associated with task states linked to the current workflow state""" |         """Returns all page revisions associated with task states linked to the current workflow state""" | ||||||
|         return Revision.page_revisions.filter( |         return Revision.page_revisions.filter( | ||||||
|             object_id=str(self.page_id), |             object_id=str(self.page_id), | ||||||
|             id__in=self.task_states.values_list("page_revision_id", flat=True), |             id__in=self.task_states.values_list("revision_id", flat=True), | ||||||
|         ).defer("content") |         ).defer("content") | ||||||
| 
 | 
 | ||||||
|     def _get_applicable_task_states(self): |     def _get_applicable_task_states(self): | ||||||
|  | @ -4099,7 +4099,7 @@ class WorkflowState(models.Model): | ||||||
|                 .values_list("id", flat=True) |                 .values_list("id", flat=True) | ||||||
|                 .first() |                 .first() | ||||||
|             ) |             ) | ||||||
|             task_states = task_states.filter(page_revision_id=latest_revision_id) |             task_states = task_states.filter(revision_id=latest_revision_id) | ||||||
|         return task_states |         return task_states | ||||||
| 
 | 
 | ||||||
|     def all_tasks_with_status(self): |     def all_tasks_with_status(self): | ||||||
|  | @ -4203,7 +4203,7 @@ class TaskStateManager(models.Manager): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TaskState(models.Model): | class TaskState(models.Model): | ||||||
|     """Tracks the status of a given Task for a particular page revision.""" |     """Tracks the status of a given Task for a particular revision.""" | ||||||
| 
 | 
 | ||||||
|     STATUS_IN_PROGRESS = "in_progress" |     STATUS_IN_PROGRESS = "in_progress" | ||||||
|     STATUS_APPROVED = "approved" |     STATUS_APPROVED = "approved" | ||||||
|  | @ -4224,10 +4224,10 @@ class TaskState(models.Model): | ||||||
|         verbose_name=_("workflow state"), |         verbose_name=_("workflow state"), | ||||||
|         related_name="task_states", |         related_name="task_states", | ||||||
|     ) |     ) | ||||||
|     page_revision = models.ForeignKey( |     revision = models.ForeignKey( | ||||||
|         "Revision", |         "Revision", | ||||||
|         on_delete=models.CASCADE, |         on_delete=models.CASCADE, | ||||||
|         verbose_name=_("page revision"), |         verbose_name=_("revision"), | ||||||
|         related_name="task_states", |         related_name="task_states", | ||||||
|     ) |     ) | ||||||
|     task = models.ForeignKey( |     task = models.ForeignKey( | ||||||
|  | @ -4277,11 +4277,9 @@ class TaskState(models.Model): | ||||||
|                 self.content_type = ContentType.objects.get_for_model(self) |                 self.content_type = ContentType.objects.get_for_model(self) | ||||||
| 
 | 
 | ||||||
|     def __str__(self): |     def __str__(self): | ||||||
|         return _( |         return _("Task '%(task_name)s' on Revision '%(revision_info)s': %(status)s") % { | ||||||
|             "Task '%(task_name)s' on Page Revision '%(revision_info)s': %(status)s" |  | ||||||
|         ) % { |  | ||||||
|             "task_name": self.task, |             "task_name": self.task, | ||||||
|             "revision_info": self.page_revision, |             "revision_info": self.revision, | ||||||
|             "status": self.status, |             "status": self.status, | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -4298,7 +4296,7 @@ class TaskState(models.Model): | ||||||
|             # Cannot locate a model class for this content type. This might happen |             # Cannot locate a model class for this content type. This might happen | ||||||
|             # if the codebase and database are out of sync (e.g. the model exists |             # if the codebase and database are out of sync (e.g. the model exists | ||||||
|             # on a different git branch and we haven't rolled back migrations before |             # on a different git branch and we haven't rolled back migrations before | ||||||
|             # switching branches); if so, the best we can do is return the page |             # switching branches); if so, the best we can do is return the task state | ||||||
|             # unchanged. |             # unchanged. | ||||||
|             return self |             return self | ||||||
|         elif isinstance(self, model_class): |         elif isinstance(self, model_class): | ||||||
|  | @ -4404,13 +4402,13 @@ class TaskState(models.Model): | ||||||
| 
 | 
 | ||||||
|     def log_state_change_action(self, user, action): |     def log_state_change_action(self, user, action): | ||||||
|         """Log the approval/rejection action""" |         """Log the approval/rejection action""" | ||||||
|         page = self.page_revision.as_object() |         obj = self.revision.as_object() | ||||||
|         next_task = self.workflow_state.get_next_task() |         next_task = self.workflow_state.get_next_task() | ||||||
|         next_task_data = None |         next_task_data = None | ||||||
|         if next_task: |         if next_task: | ||||||
|             next_task_data = {"id": next_task.id, "title": next_task.name} |             next_task_data = {"id": next_task.id, "title": next_task.name} | ||||||
|         log( |         log( | ||||||
|             instance=page, |             instance=obj, | ||||||
|             action="wagtail.workflow.{}".format(action), |             action="wagtail.workflow.{}".format(action), | ||||||
|             user=user, |             user=user, | ||||||
|             data={ |             data={ | ||||||
|  | @ -4427,7 +4425,7 @@ class TaskState(models.Model): | ||||||
|                 }, |                 }, | ||||||
|                 "comment": self.get_comment(), |                 "comment": self.get_comment(), | ||||||
|             }, |             }, | ||||||
|             revision=self.page_revision, |             revision=self.revision, | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|     class Meta: |     class Meta: | ||||||
|  |  | ||||||
|  | @ -170,7 +170,7 @@ class TestWorkflows(TestCase): | ||||||
|         task_state = workflow_state.current_task_state |         task_state = workflow_state.current_task_state | ||||||
|         self.assertEqual(task_state.task, task_1) |         self.assertEqual(task_state.task, task_1) | ||||||
|         self.assertEqual(task_state.status, "in_progress") |         self.assertEqual(task_state.status, "in_progress") | ||||||
|         self.assertEqual(task_state.page_revision, homepage.get_latest_revision()) |         self.assertEqual(task_state.revision, homepage.get_latest_revision()) | ||||||
|         if settings.USE_TZ: |         if settings.USE_TZ: | ||||||
|             self.assertEqual( |             self.assertEqual( | ||||||
|                 task_state.started_at, |                 task_state.started_at, | ||||||
|  | @ -231,9 +231,7 @@ class TestWorkflows(TestCase): | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(workflow_state.status, "approved") |         self.assertEqual(workflow_state.status, "approved") | ||||||
|         page.refresh_from_db() |         page.refresh_from_db() | ||||||
|         self.assertEqual( |         self.assertEqual(page.live_revision, workflow_state.current_task_state.revision) | ||||||
|             page.live_revision, workflow_state.current_task_state.page_revision |  | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
|     @override_settings(WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT=True) |     @override_settings(WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT=True) | ||||||
|     def test_workflow_resets_when_new_revision_created(self): |     def test_workflow_resets_when_new_revision_created(self): | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Sage Abdullah
						Sage Abdullah