Add live_revisions fk on Page, tests, migrations, update template

pull/3418/merge
Matheus Bratfisch 2017-01-27 10:15:58 +13:00 zatwierdzone przez Matt Westcott
rodzic 1f8edc8984
commit 41c8bfced9
6 zmienionych plików z 88 dodań i 2 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ Changelog
* Added a new page explorer menu built with the admin API and React (Karl Hobley, Josh Barr, Thibaud Colas, Janneke Janssen, Rob Moorman, Maurice Bartnig, Jonny Scholes, Matt Westcott, Sævar Öfjörð Magnússon, Eirikur Ingi Magnusson, Harris Lapiroff, Hugo van den Berg, Olly Willans, Andy Babic, Ben Enright, Bertrand Bordage) * Added a new page explorer menu built with the admin API and React (Karl Hobley, Josh Barr, Thibaud Colas, Janneke Janssen, Rob Moorman, Maurice Bartnig, Jonny Scholes, Matt Westcott, Sævar Öfjörð Magnússon, Eirikur Ingi Magnusson, Harris Lapiroff, Hugo van den Berg, Olly Willans, Andy Babic, Ben Enright, Bertrand Bordage)
* Optimised page URL generation by caching site paths in the request scope (Tobias McNulty, Matt Westcott) * Optimised page URL generation by caching site paths in the request scope (Tobias McNulty, Matt Westcott)
* The current live version of a page is now tracked on the revision listing view (Matheus Bratfisch)
* Fix: Unauthenticated AJAX requests to admin views now return 403 rather than redirecting to the login page (Karl Hobley) * Fix: Unauthenticated AJAX requests to admin views now return 403 rather than redirecting to the login page (Karl Hobley)
* Fix: `TableBlock` options `afterChange`, `afterCreateCol`, `afterCreateRow`, `afterRemoveCol`, `afterRemoveRow` and `contextMenu` can now be overridden (Loic Teixeira) * Fix: `TableBlock` options `afterChange`, `afterCreateCol`, `afterCreateRow`, `afterRemoveCol`, `afterRemoveRow` and `contextMenu` can now be overridden (Loic Teixeira)

Wyświetl plik

@ -45,6 +45,7 @@ Other features
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
* Optimised page URL generation by caching site paths in the request scope (Tobias McNulty, Matt Westcott) * Optimised page URL generation by caching site paths in the request scope (Tobias McNulty, Matt Westcott)
* The current live version of a page is now tracked on the revision listing view (Matheus Bratfisch)
Bug fixes Bug fixes

Wyświetl plik

@ -14,7 +14,14 @@
{% for revision in revisions %} {% for revision in revisions %}
<tr {% if revision == page.get_latest_revision %}class="index"{% endif %}> <tr {% if revision == page.get_latest_revision %}class="index"{% endif %}>
<td class="title"> <td class="title">
<h2><a href="{% url 'wagtailadmin_pages:revisions_revert' page.id revision.id %}">{{ revision.created_at }}</a> <span class="unbold">{% trans 'by' context 'points to a user who created a revision' %}<span class="avatar small"><img src="{% gravatar_url revision.user.email 25 %}" /></span>{{ revision.user }}</span> {% if revision == page.get_latest_revision %}({% trans 'Current draft' %}){% endif %}</h2> <h2>
<a href="{% url 'wagtailadmin_pages:revisions_revert' page.id revision.id %}">{{ revision.created_at }}</a>
<span class="unbold">
{% trans 'by' context 'points to a user who created a revision' %}<span class="avatar small"><img src="{% gravatar_url revision.user.email 25 %}" /></span>{{ revision.user }}
</span>
{% if revision == page.get_latest_revision %}({% trans 'Current draft' %}){% endif %}
{% if revision == page.live_revision %}({% trans 'Live version' %}){% endif %}
</h2>
<ul class="actions"> <ul class="actions">
<li><a href="{% url 'wagtailadmin_pages:revisions_view' page.id revision.id %}" class="button button-small button-secondary" target="_blank">{% trans 'Preview' %}</a></li> <li><a href="{% url 'wagtailadmin_pages:revisions_view' page.id revision.id %}" class="button button-small button-secondary" target="_blank">{% trans 'Preview' %}</a></li>

