Merge pull request from kaedroho/copy-revisions-created-at-bug

Don't overwrite created_at of copied page revisions
pull/744/merge
Matt Westcott 2014-10-24 10:42:48 +01:00
commit 548b10a82a
3 zmienionych plików z 43 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0008_populate_latest_revision_created_at'),
]
operations = [
migrations.AlterField(
model_name='pagerevision',
name='created_at',
field=models.DateTimeField(),
),
]

Wyświetl plik

@ -946,7 +946,7 @@ class SubmittedRevisionsManager(models.Manager):
class PageRevision(models.Model):
page = models.ForeignKey('Page', related_name='revisions')
submitted_for_moderation = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
created_at = models.DateTimeField()
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
content_json = models.TextField()
approved_go_live_at = models.DateTimeField(null=True, blank=True)
@ -955,6 +955,12 @@ class PageRevision(models.Model):
submitted_revisions = SubmittedRevisionsManager()
def save(self, *args, **kwargs):
# Set default value for created_at to now
# We cannot use auto_now_add as that will override
# any value that is set before saving
if self.created_at is None:
self.created_at = timezone.now()
super(PageRevision, self).save(*args, **kwargs)
if self.submitted_for_moderation:
# ensure that all other revisions of this page have the 'submitted for moderation' flag unset

Wyświetl plik

@ -443,6 +443,23 @@ class TestCopyPage(TestCase):
# Check that the new revision is not submitted for moderation
self.assertFalse(new_christmas_event.revisions.first().submitted_for_moderation)
def test_copy_page_copies_revisions_and_doesnt_change_created_at(self):
christmas_event = EventPage.objects.get(url_path='/home/events/christmas/')
christmas_event.save_revision(submitted_for_moderation=True)
# Set the created_at of the revision to a time in the past
revision = christmas_event.get_latest_revision()
revision.created_at = datetime.datetime(2014, 1, 1)
revision.save()
# Copy it
new_christmas_event = christmas_event.copy(update_attrs={'title': "New christmas event", 'slug': 'new-christmas-event'})
# Check that the created_at time is the same
christmas_event_created_at = christmas_event.get_latest_revision().created_at
new_christmas_event_created_at = new_christmas_event.get_latest_revision().created_at
self.assertEqual(christmas_event_created_at, new_christmas_event_created_at)
def test_copy_page_copies_revisions_and_doesnt_schedule(self):
christmas_event = EventPage.objects.get(url_path='/home/events/christmas/')
christmas_event.save_revision(approved_go_live_at=datetime.datetime(2014, 9, 16, 9, 12, 00, tzinfo=pytz.utc))