<commit_before># -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2019-01-02 14:03
from __future__ import unicode_literals

from django.db import migrations


def move_tmp_ids_to_actual_ids(apps, schema_editor):
    PostExtraElection = apps.get_model("candidates", "PostExtraElection")

    pees_with_tmp_ids = PostExtraElection.objects.filter(
        ballot_paper_id__startswith="tmp_"
    )
    if not pees_with_tmp_ids.exists():
        # Return quickly if no tmp ids exist, to save iterating over the file
        # needlessly
        return

    data_file = open(
        "ynr/apps/candidates/migrations/0056_tmp_ids_to_ballot_id.csv"
    )
    for line in data_file:
        tmp_id, new_id = line.split(",")
        PostExtraElection.objects.filter(ballot_paper_id=tmp_id).update(
            ballot_paper_id=new_id
        )


class Migration(migrations.Migration):

    dependencies = [("candidates", "0055_delete_complexpopolofield")]

    operations = [
        migrations.RunPython(
            move_tmp_ids_to_actual_ids, migrations.RunPython.noop
        )
    ]<commit_msg>Strip ballot IDs before updating them from CSV<commit_after># -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2019-01-02 14:03
from __future__ import unicode_literals

from django.db import migrations


def move_tmp_ids_to_actual_ids(apps, schema_editor):
    PostExtraElection = apps.get_model("candidates", "PostExtraElection")

    pees_with_tmp_ids = PostExtraElection.objects.filter(
        ballot_paper_id__startswith="tmp_"
    )
    if not pees_with_tmp_ids.exists():
        # Return quickly if no tmp ids exist, to save iterating over the file
        # needlessly
        return

    data_file = open(
        "ynr/apps/candidates/migrations/0056_tmp_ids_to_ballot_id.csv"
    )
    for line in data_file:
        tmp_id, new_id = line.split(",")
        PostExtraElection.objects.filter(ballot_paper_id=tmp_id).update(
            ballot_paper_id=new_id.strip()
        )


class Migration(migrations.Migration):

    dependencies = [("candidates", "0055_delete_complexpopolofield")]

    operations = [
        migrations.RunPython(
            move_tmp_ids_to_actual_ids, migrations.RunPython.noop
        )
    ]
{'fraction_non_alphanumeric': 0.08927770300583221, 'fraction_numerical': 0.02332884701659937, 'mean_word_length': 3.1838649155722325, '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': '255158', 'n_tokens_mistral': 776, 'n_tokens_neox': 720, 'n_words': 139}