mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge branch 'page-published-date' of https://github.com/kaedroho/wagtail into kaedroho-page-published-date
This commit is contained in:
commit
651dd4d9f3
@ -212,6 +212,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
self.assertEqual(page.title, post_data['title'])
|
||||
self.assertIsInstance(page, SimplePage)
|
||||
self.assertFalse(page.live)
|
||||
self.assertFalse(page.first_published_at)
|
||||
|
||||
# treebeard should report no consistency problems with the tree
|
||||
self.assertFalse(any(Page.find_problems()), 'treebeard found consistency problems')
|
||||
@ -298,6 +299,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
self.assertEqual(page.title, post_data['title'])
|
||||
self.assertIsInstance(page, SimplePage)
|
||||
self.assertTrue(page.live)
|
||||
self.assertTrue(page.first_published_at)
|
||||
|
||||
# Check that the page_published signal was fired
|
||||
self.assertTrue(signal_fired[0])
|
||||
@ -333,6 +335,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
self.assertTrue(PageRevision.objects.filter(page=page).exclude(approved_go_live_at__isnull=True).exists())
|
||||
# But Page won't be live
|
||||
self.assertFalse(page.live)
|
||||
self.assertFalse(page.first_published_at)
|
||||
self.assertTrue(page.status_string, "scheduled")
|
||||
|
||||
def test_create_simplepage_post_submit(self):
|
||||
@ -357,6 +360,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
self.assertEqual(page.title, post_data['title'])
|
||||
self.assertIsInstance(page, SimplePage)
|
||||
self.assertFalse(page.live)
|
||||
self.assertFalse(page.first_published_at)
|
||||
|
||||
# The latest revision for the page should now be in moderation
|
||||
self.assertTrue(page.get_latest_revision().submitted_for_moderation)
|
||||
@ -438,12 +442,13 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
||||
self.root_page = Page.objects.get(id=2)
|
||||
|
||||
# Add child page
|
||||
self.child_page = SimplePage()
|
||||
self.child_page.title = "Hello world!"
|
||||
self.child_page.slug = "hello-world"
|
||||
self.child_page.live = True
|
||||
self.root_page.add_child(instance=self.child_page)
|
||||
self.child_page.save_revision()
|
||||
child_page = SimplePage(
|
||||
title="Hello world!",
|
||||
slug="hello-world",
|
||||
)
|
||||
self.root_page.add_child(instance=child_page)
|
||||
child_page.save_revision().publish()
|
||||
self.child_page = SimplePage.objects.get(id=child_page.id)
|
||||
|
||||
# Add event page (to test edit handlers)
|
||||
self.event_page = EventPage()
|
||||
@ -584,6 +589,9 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
||||
self.child_page.has_unpublished_changes = True
|
||||
self.child_page.save()
|
||||
|
||||
# Save current value of first_published_at so we can check that it doesn't change
|
||||
first_published_at = SimplePage.objects.get(id=self.child_page.id).first_published_at
|
||||
|
||||
# Tests publish from edit page
|
||||
post_data = {
|
||||
'title': "I've been edited!",
|
||||
@ -608,6 +616,9 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
||||
# The page shouldn't have "has_unpublished_changes" flag set
|
||||
self.assertFalse(child_page_new.has_unpublished_changes)
|
||||
|
||||
# first_published_at should not change as it was already set
|
||||
self.assertEqual(first_published_at, child_page_new.first_published_at)
|
||||
|
||||
def test_edit_post_publish_scheduled(self):
|
||||
go_live_at = timezone.now() + timedelta(days=1)
|
||||
expire_at = timezone.now() + timedelta(days=2)
|
||||
|
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0010_change_page_owner_to_null_on_delete'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='page',
|
||||
name='first_published_at',
|
||||
field=models.DateTimeField(editable=False, null=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
@ -284,6 +284,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
|
||||
|
||||
locked = models.BooleanField(default=False, editable=False)
|
||||
|
||||
first_published_at = models.DateTimeField(null=True, editable=False)
|
||||
latest_revision_created_at = models.DateTimeField(null=True, editable=False)
|
||||
|
||||
search_fields = (
|
||||
@ -1099,6 +1100,7 @@ class PageRevision(models.Model):
|
||||
obj.owner = self.page.owner
|
||||
obj.locked = self.page.locked
|
||||
obj.latest_revision_created_at = self.page.latest_revision_created_at
|
||||
obj.first_published_at = self.page.first_published_at
|
||||
|
||||
return obj
|
||||
|
||||
@ -1139,6 +1141,11 @@ class PageRevision(models.Model):
|
||||
# If page goes live clear the approved_go_live_at of all revisions
|
||||
page.revisions.update(approved_go_live_at=None)
|
||||
page.expired = False # When a page is published it can't be expired
|
||||
|
||||
# Set first_published_at if the page is being published now
|
||||
if page.live and page.first_published_at is None:
|
||||
page.first_published_at = timezone.now()
|
||||
|
||||
page.save()
|
||||
self.submitted_for_moderation = False
|
||||
page.revisions.update(submitted_for_moderation=False)
|
||||
|
@ -188,6 +188,7 @@ class TestPublishScheduledPagesCommand(TestCase):
|
||||
|
||||
p = Page.objects.get(slug='hello-world')
|
||||
self.assertTrue(p.live)
|
||||
self.assertTrue(p.first_published_at)
|
||||
self.assertFalse(p.has_unpublished_changes)
|
||||
self.assertFalse(PageRevision.objects.filter(page=p).exclude(approved_go_live_at__isnull=True).exists())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user