def score(self):
        score = 0

        if (
            get_wagtail_marketing_setting('MIN_TITLE_LENGTH') <= len(self.title)
            <= get_wagtail_marketing_setting('MAX_TITLE_LENGTH')
        ):
            score += 10

        title_word_count = self.title.split()
        if (
            get_wagtail_marketing_setting('MIN_TITLE_WORD_COUNT') <= len(title_word_count)
            <= get_wagtail_marketing_setting('MAX_TITLE_WORD_COUNT')
        ):
            score += 40

        if len(self.description) >= get_wagtail_marketing_setting('MIN_DESCRIPTION_LENGTH'):
            score += 25

        if (
            get_wagtail_marketing_setting('MIN_DESCRIPTION_LENGTH') <= len(self.description)
            <= get_wagtail_marketing_setting('MAX_DESCRIPTION_LENGTH')
        ):
            score += 25

        return score
    def ICONS(self):
        icons = get_wagtail_marketing_setting('SEO_SCORE_ICONS')

        if not isinstance(icons, (list, tuple)):
            raise ImproperlyConfigured("WAGTAIL_MARKETING_SEO_SCORE_ICONS must be a list or a tuple")
        elif len(icons) != 4:
            raise ImproperlyConfigured("WAGTAIL_MARKETING_SEO_SCORE_ICONS should have a length of 4")

        return icons
Esempio n. 3
0
class SeoListingAdmin(ModelAdmin):
    model = get_page_model()
    menu_label = _("Pages Meta Listing")
    menu_icon = 'fa-bullseye'
    menu_order = 1000

    list_display = ('admin_display_title', 'seo_title', 'search_engine',
                    'score')
    list_filter = get_wagtail_marketing_setting('LIST_FILTER')
    ordering = ('-seo_title', '-search_description')
    search_fields = ('title', 'seo_title', 'search_description')
    url_helper_class = PageAdminURLHelper

    def seo_helper(self, obj):
        return SeoHelper(obj.get_admin_display_title(), obj.seo_title,
                         obj.search_description)

    def admin_display_title(self, obj):
        return obj.get_admin_display_title()

    admin_display_title.short_description = _("Content page title")

    def search_engine(self, obj):
        seo = self.seo_helper(obj)
        return format_html('<strong>{}</strong><p>{}</p>', seo.truncated_title,
                           seo.truncated_description)

    search_engine.short_description = _("Search engine example")

    def score(self, obj):
        seo = self.seo_helper(obj)
        return format_html('<span style="font-size: 28px;">{}</span>',
                           seo.icon)

    score.short_description = _("Score")

    def get_queryset(self, request):
        """ Exclude root page from the queryset """
        qs = super().get_queryset(request)
        return qs.exclude(depth=1)
 def truncated_description(self):
     return truncatechars(
         self.description,
         get_wagtail_marketing_setting('MAX_DESCRIPTION_LENGTH'),
     )
 def truncated_title(self):
     return truncatechars(
         self.title,
         get_wagtail_marketing_setting('MAX_TITLE_LENGTH'),
     )