コード例 #1
0
def page_listing_more_buttons(page,
                              page_perms,
                              is_parent=False,
                              next_url=None):
    if page_perms.user.has_perm(
            'wagtail_localize.submit_translation') and not page.is_root():
        # If there's at least one locale that we haven't translated into yet, show "Translate this page" button
        has_locale_to_translate_to = Locale.objects.exclude(
            id__in=page.get_translations(inclusive=True).exclude(
                alias_of__isnull=False).values_list('locale_id',
                                                    flat=True)).exists()

        if has_locale_to_translate_to:
            url = reverse("wagtail_localize:submit_page_translation",
                          args=[page.id])
            if next_url is not None:
                url += '?' + urlencode({'next': next_url})

            yield wagtailadmin_widgets.Button(_("Translate this page"),
                                              url,
                                              priority=60)

        # If the page is the source for translations, show "Sync translated pages" button
        source = TranslationSource.objects.get_for_instance_or_none(page)
        if source is not None and source.translations.filter(
                enabled=True).exists():
            url = reverse("wagtail_localize:update_translations",
                          args=[source.id])
            if next_url is not None:
                url += '?' + urlencode({'next': next_url})

            yield wagtailadmin_widgets.Button(_("Sync translated pages"),
                                              url,
                                              priority=65)
コード例 #2
0
def page_listing_more_buttons(page,
                              page_perms,
                              is_parent=False,
                              next_url=None):
    yield wagtailadmin_widgets.Button(
        'Re-publish to a Release',
        '/crc-cms/pages/%d/republish-page-and-children/' % (page.id),
        priority=60)
    yield wagtailadmin_widgets.Button(
        'Un-publish from a Release',
        '/crc-cms/pages/%d/unpublish-page-and-children/' % (page.id),
        priority=65)
    yield wagtailadmin_widgets.Button(
        'Remove from a Release',
        '/crc-cms/pages/%d/remove-page-and-children-from-release/' % (page.id),
        priority=70)
コード例 #3
0
ファイル: wagtail_hooks.py プロジェクト: stelles/wagtailtrans
def edit_in_language_items(page, page_perms, is_parent=False):
    """Add all other languages in the ``Edit in`` dropdown.

    All languages other than the canonical language are listed as dropdown
    options which allows the user to click on them and edit the page in the
    language they prefer.

    """
    other_languages = (
        page.specific
        .get_translations(only_live=False)
        .exclude(pk=page.pk)
        .select_related('language')
        .order_by('language__position')
    )

    for prio, language_page in enumerate(other_languages):
        edit_url = reverse('wagtailadmin_pages:edit', args=(language_page.pk,))
        return_page = language_page.canonical_page or language_page
        next_url = reverse('wagtailadmin_explore', args=(return_page.get_parent().pk,))

        yield widgets.Button(
            force_text(language_page.language),
            "{edit_url}?next={next_url}".format(
                edit_url=edit_url,
                next_url=next_url
            ),
            priority=prio,
        )
コード例 #4
0
ファイル: test_buttons_hooks.py プロジェクト: xishi00/wagtail
 def page_custom_listing_more_buttons(page,
                                      page_perms,
                                      is_parent=False):
     yield wagtailadmin_widgets.Button(
         'Another useless dropdown button in "One more more button" dropdown',
         '/custom-url',
         priority=10)
コード例 #5
0
    def page_translations_menu_items(page, page_perms, is_parent=False):
        priority = 1
        exclude_lang = []

        if hasattr(page, 'language') and page.language:
            exclude_lang += [page.language.code]

        if get_wagtailtrans_setting('STRICT_TRANSLATE_PERMISSIONS'):
            user_groups = page_perms.user.groups.values_list('name', flat=True)
            if not is_privileged_user(user_groups):
                exclude_lang += [
                    lang
                    for lang in Language.objects.live().values_list('code',
                                                                    flat=True)
                    if lang not in allowed_language_codes(user_groups)
                ]

        other_languages = set(Language.objects.live().exclude(
            code__in=exclude_lang).order_by('position'))

        translations = page.get_translations(
            only_live=False).select_related('language')
        taken_languages = set(t.language for t in translations)

        translation_targets = other_languages - taken_languages
        for language in translation_targets:
            yield widgets.Button(force_text(language),
                                 reverse('wagtailtrans_translations:add',
                                         kwargs={
                                             'instance_id': page.pk,
                                             'language_code': language.code,
                                         }),
                                 priority=priority)

            priority += 1
コード例 #6
0
    def page_translations_menu_items(page,
                                     page_perms,
                                     is_parent=False,
                                     next_url=None):
        prio = 1
        exclude_lang = None

        if hasattr(page, 'language') and page.language:
            exclude_lang = page.language

        other_languages = set(
            Language.objects.exclude(pk=exclude_lang.pk).order_by('position'))

        translations = page.get_translations(
            only_live=False).select_related('language')
        taken_languages = set(t.language for t in translations)

        translation_targets = other_languages - taken_languages
        for language in translation_targets:
            yield widgets.Button(force_str(language),
                                 reverse('wagtailtrans_translations:add',
                                         kwargs={
                                             'instance_id': page.pk,
                                             'language_code': language.code,
                                         }),
                                 priority=prio)

            prio += 1
