mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Add support for previewing snippet revisions
This commit is contained in:
parent
4c26421b1f
commit
718e5c6a02
@ -7,6 +7,9 @@
|
||||
{% 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 %}
|
||||
<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>
|
||||
{% endif %}
|
||||
{% if revision == latest_revision %}
|
||||
<li><a href="{% url view.edit_url_name object.pk|admin_urlquote %}" class="button button-small button-secondary">{% trans 'Edit' %}</a></li>
|
||||
{% else %}
|
||||
|
@ -23,7 +23,11 @@ from wagtail.admin.views.generic import CreateView, DeleteView, EditView, IndexV
|
||||
from wagtail.admin.views.generic.mixins import RevisionsRevertMixin
|
||||
from wagtail.admin.views.generic.models import RevisionsCompareView
|
||||
from wagtail.admin.views.generic.permissions import PermissionCheckedMixin
|
||||
from wagtail.admin.views.generic.preview import PreviewOnCreate, PreviewOnEdit
|
||||
from wagtail.admin.views.generic.preview import (
|
||||
PreviewOnCreate,
|
||||
PreviewOnEdit,
|
||||
PreviewRevision,
|
||||
)
|
||||
from wagtail.admin.views.reports.base import ReportView
|
||||
from wagtail.admin.viewsets.base import ViewSet
|
||||
from wagtail.log_actions import log
|
||||
@ -521,6 +525,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["preview_enabled"] = isinstance(self.object, PreviewableMixin)
|
||||
context["object"] = self.object
|
||||
context["view"] = self.view
|
||||
return context
|
||||
@ -530,6 +535,7 @@ class History(ReportView):
|
||||
view_name = "history"
|
||||
index_url_name = None
|
||||
edit_url_name = None
|
||||
revisions_view_url_name = None
|
||||
revisions_revert_url_name = None
|
||||
revisions_compare_url_name = None
|
||||
any_permission_required = ["add", "change", "delete"]
|
||||
@ -574,6 +580,10 @@ class History(ReportView):
|
||||
)
|
||||
|
||||
|
||||
class RevisionsView(PermissionCheckedMixin, PreviewRevision):
|
||||
permission_required = "change"
|
||||
|
||||
|
||||
class RevisionsCompare(PermissionCheckedMixin, RevisionsCompareView):
|
||||
permission_required = "change"
|
||||
header_icon = "snippet"
|
||||
@ -598,6 +608,7 @@ class SnippetViewSet(ViewSet):
|
||||
delete_view_class = Delete
|
||||
usage_view_class = Usage
|
||||
history_view_class = History
|
||||
revisions_view_class = RevisionsView
|
||||
revisions_compare_view_class = RevisionsCompare
|
||||
preview_on_add_view_class = PreviewOnCreate
|
||||
preview_on_edit_view_class = PreviewOnEdit
|
||||
@ -688,10 +699,18 @@ class SnippetViewSet(ViewSet):
|
||||
permission_policy=self.permission_policy,
|
||||
index_url_name=self.get_url_name("list"),
|
||||
edit_url_name=self.get_url_name("edit"),
|
||||
revisions_view_url_name=self.get_url_name("revisions_view"),
|
||||
revisions_revert_url_name=self.get_url_name("revisions_revert"),
|
||||
revisions_compare_url_name=self.get_url_name("revisions_compare"),
|
||||
)
|
||||
|
||||
@property
|
||||
def revisions_view(self):
|
||||
return self.revisions_view_class.as_view(
|
||||
model=self.model,
|
||||
permission_policy=self.permission_policy,
|
||||
)
|
||||
|
||||
@property
|
||||
def revisions_revert(self):
|
||||
return self.revisions_revert_view_class.as_view(
|
||||
@ -764,6 +783,15 @@ class SnippetViewSet(ViewSet):
|
||||
]
|
||||
|
||||
if issubclass(self.model, RevisionMixin):
|
||||
if issubclass(self.model, PreviewableMixin):
|
||||
urlpatterns += [
|
||||
path(
|
||||
"history/<str:pk>/revisions/<int:revision_id>/view/",
|
||||
self.revisions_view,
|
||||
name="revisions_view",
|
||||
)
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
path(
|
||||
"history/<str:pk>/revisions/<int:revision_id>/revert/",
|
||||
|
Loading…
Reference in New Issue
Block a user