API¶
-
class
yaturbo.toolbox.
YandexTurboFeed
¶ Yandex Turbo Pages Feed.
from yaturbo import YandexTurboFeed class TurboFeed(YandexTurboFeed): ''' More information on Django Syndication Feed Framework configuration: https://docs.djangoproject.com/en/2.0/ref/contrib/syndication/ ''' turbo_sanitize = True # Let's strip HTML tags unsupported by Turbo pages. def item_turbo(self, item): return 'turbo contents' feed = TurboFeed() # configure Yandex Metrika counter feed.configure_analytics_yandex('123456789') # configure Yandex Advertisement Network feed.configure_ad_yandex('A-123', 'page-top') urlpatterns = [ ... path('turbo/', feed), ... ]
-
configure_ad_yandex
(ident, turbo_id=u'')¶ Configure Yandex Advertisement Network.
Parameters: - ident (str|unicode) – Ad ID.
- turbo_id (str|unicode) – ID of a place (figure) on Turbo page where to put an Ad block.
-
configure_analytics_google
(ident)¶ Configure Google Analytics counter.
Parameters: ident (str|unicode) – Counter ID.
-
configure_analytics_yandex
(ident, params=None)¶ Configure Yandex Metrika analytics counter.
Parameters: - ident (str|unicode) – Metrika counter ID.
- params (dict) – Additional params.
-
item_turbo
(item)¶ This can be overridden to set turbo contents.
Parameters: item – Return type: str|unicode
-
item_turbo_source
(item)¶ This can be overridden to set turbo source URL.
Can be used with Yandex Metrika.
Parameters: item – Return type: str|unicode
-
item_turbo_topic
(item)¶ This can be overridden to set turbo page topic (title).
Can be used with Yandex Metrika.
Parameters: item – Return type: str|unicode
-
turbo_sanitize
= False¶ Whether to automatically sanitize HTML contents returned from .item_turbo().
Can be useful if you do not keep special HTML for Turbo pages.
-
-
yaturbo.toolbox.
sanitize_turbo
(html, allowed_tags=[u'a', u'abbr', u'b', u'big', u'blockquote', u'br', u'button', u'code', u'dd', u'del', u'div', u'dl', u'dt', u'em', u'figcaption', u'figure', u'form', u'h1', u'h2', u'h3', u'h4', u'h5', u'h6', u'header', u'hr', u'i', u'iframe', u'img', u'ins', u'li', u'menu', u'meta', u'ol', u'p', u'pre', u'small', u'source', u'strong', u'sub', u'sup', u'table', u'td', u'th', u'tr', u'u', u'ul', u'video'], allowed_attrs={u'a': [u'data-turbo', u'href'], u'abbr': [u'title'], u'button': [u'data-agreement-company', u'data-agreement-link', u'data-background-color', u'data-color', u'data-primary', u'data-send-to', u'data-turbo', u'disabled', u'formaction'], u'div': [u'data-agreement-company', u'data-agreement-link', u'data-author', u'data-avatar-url', u'data-block', u'data-color', u'data-description', u'data-expanded', u'data-height', u'data-icon', u'data-item-view', u'data-layout', u'data-network', u'data-send-to', u'data-stick', u'data-subtitle', u'data-thumb', u'data-thumb-position', u'data-thumb-ratio', u'data-title', u'data-type', u'data-url', u'data-value', u'data-view', u'itemscope', u'itemtype'], u'figure': [u'data-platform-desktop', u'data-platform-mobile', u'data-turbo-ad-id'], u'form': [u'action', u'data-agreement-company', u'data-agreement-link', u'data-send-to', u'data-type', u'method', u'name', u'placeholder', u'type'], u'iframe': [u'allowfullscreen', u'frameborder', u'hd', u'height', u'referrerpolicy', u'sandbox', u'src', u'width'], u'img': [u'src'], u'meta': [u'content', u'itemprop'], u'source': [u'data-duration', u'data-title', u'src', u'type'], u'table': [u'data-invisible'], u'video': [u'height', u'width']})¶ Sanitizes HTML, removing not allowed tags and attributes.
Parameters: - html (str|unicode) –
- allowed_tags (list) – List of allowed tags.
- allowed_attrs (dict) – Dictionary with attributes allowed for tags.
Return type: unicode