コード例 #7
0
 def page_listing_more_buttons(page,
                               page_perms,
                               is_parent=False,
                               next_url=None):
     yield wagtailadmin_widgets.Button(
         'Another useless button in default "More" dropdown',
         '/custom-url',
         priority=10)
コード例 #8
0
ファイル: wagtail_hooks.py プロジェクト: jonndoe/fawbesturn
def page_custom_listing_more_buttons(page, page_perms, is_parent=False):
    if page_perms.can_move():
        yield wagtailadmin_widgets.Button('Move',
                                          reverse('wagtailadmin_pages:move',
                                                  args=[page.id]),
                                          priority=10)
    if page_perms.can_delete():
        yield wagtailadmin_widgets.Button('Delete',
                                          reverse('wagtailadmin_pages:delete',
                                                  args=[page.id]),
                                          priority=30)
    if page_perms.can_unpublish():
        yield wagtailadmin_widgets.Button('Unpublish',
                                          reverse(
                                              'wagtailadmin_pages:unpublish',
                                              args=[page.id]),
                                          priority=40)
コード例 #9
0
def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
    if page_perms.user.has_perm("simple_translation.submit_translation") and not page.is_root():
        # If there's at least one locale that we haven't translated into yet, show "Translate this page" button
        has_locale_to_translate_to = Locale.objects.exclude(
            id__in=page.get_translations(inclusive=True).values_list("locale_id", flat=True)
        ).exists()

        if has_locale_to_translate_to:
            url = reverse("simple_translation:submit_page_translation", args=[page.id])
            yield wagtailadmin_widgets.Button(_("Translate"), url, priority=60)
コード例 #10
0
def add_sharing_link(page, page_perms, is_parent=False):
    sharing_url = get_sharing_url(page)

    if sharing_url:
        yield wagtailadmin_widgets.Button(
            'View sharing link',
            sharing_url,
            attrs={
                'title':
                _("View shared revision of '{}'").format(
                    page.get_admin_display_title()),
            },
            priority=90)
コード例 #11
0
def edit_in_language_items(page, page_perms, is_parent=False):
    """
    Add all other languages in the ``Edit in`` dropdown.

    All languages other than the canonical language are listed as dropdown
    options which allows the user to click on them and edit the page in the
    language they prefer.
    """
    excluded_language_codes = []
    if get_wagtailtrans_setting('STRICT_TRANSLATE_PERMISSIONS'):
        """Restricting translate permissions according to user's groups."""
        user_groups = page_perms.user.groups.values_list('name', flat=True)
        if not is_privileged_user(user_groups):
            excluded_language_codes += [
                lang for lang in Language.objects.live().values_list('code',
                                                                     flat=True)
                if lang not in allowed_language_codes(user_groups)
            ]

    other_languages = (page.specific.get_translations(only_live=False).exclude(
        pk=page.pk, language__code__in=excluded_language_codes).select_related(
            'language').order_by('language__position'))

    for priority, language_page in enumerate(other_languages):
        edit_url = reverse('wagtailadmin_pages:edit',
                           args=(language_page.pk, ))
        return_page = language_page.canonical_page or language_page
        next_url = reverse('wagtailadmin_explore',
                           args=(return_page.get_parent().pk, ))

        yield widgets.Button(
            force_text(language_page.language),
            "{edit_url}?next={next_url}".format(edit_url=edit_url,
                                                next_url=next_url),
            priority=priority,
        )
コード例 #12
0
 def page_header_buttons(page, page_perms, next_url=None):
     yield wagtailadmin_widgets.Button('Another useless header button',
                                       '/custom-url',
                                       priority=10)
コード例 #13
0
def page_listing_more_buttons(page, page_perms, is_parent=False):
    yield wagtailadmin_widgets.Button('Полный урл', page.full_url, priority=1)
コード例 #14
0
ファイル: wagtail_hooks.py プロジェクト: jonndoe/fawbesturn
def page_listing_more_buttons(page, page_perms, is_parent=False):
    yield wagtailadmin_widgets.Button('A dropdown button',
                                      '/goes/to/a/url/',
                                      priority=60)
コード例 #15
0
ファイル: test_buttons_hooks.py プロジェクト: tnir/wagtail
 def page_custom_listing_more_buttons(page, page_perms, next_url=None):
     yield wagtailadmin_widgets.Button(
         'Another useless dropdown button in "One more more button" dropdown',
         "/custom-url",
         priority=10,
     )
コード例 #16
0
def page_listing_more_buttons(page, page_perms, is_parent=False):
    yield wagtailadmin_widgets.Button(
        '[TBS] Convert images to "medium"',
        f'/admin/pages/{page.pk}/tools/images_to_medium/',
        priority=60,
    )