kopia lustrzana https://github.com/wagtail/wagtail
Merge pull request #732 from kaedroho/copy-revisions-created-at-bug
Don't overwrite created_at of copied page revisionspull/744/merge
commit
548b10a82a
|
@ -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(),
|
||||||
|
),
|
||||||
|
]
|
|
@ -946,7 +946,7 @@ class SubmittedRevisionsManager(models.Manager):
|
||||||
class PageRevision(models.Model):
|
class PageRevision(models.Model):
|
||||||
page = models.ForeignKey('Page', related_name='revisions')
|
page = models.ForeignKey('Page', related_name='revisions')
|
||||||
submitted_for_moderation = models.BooleanField(default=False)
|
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)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
|
||||||
content_json = models.TextField()
|
content_json = models.TextField()
|
||||||
approved_go_live_at = models.DateTimeField(null=True, blank=True)
|
approved_go_live_at = models.DateTimeField(null=True, blank=True)
|
||||||
|
@ -955,6 +955,12 @@ class PageRevision(models.Model):
|
||||||
submitted_revisions = SubmittedRevisionsManager()
|
submitted_revisions = SubmittedRevisionsManager()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
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)
|
super(PageRevision, self).save(*args, **kwargs)
|
||||||
if self.submitted_for_moderation:
|
if self.submitted_for_moderation:
|
||||||
# ensure that all other revisions of this page have the 'submitted for moderation' flag unset
|
# ensure that all other revisions of this page have the 'submitted for moderation' flag unset
|
||||||
|
|
|
@ -443,6 +443,23 @@ class TestCopyPage(TestCase):
|
||||||
# Check that the new revision is not submitted for moderation
|
# Check that the new revision is not submitted for moderation
|
||||||
self.assertFalse(new_christmas_event.revisions.first().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):
|
def test_copy_page_copies_revisions_and_doesnt_schedule(self):
|
||||||
christmas_event = EventPage.objects.get(url_path='/home/events/christmas/')
|
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))
|
christmas_event.save_revision(approved_go_live_at=datetime.datetime(2014, 9, 16, 9, 12, 00, tzinfo=pytz.utc))
|
||||||
|
|
Ładowanie…
Reference in New Issue