Show draft/live status tags on snippet history only if DraftStateMixin is applied

pull/9172/head
Sage Abdullah 2022-09-08 14:18:43 +01:00 zatwierdzone przez Matt Westcott
rodzic c0ae976471
commit eb2ebca0af
3 zmienionych plików z 27 dodań i 4 usunięć

Wyświetl plik

@ -4,8 +4,10 @@
{% if revision_enabled and instance.revision %}
{% with revision=instance.revision latest_revision=object.get_latest_revision previous_revision=instance.revision.get_previous %}
<span>{{ value }}</span>
{% if instance.action == 'wagtail.publish' and revision == object.live_revision %}<span class="status-tag primary">{% trans 'Live version' %}</span>
{% elif instance.content_changed and revision == latest_revision %}<span class="status-tag primary">{% trans 'Current draft' %}</span>{% endif %}
{% if draftstate_enabled %}
{% if instance.action == 'wagtail.publish' and revision == object.live_revision %}<span class="status-tag primary">{% trans 'Live version' %}</span>
{% elif instance.content_changed and revision == latest_revision %}<span class="status-tag primary">{% trans 'Current draft' %}</span>{% endif %}
{% endif %}
<ul class="actions">
{% if preview_enabled and object.is_previewable %}
<li><a href="{% url view.revisions_view_url_name object.pk|admin_urlquote revision.pk %}" class="button button-small button-secondary" target="_blank" rel="noreferrer">{% trans 'Preview' %}</a></li>

Wyświetl plik

@ -2260,6 +2260,14 @@ class TestSnippetHistory(TestCase, WagtailTestUtils):
args=[self.revisable_snippet.pk, self.initial_revision.pk],
)
# Should not show the "live version" or "current draft" status tags
self.assertNotContains(
response, '<span class="status-tag primary">Live version</span>'
)
self.assertNotContains(
response, '<span class="status-tag primary">Current draft</span>'
)
# The latest revision should have an "Edit" action instead of "Review"
self.assertContains(
response,
@ -2274,14 +2282,26 @@ class TestSnippetHistory(TestCase, WagtailTestUtils):
count=1,
)
def test_use_latest_draft_as_title(self):
def test_with_live_and_draft_status(self):
snippet = DraftStateModel.objects.create(text="Draft-enabled Foo, Published")
snippet.save_revision().publish()
snippet.refresh_from_db()
snippet.text = "Draft-enabled Bar, In Draft"
snippet.save_revision()
snippet.save_revision(log_action=True)
response = self.get(snippet)
# Should show the "live version" status tag for the published revision
self.assertContains(
response, '<span class="status-tag primary">Live version</span>', count=1
)
# Should show the "current draft" status tag for the draft revision
self.assertContains(
response, '<span class="status-tag primary">Current draft</span>', count=1
)
# Should use the latest draft title in the header subtitle
self.assertContains(
response,

Wyświetl plik

@ -582,6 +582,7 @@ class ActionColumn(Column):
def get_cell_context_data(self, instance, parent_context):
context = super().get_cell_context_data(instance, parent_context)
context["revision_enabled"] = isinstance(self.object, RevisionMixin)
context["draftstate_enabled"] = isinstance(self.object, DraftStateMixin)
context["preview_enabled"] = isinstance(self.object, PreviewableMixin)
context["object"] = self.object
context["view"] = self.view