<commit_before># coding: utf-8

from __future__ import unicode_literals

import sys

from django.db import migrations

ACTIVATED = u"ALREADY_ACTIVATED"


def move_user_needs(apps, schema_editor):
    OldRegistrationModel = apps.get_model("registration_history",
                                          'OldRegistrationProfile')
    UserAccount = apps.get_model("accounts", "UserAccount")
    ShiftHelper = apps.get_model("scheduler", "ShiftHelper")

    sys.stdout.write(' ' * 80)
    sys.stdout.flush()

    account_count, shift_count, users_without_shifts = 0, 0, 0
    for rp in OldRegistrationModel.objects.all():

        if rp.activation_key == ACTIVATED:
            has_shifts = False
            account, _ = UserAccount.objects.get_or_create(user=rp.user)
            account_count += 1
            for need in rp.needs.all():
                shift_helper, _ = ShiftHelper.objects.get_or_create(
                    user_account=account, need=need)
                shift_count += 1
                has_shifts = True
            if not has_shifts:
                users_without_shifts += 1
        if account_count % 43 == 0:
            sys.stdout.write(
                '\r    Migrated {} accounts totalling {} shifts ({} users w/o shifts)'.format(
                    account_count, shift_count, users_without_shifts))
            sys.stdout.flush()


class Migration(migrations.Migration):
    dependencies = [
        ('accounts', '0001_initial'),
        ('registration_history', '0001_initial'),
        ('scheduler', '0021_add_shift_users'),
    ]

    operations = [
        migrations.RunPython(move_user_needs)
    ]
<commit_msg>-PEP8 - variables should be lowercase (fixed one additional file)<commit_after># coding: utf-8

from __future__ import unicode_literals

import sys

from django.db import migrations

ACTIVATED = u"ALREADY_ACTIVATED"


def move_user_needs(apps, schema_editor):
    old_registration_model = apps.get_model("registration_history",
                                          'OldRegistrationProfile')
    user_account_model = apps.get_model("accounts", "UserAccount")
    shift_helper_model = apps.get_model("scheduler", "ShiftHelper")

    sys.stdout.write(' ' * 80)
    sys.stdout.flush()

    account_count, shift_count, users_without_shifts = 0, 0, 0
    for rp in old_registration_model.objects.all():

        if rp.activation_key == ACTIVATED:
            has_shifts = False
            account, _ = user_account_model.objects.get_or_create(user=rp.user)
            account_count += 1
            for need in rp.needs.all():
                shift_helper, _ = shift_helper_model.objects.get_or_create(
                    user_account=account, need=need)
                shift_count += 1
                has_shifts = True
            if not has_shifts:
                users_without_shifts += 1
        if account_count % 43 == 0:
            sys.stdout.write(
                '\r    Migrated {} accounts totalling {} shifts ({} users w/o shifts)'.format(
                    account_count, shift_count, users_without_shifts))
            sys.stdout.flush()


class Migration(migrations.Migration):
    dependencies = [
        ('accounts', '0001_initial'),
        ('registration_history', '0001_initial'),
        ('scheduler', '0021_add_shift_users'),
    ]

    operations = [
        migrations.RunPython(move_user_needs)
    ]

{'fraction_non_alphanumeric': 0.09746012994683993, 'fraction_numerical': 0.014471352628470172, 'mean_word_length': 2.3271119842829076, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6885344', 'n_tokens_mistral': 1036, 'n_tokens_neox': 943, 'n_words': 196}