def page_listing_buttons(page, page_perms, is_parent=False, next_url=None): if page_perms.can_edit(): yield PageListingButton( _('Edit'), reverse('wagtailadmin_pages:edit', args=[page.id]), attrs={'aria-label': _("Edit '%(title)s'") % {'title': page.get_admin_display_title()}}, priority=10 ) if page.has_unpublished_changes and page.is_previewable(): yield PageListingButton( _('View draft'), reverse('wagtailadmin_pages:view_draft', args=[page.id]), attrs={ 'aria-label': _("Preview draft version of '%(title)s'") % {'title': page.get_admin_display_title()}, 'target': '_blank', 'rel': 'noopener noreferrer' }, priority=20 ) if page.live and page.url: yield PageListingButton( _('View live'), page.url, attrs={ 'target': "_blank", 'rel': 'noopener noreferrer', 'aria-label': _("View live version of '%(title)s'") % {'title': page.get_admin_display_title()}, }, priority=30 ) if page_perms.can_add_subpage(): if is_parent: yield Button( _('Add child page'), reverse('wagtailadmin_pages:add_subpage', args=[page.id]), attrs={ 'aria-label': _("Add a child page to '%(title)s' ") % {'title': page.get_admin_display_title()}, }, classes={'button', 'button-small', 'bicolor', 'icon', 'white', 'icon-plus'}, priority=40 ) else: yield PageListingButton( _('Add child page'), reverse('wagtailadmin_pages:add_subpage', args=[page.id]), attrs={'aria-label': _("Add a child page to '%(title)s' ") % {'title': page.get_admin_display_title()}}, priority=40 ) yield ButtonWithDropdownFromHook( _('More'), hook_name='register_page_listing_more_buttons', page=page, page_perms=page_perms, is_parent=is_parent, next_url=next_url, attrs={ 'target': '_blank', 'rel': 'noopener noreferrer', 'title': _("View more options for '%(title)s'") % {'title': page.get_admin_display_title()} }, priority=50 )
def joplin_page_listing_buttons(page, page_perms, is_parent=False): if page_perms.can_edit(): yield PageListingButton( _('Edit'), reverse('wagtailadmin_pages:edit', args=[page.id]), attrs={'title': _("Edit '{title}'").format( title=page.get_admin_display_title())}, priority=10 ) if page.has_unpublished_changes: try: yield PageListingButton( _('View draft'), page.janis_preview_url(), attrs={'title': _("Preview draft version of '{title}'").format( title=page.get_admin_display_title()), 'target': '_blank'}, priority=20 ) except Exception as e: raise e if page.live and page.url and hasattr(page, 'janis_url'): yield PageListingButton( _('View live'), page.janis_url(), attrs={'target': "_blank", 'title': _("View live version of '{title}'").format( title=page.get_admin_display_title())}, priority=30 ) # make the author notes icon appear if latest revision has notes latest_revision_as_page = page.get_latest_revision_as_page() if hasattr(latest_revision_as_page, 'author_notes') and latest_revision_as_page.author_notes: yield Button( _('📝'), 'javascript:null;', attrs={'title': _("Notes for authors entered"), 'class': 'has-author-notes'}, priority=70 ) yield ButtonWithDropdownFromHook( _('More'), hook_name='register_joplin_page_listing_more_buttons', page=page, page_perms=page_perms, is_parent=is_parent, attrs={'target': '_blank', 'title': _("View more options for '{title}'").format( title=page.get_admin_display_title())}, priority=50 )
def test_get_button_url_name_internal_url(page): button = PageListingButton( 'View draft', reverse('wagtailadmin_pages:view_draft', args=[page.id]), ) assert helpers.get_button_url_name(button) == 'view_draft'
def update_default_listing_buttons(page, page_perms, is_parent=False): buttons = list(page_listing_buttons(page, page_perms, is_parent)) if isinstance(page, models.BasePage): for button in buttons: if helpers.get_button_url_name(button) == 'view_draft': button.url = page.get_url(is_draft=True) else: # limit buttons for non-subclasses-of-BasePage allowed_urls = ['add_subpage'] buttons = [ button for button in buttons if helpers.get_button_url_name(button) in allowed_urls ] # since the drop-down is removed by the above, add a delete # button to this list if page_perms.can_delete(): buttons.append( PageListingButton( 'Delete', reverse('wagtailadmin_pages:delete', args=[page.id]), attrs={ 'title': "Delete '%s'" % page.get_admin_display_title() }, )) return buttons
def bulk_action_choices(context, app_label, model_name): bulk_actions_list = list( bulk_action_registry.get_bulk_actions_for_model(app_label, model_name) ) bulk_actions_list.sort(key=lambda x: x.action_priority) bulk_action_more_list = [] if len(bulk_actions_list) > 4: bulk_action_more_list = bulk_actions_list[4:] bulk_actions_list = bulk_actions_list[:4] next_url = get_valid_next_url_from_request(context["request"]) if not next_url: next_url = context["request"].path bulk_action_buttons = [ PageListingButton( action.display_name, reverse( "wagtail_bulk_action", args=[app_label, model_name, action.action_type] ) + "?" + urlencode({"next": next_url}), attrs={"aria-label": action.aria_label}, priority=action.action_priority, classes=action.classes | {"bulk-action-btn"}, ) for action in bulk_actions_list ] if bulk_action_more_list: more_button = ButtonWithDropdown( label=_("More"), attrs={"title": _("View more bulk actions")}, classes={"bulk-actions-more", "dropup"}, button_classes={"button", "button-small"}, buttons_data=[ { "label": action.display_name, "url": reverse( "wagtail_bulk_action", args=[app_label, model_name, action.action_type], ) + "?" + urlencode({"next": next_url}), "attrs": {"aria-label": action.aria_label}, "priority": action.action_priority, "classes": {"bulk-action-btn"}, } for action in bulk_action_more_list ], ) more_button.is_parent = True bulk_action_buttons.append(more_button) return {"buttons": bulk_action_buttons}
def bulk_action_choices(context, app_label, model_name): bulk_actions_list = list( bulk_action_registry.get_bulk_actions_for_model(app_label, model_name)) bulk_actions_list.sort(key=lambda x: x.action_priority) bulk_action_more_list = [] if len(bulk_actions_list) > 4: bulk_action_more_list = bulk_actions_list[4:] bulk_actions_list = bulk_actions_list[:4] next_url = get_valid_next_url_from_request(context['request']) if not next_url: next_url = context['request'].path bulk_action_buttons = [ PageListingButton( action.display_name, reverse('wagtail_bulk_action', args=[app_label, model_name, action.action_type]) + '?' + urlencode({'next': next_url}), attrs={'aria-label': action.aria_label}, priority=action.action_priority, classes=action.classes | {'bulk-action-btn'}, ) for action in bulk_actions_list ] if bulk_action_more_list: more_button = ButtonWithDropdown( label=_("More"), attrs={'title': _("View more bulk actions")}, classes={'bulk-actions-more', 'dropup'}, button_classes={'button', 'button-small'}, buttons_data=[{ 'label': action.display_name, 'url': reverse('wagtail_bulk_action', args=[app_label, model_name, action.action_type]) + '?' + urlencode({'next': next_url}), 'attrs': { 'aria-label': action.aria_label }, 'priority': action.action_priority, 'classes': {'bulk-action-btn'}, } for action in bulk_action_more_list]) more_button.is_parent = True bulk_action_buttons.append(more_button) return {'buttons': bulk_action_buttons}
def test_get_button_url_name_external_url(): button = PageListingButton('View draft', 'http://www.example.com') assert helpers.get_button_url_name(button) is None
def page_listing_buttons(page, page_perms, is_parent=False, next_url=None): if page_perms.can_edit(): yield PageListingButton( _("Edit"), reverse("wagtailadmin_pages:edit", args=[page.id]), attrs={ "aria-label": _("Edit '%(title)s'") % { "title": page.get_admin_display_title() } }, priority=10, ) if page.has_unpublished_changes and page.is_previewable(): yield PageListingButton( _("View draft"), reverse("wagtailadmin_pages:view_draft", args=[page.id]), attrs={ "aria-label": _("Preview draft version of '%(title)s'") % { "title": page.get_admin_display_title() }, "rel": "noreferrer", }, priority=20, ) if page.live and page.url: yield PageListingButton( _("View live"), page.url, attrs={ "rel": "noreferrer", "aria-label": _("View live version of '%(title)s'") % { "title": page.get_admin_display_title() }, }, priority=30, ) if page_perms.can_add_subpage(): if is_parent: yield Button( _("Add child page"), reverse("wagtailadmin_pages:add_subpage", args=[page.id]), attrs={ "aria-label": _("Add a child page to '%(title)s' ") % { "title": page.get_admin_display_title() }, }, classes={ "button", "button-small", "bicolor", "icon", "white", "icon-plus", }, priority=40, ) else: yield PageListingButton( _("Add child page"), reverse("wagtailadmin_pages:add_subpage", args=[page.id]), attrs={ "aria-label": _("Add a child page to '%(title)s' ") % { "title": page.get_admin_display_title() } }, priority=40, ) yield ButtonWithDropdownFromHook( _("More"), hook_name="register_page_listing_more_buttons", page=page, page_perms=page_perms, is_parent=is_parent, next_url=next_url, attrs={ "target": "_blank", "rel": "noreferrer", "title": _("View more options for '%(title)s'") % { "title": page.get_admin_display_title() }, }, priority=50, )
def joplin_page_listing_buttons(page, page_perms, is_parent=False): if page_perms.can_edit(): yield PageListingButton(_('Edit'), reverse('wagtailadmin_pages:edit', args=[page.id]), attrs={ 'title': _("Edit '{title}'").format( title=page.get_admin_display_title()) }, priority=10) if page.has_unpublished_changes: yield PageListingButton( _('View draft'), page.janis_preview_url(), attrs={ 'title': _("Preview draft version of '{title}'").format( title=page.get_admin_display_title()), 'target': '_blank' }, priority=20) if page.live and page.url and hasattr(page, 'janis_url'): yield PageListingButton(_('View live'), page.janis_url(), attrs={ 'target': "_blank", 'title': _("View live version of '{title}'").format( title=page.get_admin_display_title()) }, priority=30) # This is kinda hacky but it should let us know when we have notes on a revision latest_revision = None all_revisions = PageRevision.objects.filter(page_id=page.id) for revision in all_revisions: if revision.is_latest_revision(): latest_revision = revision if latest_revision: author_notes = latest_revision.as_page_object().author_notes # Following this: https://docs.python.org/3/library/html.parser.html#examples parser = CheckForDataInHTMLParser() parser.feed(author_notes) if parser.has_data: yield Button( _('📝'), 'javascript:alert("Wouldn\'t it be cool if this linked to the notes?");', attrs={ 'title': _("Notes for authors entered"), 'class': 'has-author-notes' }, priority=70) yield ButtonWithDropdownFromHook( _('More'), hook_name='register_joplin_page_listing_more_buttons', page=page, page_perms=page_perms, is_parent=is_parent, attrs={ 'target': '_blank', 'title': _("View more options for '{title}'").format( title=page.get_admin_display_title()) }, priority=50)