<commit_before>import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
from wagtail.core import hooks
from django.urls import reverse
from wagtail.admin.menu import MenuItem

from .functions import invalidate_cloudfront_caches

@hooks.register('register_rich_text_features')
def register_strikethrough_feature(features):
    """
    Registering the `superscript` feature, which uses the `SUPERSCRIPT` Draft.js inline style type,
    and is stored as HTML with an `<sup>` tag.
    """
    feature_name = 'superscript'
    type_ = 'SUPERSCRIPT'
    tag = 'sup'

    control = {
        'type': type_,
        'label': '^',
        'description': 'Superscript',
    }

    features.register_editor_plugin(
        'draftail', feature_name, draftail_features.InlineStyleFeature(control)
    )

    db_conversion = {
        'from_database_format': {tag: InlineStyleElementHandler(type_)},
        'to_database_format': {'style_map': {type_: tag}},
    }
    features.default_features.append(feature_name)
    features.register_converter_rule('contentstate', feature_name, db_conversion)

@hooks.register('after_edit_page')
def invalidate_cloudfront_cache_on_page_save(page, request):
    invalidate_cloudfront_caches()

@hooks.register('register_settings_menu_item')
def register_500_menu_item():
  return MenuItem('Generate 500', reverse('throw_error'), classnames='icon icon-warning', order=10000)

<commit_msg>Move cache invalidatation to all model saves (#1022)<commit_after>import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
from wagtail.core import hooks
from django.urls import reverse
from wagtail.admin.menu import MenuItem

from django.db.models.signals import post_save
from django.dispatch import receiver

from .functions import invalidate_cloudfront_caches

@hooks.register('register_rich_text_features')
def register_strikethrough_feature(features):
    """
    Registering the `superscript` feature, which uses the `SUPERSCRIPT` Draft.js inline style type,
    and is stored as HTML with an `<sup>` tag.
    """
    feature_name = 'superscript'
    type_ = 'SUPERSCRIPT'
    tag = 'sup'

    control = {
        'type': type_,
        'label': '^',
        'description': 'Superscript',
    }

    features.register_editor_plugin(
        'draftail', feature_name, draftail_features.InlineStyleFeature(control)
    )

    db_conversion = {
        'from_database_format': {tag: InlineStyleElementHandler(type_)},
        'to_database_format': {'style_map': {type_: tag}},
    }
    features.default_features.append(feature_name)
    features.register_converter_rule('contentstate', feature_name, db_conversion)

@hooks.register('register_settings_menu_item')
def register_500_menu_item():
  return MenuItem('Generate 500', reverse('throw_error'), classnames='icon icon-warning', order=10000)

@receiver(post_save)
def invalidate_cloudfront_caches_post_save(sender, instance, **kwargs):
    invalidate_cloudfront_caches()
{'fraction_non_alphanumeric': 0.10003155569580309, 'fraction_numerical': 0.008204480908804039, 'mean_word_length': 5.084452975047984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3288427', 'n_tokens_mistral': 989, 'n_tokens_neox': 956, 'n_words': 198}