<commit_before>from __future__ import unicode_literals

# from django.db.models.signals import post_save, post_delete
from django.conf import settings
from django.dispatch import receiver
# from cms.models import Title
from cms.constants import PUBLISHER_STATE_DIRTY
from cms.signals import post_placeholder_operation, post_obj_operation, post_publish

from djangocms_misc.global_untranslated_placeholder.utils import get_untranslated_default_language


# published. if not default language, publish default as well
@receiver(
    post_publish,
    dispatch_uid="cms_global_untranslated_placeholder_post_publish",
)
def post_publish_handler(**kwargs):
    page_instance = kwargs.get('instance', None)
    if not page_instance:
        return
    published_language = kwargs.get('language', settings.LANGUAGE_CODE)
    default_language = get_untranslated_default_language()
    if not published_language == default_language:
        page_instance.publish(default_language)



# something has changed, if we are not on the default lang, mark current lang/title as dirty as well
@receiver(
    post_placeholder_operation,
    dispatch_uid="cms_global_untranslated_placeholder_post_placeholder_operation",
)
def post_placeholder_operation_handler(sender, operation, request, language, token, origin, **kwargs):
    plugin = None
    if operation == 'change_plugin':
        plugin = kwargs.get('new_plugin', None)
    if not plugin:
        plugin = kwargs.get('plugin', None)
    if not plugin:
        plugin = kwargs.get('plugins', [None, ])[0]
    print operation
    print plugin
    print kwargs
    if plugin:
        placeholder = plugin.placeholder
        if not plugin.language == language:
            # mark current language Title as dirty as well!
            if placeholder.page:
                title = placeholder.page.get_title_obj(language)
                title.publisher_state = PUBLISHER_STATE_DIRTY
                title.save()<commit_msg>with autopublisher, no signals are needed!<commit_after>from __future__ import unicode_literals

# from django.db.models.signals import post_save, post_delete
from django.conf import settings
from django.dispatch import receiver
# from cms.models import Title
from cms.constants import PUBLISHER_STATE_DIRTY
from cms.signals import post_placeholder_operation, post_obj_operation, post_publish

from djangocms_misc.global_untranslated_placeholder.utils import get_untranslated_default_language


if not 'djangocms_misc.autopublisher' in settings.INSTALLED_APPS:

    # published. if not default language, publish default as well
    @receiver(
        post_publish,
        dispatch_uid="cms_global_untranslated_placeholder_post_publish",
    )
    def post_publish_handler(**kwargs):
        page_instance = kwargs.get('instance', None)
        if not page_instance:
            return
        published_language = kwargs.get('language', settings.LANGUAGE_CODE)
        default_language = get_untranslated_default_language()
        if not published_language == default_language:
            page_instance.publish(default_language)


    # something has changed, if we are not on the default lang, mark current lang/title as dirty as well
    @receiver(
        post_placeholder_operation,
        dispatch_uid="cms_global_untranslated_placeholder_post_placeholder_operation",
    )
    def post_placeholder_operation_handler(sender, operation, request, language, token, origin, **kwargs):
        plugin = None
        if operation == 'change_plugin':
            plugin = kwargs.get('new_plugin', None)
        if not plugin:
            plugin = kwargs.get('plugin', None)
        if not plugin:
            plugin = kwargs.get('plugins', [None, ])[0]
        print operation
        print plugin
        print kwargs
        if plugin:
            placeholder = plugin.placeholder
            if not plugin.language == language:
                # mark current language Title as dirty as well!
                if placeholder.page:
                    title = placeholder.page.get_title_obj(language)
                    title.publisher_state = PUBLISHER_STATE_DIRTY
                    title.save()
{'fraction_non_alphanumeric': 0.06756431834575619, 'fraction_numerical': 0.00048088482808367395, 'mean_word_length': 3.392819429778247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '674635', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1086, 'n_words': 299}