Wyświetl plik

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-26 21:32
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0033_remove_golive_expiry_help_text'),
]
operations = [
migrations.AddField(
model_name='page',
name='live_revision',
field=models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.PageRevision', verbose_name='live revision'),
),
]

Wyświetl plik

@ -327,6 +327,15 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
null=True, null=True,
editable=False editable=False
) )
live_revision = models.ForeignKey(
'PageRevision',
related_name='+',
verbose_name='live revision',
on_delete=models.SET_NULL,
null=True,
blank=True,
editable=False
)
search_fields = [ search_fields = [
index.SearchField('title', partial_match=True, boost=2), index.SearchField('title', partial_match=True, boost=2),
@ -701,6 +710,7 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
if self.live: if self.live:
self.live = False self.live = False
self.has_unpublished_changes = True self.has_unpublished_changes = True
self.live_revision = None
if set_expired: if set_expired:
self.expired = True self.expired = True
@ -1081,6 +1091,7 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
if not keep_live: if not keep_live:
page_copy.live = False page_copy.live = False
page_copy.has_unpublished_changes = True page_copy.has_unpublished_changes = True
page_copy.live_revision = None
if user: if user:
page_copy.owner = user page_copy.owner = user
@ -1162,7 +1173,10 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
for field, value in update_attrs.items(): for field, value in update_attrs.items():
setattr(latest_revision, field, value) setattr(latest_revision, field, value)
latest_revision.save_revision(user=user, changed=False) latest_revision_as_page_revision = latest_revision.save_revision(user=user, changed=False)
if keep_live:
page_copy.live_revision = latest_revision_as_page_revision
page_copy.save()
# Log # Log
logger.info("Page copied: \"%s\" id=%d from=%d", page_copy.title, page_copy.id, self.id) logger.info("Page copied: \"%s\" id=%d from=%d", page_copy.title, page_copy.id, self.id)
@ -1495,6 +1509,7 @@ class PageRevision(models.Model):
if page.live and page.first_published_at is None: if page.live and page.first_published_at is None:
page.first_published_at = timezone.now() page.first_published_at = timezone.now()
page.live_revision = self
page.save() page.save()
self.submitted_for_moderation = False self.submitted_for_moderation = False
page.revisions.update(submitted_for_moderation=False) page.revisions.update(submitted_for_moderation=False)

Wyświetl plik

@ -545,6 +545,47 @@ class TestPrevNextSiblings(TestCase):
self.assertEqual(final_event.get_prev_siblings(inclusive=True).first(), final_event) self.assertEqual(final_event.get_prev_siblings(inclusive=True).first(), final_event)
class TestLiveRevision(TestCase):
fixtures = ['test.json']
def test_publish_method_will_set_live_revision(self):
page = Page.objects.get(id=1)
revision = page.save_revision()
revision.publish()
page.refresh_from_db()
self.assertEqual(page.live_revision, revision)
def test_unpublish_method_will_clean_live_revision(self):
page = Page.objects.get(id=1)
revision = page.save_revision()
revision.publish()
page.unpublish()
page.refresh_from_db()
self.assertIsNone(page.live_revision)
def test_copy_method_with_keep_live_will_update_live_revision(self):
about_us = SimplePage.objects.get(url_path='/home/about-us/')
revision = about_us.save_revision()
revision.publish()
new_about_us = about_us.copy(keep_live=True, update_attrs={'title': "New about us", 'slug': 'new-about-us'})
self.assertIsNotNone(new_about_us.live_revision)
self.assertNotEqual(about_us.live_revision, new_about_us.live_revision)
def test_copy_method_without_keep_live_will_not_update_live_revision(self):
about_us = SimplePage.objects.get(url_path='/home/about-us/')
revision = about_us.save_revision()
revision.publish()
new_about_us = about_us.copy(keep_live=False, update_attrs={'title': "New about us", 'slug': 'new-about-us'})
self.assertIsNone(new_about_us.live_revision)
class TestCopyPage(TestCase): class TestCopyPage(TestCase):
fixtures = ['test.json'] fixtures = ['test.json']