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

import sys

from django.db import models, migrations
from django.utils.text import slugify
from common.migrations import skip


def add_slugs(apps, schema_editor):
    Organization = apps.get_model('organizations', 'Organization')
    Facility = apps.get_model('organizations', 'Facility')

    for model in (Organization, Facility):
        for instance in model.objects.all():
            instance.slug = slugify(instance.name)
            instance.save()
            sys.stdout.write(u'{} -> {}\n'.format(instance, instance.slug))


class Migration(migrations.Migration):
    dependencies = [
        ('organizations', '0007_auto_20151023_2129'),
    ]

    operations = [
        migrations.AddField(
            model_name='facility',
            name='slug',
            field=models.SlugField(null=True, verbose_name='slug', blank=True),
        ),
        migrations.AddField(
            model_name='organization',
            name='slug',
            field=models.SlugField(null=True, verbose_name='slug', blank=True),
        ),

        migrations.RunPython(add_slugs, skip),

        migrations.AlterField(
            model_name='facility',
            name='slug',
            field=models.SlugField(verbose_name='slug'),
        ),
        migrations.AlterField(
            model_name='organization',
            name='slug',
            field=models.SlugField(verbose_name='slug'),
        ),
    ]
<commit_msg>added a catch for missing instance name from dummy data<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys

from django.db import models, migrations
from django.utils.text import slugify
from common.migrations import skip


def add_slugs(apps, schema_editor):
    Organization = apps.get_model('organizations', 'Organization')
    Facility = apps.get_model('organizations', 'Facility')

    for model in (Organization, Facility):
        for instance in model.objects.all():
            instance.slug = slugify(instance.name) or slugify('{}'.format(instance.id))
            instance.save()
            sys.stdout.write(u'{} -> {}\n'.format(instance, instance.slug))


class Migration(migrations.Migration):
    dependencies = [
        ('organizations', '0007_auto_20151023_2129'),
    ]

    operations = [
        migrations.AddField(
            model_name='facility',
            name='slug',
            field=models.SlugField(null=True, verbose_name='slug', blank=True),
        ),
        migrations.AddField(
            model_name='organization',
            name='slug',
            field=models.SlugField(null=True, verbose_name='slug', blank=True),
        ),

        migrations.RunPython(add_slugs, skip),

        migrations.AlterField(
            model_name='facility',
            name='slug',
            field=models.SlugField(verbose_name='slug'),
        ),
        migrations.AlterField(
            model_name='organization',
            name='slug',
            field=models.SlugField(verbose_name='slug'),
        ),
    ]

{'fraction_non_alphanumeric': 0.12269938650306748, 'fraction_numerical': 0.010978366160800775, 'mean_word_length': 2.560919540229885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '521352', 'n_tokens_mistral': 897, 'n_tokens_neox': 893, 'n_words': 159}