<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from itertools import chain

from django.conf import settings

from cms import api, constants
from cms.exceptions import PublicIsUnmodifiable
from cms.extensions import extension_pool
from cms.models import Page, Placeholder, Title, menu_pool, copy_plugins_to


VERSION_ROOT_TITLE = '.~VERSION_ROOT_TITLE'

VERSION_FIELD_DEFAULTS = {
    'Page': {
        'path': None,
        'depth': None,
        'numchild': 0,
        'publisher_public_id': None,
        'is_home': False,
        'reverse_id': None,
        'in_navigation': False,
    },
    'Title': {
        'published': False,
        'publisher_public': None,
    },
}


def _copy_model(instance, **attrs):
    instance.pk = None
    for field, value in chain(VERSION_FIELD_DEFAULTS.get(instance.__class__.__name__, {}).items(), attrs.items()):
        try:
            value = value(instance)
        except TypeError:
            pass
        setattr(instance, field, value)
    instance.save()
    return instance


def get_version_page_root(site):
    try:
        return Page.objects.get(title_set__title=VERSION_ROOT_TITLE, site=site)
    except Page.DoesNotExist:
        return api.create_page(
            VERSION_ROOT_TITLE, constants.TEMPLATE_INHERITANCE_MAGIC, settings.LANGUAGES[0][0], site=site)


def revise_page(page):
    """
    Copy a page [ and all its descendants to a new location ]<commit_msg>set attrs first in _copy_model<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from itertools import chain

from cms.utils import page as page_utils
from django.conf import settings

from cms import api, constants
from cms.exceptions import PublicIsUnmodifiable
from cms.extensions import extension_pool
from cms.models import Page, Placeholder, Title, menu_pool, copy_plugins_to


VERSION_ROOT_TITLE = '.~VERSION_ROOT_TITLE'

VERSION_FIELD_DEFAULTS = {
    'Page': {
        'path': None,
        'depth': None,
        'numchild': 0,
        'publisher_public_id': None,
        'is_home': False,
        'reverse_id': None,
        'in_navigation': False,
    },
    'Title': {
        'published': False,
        'publisher_public': None,
        'slug': page_utils.get_available_slug,
    },
}


def _copy_model(instance, **attrs):
    instance.pk = None
    for field, value in chain(attrs.items(), VERSION_FIELD_DEFAULTS.get(instance.__class__.__name__, {}).items()):
        try:
            value = value(instance)
        except TypeError:
            pass
        setattr(instance, field, value)
    instance.save()
    return instance


def get_version_page_root(site):
    try:
        return Page.objects.get(title_set__title=VERSION_ROOT_TITLE, site=site)
    except Page.DoesNotExist:
        return api.create_page(
            VERSION_ROOT_TITLE, constants.TEMPLATE_INHERITANCE_MAGIC, settings.LANGUAGES[0][0], site=site)


def revise_page(page):
    """
    Copy a page [ and all its descendants to a new location ]
{'fraction_non_alphanumeric': 0.10122394971882236, 'fraction_numerical': 0.0026463777704267286, 'mean_word_length': 3.1255115961800817, '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': '2735488', 'n_tokens_mistral': 943, 'n_tokens_neox': 936, 'n_words': 232}