<commit_before>"""Scripts to migrate legacy objects in existing databases."""
import logging  # pragma: no cover
from pyramid.threadlocal import get_current_registry
from adhocracy_core.evolution import migrate_new_sheet
from adhocracy_core.resources.organisation import IOrganisation
from adhocracy_meinberlin.resources.kiezkassen import IProposalVersion
import adhocracy_core.sheets
import adhocracy_meinberlin.sheets

logger = logging.getLogger(__name__)  # pragma: no cover


def use_adhocracy_core_title_sheet(root):  # pragma: no cover
    """Migrate kiezkassen proposal to adhocracy_core title sheet.

    Add title sheet.
    Remove title field from proposal sheet.
    """
    migrate_new_sheet(root, IProposalVersion,
                      adhocracy_core.sheets.title.ITitle,
                      adhocracy_meinberlin.sheets.kiezkassen.IProposal,
                      remove_isheet_old=False,
                      fields_mapping=[('title', 'title')])


def use_adhocracy_core_description_sheet(root):  # pragma: no cover
    """Migrate kiezkassen proposal to description sheet.

    Add description sheet.
    Remove detail field from proposal sheet.
    """
    migrate_new_sheet(root, IProposalVersion,
                      adhocracy_core.sheets.description.IDescription,
                      adhocracy_meinberlin.sheets.kiezkassen.IProposal,
                      remove_isheet_old=False,
                      fields_mapping=[('description', 'detail')])


def add_sample_organisation(root):
    """Add sample organisation and kiezkassen process."""
    registry = get_current_registry(root)
    appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
                  {'name': 'organisation'},
                  adhocracy_core.sheets.title.ITitle.__identifier__:
                  {'title': 'Sample Organisation'}}
    registry.content.create(IOrganisation.__identifier__,
                            parent=root,
                            appstructs=appstructs)


def includeme(config):  # pragma: no cover
    """Register evolution utilities and add evolution steps."""
    config.add_evolution_step(use_adhocracy_core_title_sheet)
    config.add_evolution_step(use_adhocracy_core_description_sheet)<commit_msg>Revert "Do not create sample kiezkassen process in evolve script"<commit_after>"""Scripts to migrate legacy objects in existing databases."""
import logging  # pragma: no cover
from pyramid.threadlocal import get_current_registry
from adhocracy_core.evolution import migrate_new_sheet
from adhocracy_core.resources.organisation import IOrganisation
from adhocracy_meinberlin.resources.kiezkassen import IProposalVersion
from adhocracy_meinberlin.resources.kiezkassen import IProcess
import adhocracy_core.sheets
import adhocracy_meinberlin.sheets

logger = logging.getLogger(__name__)  # pragma: no cover


def use_adhocracy_core_title_sheet(root):  # pragma: no cover
    """Migrate kiezkassen proposal to adhocracy_core title sheet.

    Add title sheet.
    Remove title field from proposal sheet.
    """
    migrate_new_sheet(root, IProposalVersion,
                      adhocracy_core.sheets.title.ITitle,
                      adhocracy_meinberlin.sheets.kiezkassen.IProposal,
                      remove_isheet_old=False,
                      fields_mapping=[('title', 'title')])


def use_adhocracy_core_description_sheet(root):  # pragma: no cover
    """Migrate kiezkassen proposal to description sheet.

    Add description sheet.
    Remove detail field from proposal sheet.
    """
    migrate_new_sheet(root, IProposalVersion,
                      adhocracy_core.sheets.description.IDescription,
                      adhocracy_meinberlin.sheets.kiezkassen.IProposal,
                      remove_isheet_old=False,
                      fields_mapping=[('description', 'detail')])


def add_sample_organisation(root):
    """Add sample organisation and kiezkassen process."""
    registry = get_current_registry(root)
    appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
                  {'name': 'organisation'},
                  adhocracy_core.sheets.title.ITitle.__identifier__:
                  {'title': 'Sample Organisation'}}
    registry.content.create(IOrganisation.__identifier__,
                            parent=root,
                            appstructs=appstructs)
    appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
                  {'name': 'kiezkasse'},
                  adhocracy_core.sheets.title.ITitle.__identifier__:
                  {'title': 'Sample Kiezkassen process'}}
    registry.content.create(IProcess.__identifier__,
                            parent=root['organisation'],
                            appstructs=appstructs)


def includeme(config):  # pragma: no cover
    """Register evolution utilities and add evolution steps."""
    config.add_evolution_step(use_adhocracy_core_title_sheet)
    config.add_evolution_step(use_adhocracy_core_description_sheet)
{'fraction_non_alphanumeric': 0.07707707707707707, 'fraction_numerical': 0.0, 'mean_word_length': 2.9713831478537363, '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': '3436630', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1339, 'n_words': 280}