Skip to content

Commit c2c878d

Browse files
committed
When putting an experiment live, ensure that any unpublished alternative pages have their latest draft revisions copied to the live table
The live table is not routinely updated while the page is in draft, so this step ensures that the version shown is an up-to-date one.
1 parent a08c352 commit c2c878d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

experiments/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ class Experiment(ClusterableModel):
4848
FieldPanel('status'),
4949
]
5050

51+
def __init__(self, *args, **kwargs):
52+
super(Experiment, self).__init__(*args, **kwargs)
53+
self._initial_status = self.status
54+
55+
def save(self, *args, **kwargs):
56+
result = super(Experiment, self).save(*args, **kwargs)
57+
if self._initial_status == 'draft' and self.status == 'live':
58+
# For any alternative pages that are unpublished, copy the latest draft revision
59+
# to the main table (with is_live=False) so that the revision shown as an alternative
60+
# is not an out-of-date one
61+
for alternative in self.alternatives.select_related('page'):
62+
if not alternative.page.live:
63+
revision = alternative.page.get_latest_revision_as_page()
64+
revision.live = False
65+
revision.has_unpublished_changes = True
66+
revision.save()
67+
68+
return result
69+
5170
def get_variations(self):
5271
return [self.control_page] + [alt.page for alt in self.alternatives.select_related('page')]
5372

0 commit comments

Comments
 (0)