Skip to content

Commit

Permalink
Update migrations to work with latest workflow branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Jun 16, 2020
1 parent 9d62ae0 commit 1734a0e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion wagtail_review/migrations/0009_wagtail_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0048_taskstate_finished_by'),
('wagtailcore', '0049_taskstate_finished_by'),
('wagtail_review', '0008_rename_externaluser_to_externalreviewer'),
]

Expand Down
2 changes: 1 addition & 1 deletion wagtail_review/migrations/0010_groupreviewtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Migration(migrations.Migration):

dependencies = [
('auth', '0011_update_proxy_permissions'),
('wagtailcore', '0048_taskstate_finished_by'),
('wagtailcore', '0049_taskstate_finished_by'),
('wagtail_review', '0009_wagtail_workflow'),
]

Expand Down
22 changes: 22 additions & 0 deletions wagtail_review/migrations/0012_rename_comment_to_review_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.0.7 on 2020-06-16 11:57

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('wagtail_review', '0011_groupreviewtask_meta'),
]

run_before = [
('wagtailcore', '0051_taskstate_comment'),
]

operations = [
migrations.RenameField(
model_name='reviewtaskstate',
old_name='comment',
new_name='review_comment',
),
]
30 changes: 30 additions & 0 deletions wagtail_review/migrations/0013_populate_new_comment_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.0.7 on 2020-06-16 11:58

from django.db import migrations


def populate_new_comment_field(apps, schema_editor):
ReviewTaskState = apps.get_model('wagtail_review.ReviewTaskState')

for task_state in ReviewTaskState.objects.only('review_comment'):
task_state.comment = task_state.review_comment
task_state.save(update_fields=['comment'])


def populate_old_comment_field(apps, schema_editor):
ReviewTaskState = apps.get_model('wagtail_review.ReviewTaskState')

for task_state in ReviewTaskState.objects.only('comment'):
task_state.review_comment = task_state.comment
task_state.save(update_fields=['review_comment'])


class Migration(migrations.Migration):

dependencies = [
('wagtail_review', '0012_rename_comment_to_review_comment'),
]

operations = [
migrations.RunPython(populate_new_comment_field, populate_old_comment_field),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.0.7 on 2020-06-16 12:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('wagtail_review', '0013_populate_new_comment_field'),
]

operations = [
migrations.RemoveField(
model_name='reviewtaskstate',
name='review_comment',
),
]
10 changes: 3 additions & 7 deletions wagtail_review/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,9 @@ class ReviewResponse(models.Model):


class ReviewTaskState(TaskState):
comment = models.TextField(blank=True)
reviewer = models.ForeignKey(Reviewer, on_delete=models.CASCADE, related_name='+', null=True)

def _finalise(self, user=None, reviewer=None, comment=''):
self.comment = comment
def _finalise(self, user=None, reviewer=None):
self.reviewer = reviewer
if reviewer and reviewer.internal_id:
self.finished_by_id = reviewer.internal_id
Expand All @@ -357,20 +355,18 @@ def _finalise(self, user=None, reviewer=None, comment=''):
self.finished_at = timezone.now()

@transaction.atomic
def approve(self, user=None, reviewer=None, comment='', **kwargs):
def approve(self, user=None, reviewer=None, **kwargs):
self._finalise(
user=user,
reviewer=reviewer,
comment=comment,
)
super().approve(**kwargs)

@transaction.atomic
def reject(self, user=None, reviewer=None, comment='', **kwargs):
def reject(self, user=None, reviewer=None, **kwargs):
self._finalise(
user=user,
reviewer=reviewer,
comment=comment,
)
super().reject(**kwargs)

Expand Down

0 comments on commit 1734a0e

Please sign in to comment.