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

from django.db import migrations, models


def combine_statics(apps, schema_editor):
    """
    Custom function that combines the old static1, static2, and static3
    into a ManyToManyField called statics. Doesn't use .add() because
    django doesn't let you do that when you have an intermediate table.
    """
    WormholeType = apps.get_model("Map", "WormholeType")
    WSystem = apps.get_model("Map", "WSystem")
    SystemStatic = apps.get_model("Map", "SystemStatic")
    for wsystem in WSystem.objects.all():
        # Get all the static wormholes
        hole1 = wsystem.static1
        hole2 = wsystem.static2
        # Add the wormholes to statics if the static exists
        try:
            static1 = WormholeType.objects.get(name=hole1)
            sys_static1 = SystemStatic(system=wsystem, static=static1)
            sys_static1.save()
        except WormholeType.DoesNotExist:
            pass        # Do nothing, no static to add
        try:
            static2 = WormholeType.objects.get(name=hole2)
            sys_static2 = SystemStatic(system=wsystem, static=static2)
            sys_static2.save()
        except WormholeType.DoesNotExist:
            pass        # Do nothing, no static to add


class Migration(migrations.Migration):

    dependencies = [
        ('Map', '0004_auto_20151229_1537'),
    ]

    operations = [
        migrations.CreateModel(
            name='SystemStatic',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('date_added', models.DateTimeField(auto_now_add=True)),
                ('date_modified', models.DateTimeField(auto_now=True)),
                ('static', models.ForeignKey(to='Map.WormholeType', blank=True, null=True)),
                ('system', models.ForeignKey(to='Map.WSystem', blank=True, null=True)),
            ],
        ),
        migrations.AddField(
            model_name='wsystem',
            name='statics',
            field=models.ManyToManyField(to='Map.WormholeType', null=True, through='Map.SystemStatic', blank=True),
        ),
        migrations.RunPython(combine_statics),
        migrations.RemoveField(<commit_msg>Simplify system static migration and add reverse<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def combine_statics(apps, schema_editor):
    """
    Custom function that combines the old static1, static2, and static3
    into a ManyToManyField called statics. Doesn't use .add() because
    django doesn't let you do that when you have an intermediate table.
    """
    WSystem = apps.get_model("Map", "WSystem")
    SystemStatic = apps.get_model("Map", "SystemStatic")
    for wsystem in WSystem.objects.all():
        # Get all the static wormholes
        hole1 = wsystem.static1
        hole2 = wsystem.static2
        # Add the wormholes to statics if the static exists
        if hole1:
            SystemStatic.objects.create(system=wsystem, static=hole1)
        if hole2:
            SystemStatic.objects.create(system=wsystem, static=hole2)


def split_statics(apps, schema_editor):
    WSystem = apps.get_model("Map", "WSystem")
    SystemStatic = apps.get_model("Map", "SystemStatic")
    for static in SystemStatic.objects.all():
        wsystem = static.system
        if not wsystem.static1:
            wsystem.static1 = static.static
        elif not wsystem.static2:
            wsystem.static2 = static.static
        else:
            print("System %s has already two statics, skipping %s." % (wsystem, static))
        wsystem.save()


class Migration(migrations.Migration):

    dependencies = [
        ('Map', '0004_auto_20151229_1537'),
    ]

    operations = [
        migrations.CreateModel(
            name='SystemStatic',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('date_added', models.DateTimeField(auto_now_add=True)),
                ('date_modified', models.DateTimeField(auto_now=True)),
                ('static', models.ForeignKey(to='Map.WormholeType', blank=True, null=True)),
                ('system', models.ForeignKey(to='Map.WSystem', blank=True, null=True)),
            ],
        ),
        migrations.AddField(
            model_name='wsystem',
            name='statics',
            field=models.ManyToManyField(to='Map.WormholeType', null=True, through='Map.SystemStatic', blank=True),
        ),
        migrations.RunPython(combine_statics, split_statics),
        migrations.RemoveField(
{'fraction_non_alphanumeric': 0.10984126984126984, 'fraction_numerical': 0.013968253968253968, 'mean_word_length': 2.643793369313801, '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': '5068', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1334, 'n_words': 304}