kopia lustrzana https://github.com/wagtail/wagtail
Refactor default snippets listing buttons to reuse the generic IndexView buttons
rodzic
e9dfca2cf7
commit
1a1fc5c1a7
|
@ -252,6 +252,7 @@ ul.listing {
|
|||
&--inline-actions td.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
|
||||
{% 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 draftstate_enabled %}
|
||||
{% if instance.action == 'wagtail.publish' and revision == object.live_revision %}{% trans 'Live version' as status_label %}{% status status_label classname="w-status--primary" %}
|
||||
{% elif instance.content_changed and revision == latest_revision %}{% trans 'Current draft' as status_label %}{% status status_label classname="w-status--primary" %}{% endif %}
|
||||
{% endif %}
|
||||
<div class="w-flex w-items-center w-gap-2">
|
||||
{{ value }}
|
||||
{% if draftstate_enabled %}
|
||||
{% if instance.action == 'wagtail.publish' and revision == object.live_revision %}{% trans 'Live version' as status_label %}{% status status_label classname="w-status--primary" %}
|
||||
{% elif instance.content_changed and revision == latest_revision %}{% trans 'Current draft' as status_label %}{% status status_label classname="w-status--primary" %}{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<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>
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
{% extends "wagtailadmin/tables/title_cell.html" %}
|
||||
{% load wagtailsnippets_admin_tags %}
|
||||
|
||||
<td class="{% if column.classname %}{{ column.classname }} {% endif %}title">
|
||||
<span class="title-wrapper">
|
||||
{% if link_url %}
|
||||
<a {% include "wagtailadmin/shared/attrs.html" with attrs=link_attrs %}>{{ value }}</a>
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
</span>
|
||||
<ul class="actions">
|
||||
{% snippet_listing_buttons instance %}
|
||||
</ul>
|
||||
</td>
|
||||
{% block buttons %}
|
||||
{% snippet_listing_buttons instance %}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -9,10 +9,7 @@ from wagtail import hooks
|
|||
from wagtail.admin.menu import MenuItem
|
||||
from wagtail.snippets.bulk_actions.delete import DeleteBulkAction
|
||||
from wagtail.snippets.models import get_snippet_models
|
||||
from wagtail.snippets.permissions import (
|
||||
user_can_edit_snippet_type,
|
||||
user_can_edit_snippets,
|
||||
)
|
||||
from wagtail.snippets.permissions import user_can_edit_snippets
|
||||
from wagtail.snippets.views import snippets as snippet_views
|
||||
from wagtail.snippets.widgets import SnippetListingButton
|
||||
|
||||
|
@ -66,17 +63,6 @@ def register_snippet_listing_buttons(snippet, user, next_url=None):
|
|||
viewset = model.snippet_viewset
|
||||
permission_policy = viewset.permission_policy
|
||||
|
||||
if user_can_edit_snippet_type(user, model):
|
||||
yield SnippetListingButton(
|
||||
_("Edit"),
|
||||
reverse(
|
||||
viewset.get_url_name("edit"),
|
||||
args=[quote(snippet.pk)],
|
||||
),
|
||||
attrs={"aria-label": _("Edit '%(title)s'") % {"title": str(snippet)}},
|
||||
priority=10,
|
||||
)
|
||||
|
||||
if viewset.inspect_view_enabled and permission_policy.user_has_any_permission(
|
||||
user, viewset.inspect_view_class.any_permission_required
|
||||
):
|
||||
|
@ -90,17 +76,5 @@ def register_snippet_listing_buttons(snippet, user, next_url=None):
|
|||
priority=20,
|
||||
)
|
||||
|
||||
if permission_policy.user_has_permission(user, "delete"):
|
||||
yield SnippetListingButton(
|
||||
_("Delete"),
|
||||
reverse(
|
||||
viewset.get_url_name("delete"),
|
||||
args=[quote(snippet.pk)],
|
||||
),
|
||||
attrs={"aria-label": _("Delete '%(title)s'") % {"title": str(snippet)}},
|
||||
priority=30,
|
||||
classname="no",
|
||||
)
|
||||
|
||||
|
||||
hooks.register("register_bulk_action", DeleteBulkAction)
|
||||
|
|
Ładowanie…
Reference in New Issue