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

from django.db import models, migrations
import akvo.rsr.fields


def unique_organisation_names(apps, schema_editor):
    """Make sure that the organisation.name and organisation.long_name are unique."""
    Organisation = apps.get_model('rsr', 'Organisation')

    org_double_name = {}
    org_double_long_name = {}

    for organisation in Organisation.objects.all():
        org_names = Organisation.objects.filter(name=organisation.name)
        if org_names.count() > 1 and organisation.name not in org_double_name.keys():
            org_double_name[organisation.name] = org_names

        org_long_names = Organisation.objects.filter(long_name=organisation.long_name)
        if org_long_names.count() > 1 and organisation.long_name not in org_double_long_name.keys():
            org_double_long_name[organisation.long_name] = org_long_names

    for double_name in org_double_name.keys():
        org_qs = org_double_name[double_name]
        for i, org in enumerate(org_qs):
            if not i == 0:
                if len(org.name) > 21:
                    org.name = org.name[:-4] + u' (' + unicode(i) + u')'
                else:
                    org.name += u' (' + unicode(i + 1) + u')'
                org.save()

    for double_long_name in org_double_long_name.keys():
        org_ln_qs = org_double_long_name[double_long_name]
        for j, org in enumerate(org_ln_qs):
            if not j == 0:
                if len(org.long_name) > 71:
                    org.long_name = org.long_name[:-4] + u' (' + unicode(j) + u')'
                else:
                    org.long_name += u' (' + unicode(j + 1) + u')'
                org.save()


class Migration(migrations.Migration):

    dependencies = [
        ('rsr', '0013_auto_20150803_0905'),
    ]

    operations = [<commit_msg>[#1406] Changed '(1)' to '(2)' for double org names, always<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import akvo.rsr.fields


def unique_organisation_names(apps, schema_editor):
    """Make sure that the organisation.name and organisation.long_name are unique."""
    Organisation = apps.get_model('rsr', 'Organisation')

    org_double_name = {}
    org_double_long_name = {}

    for organisation in Organisation.objects.all():
        org_names = Organisation.objects.filter(name=organisation.name)
        if org_names.count() > 1 and organisation.name not in org_double_name.keys():
            org_double_name[organisation.name] = org_names

        org_long_names = Organisation.objects.filter(long_name=organisation.long_name)
        if org_long_names.count() > 1 and organisation.long_name not in org_double_long_name.keys():
            org_double_long_name[organisation.long_name] = org_long_names

    for double_name in org_double_name.keys():
        org_qs = org_double_name[double_name]
        for i, org in enumerate(org_qs):
            if not i == 0:
                if len(org.name) > 21:
                    org.name = org.name[:-4] + u' (' + unicode(i + 1) + u')'
                else:
                    org.name += u' (' + unicode(i + 1) + u')'
                org.save()

    for double_long_name in org_double_long_name.keys():
        org_ln_qs = org_double_long_name[double_long_name]
        for j, org in enumerate(org_ln_qs):
            if not j == 0:
                if len(org.long_name) > 71:
                    org.long_name = org.long_name[:-4] + u' (' + unicode(j + 1) + u')'
                else:
                    org.long_name += u' (' + unicode(j + 1) + u')'
                org.save()


class Migration(migrations.Migration):

    dependencies = [
        ('rsr', '0013_auto_20150803_0905'),
    ]

    operations = [
{'fraction_non_alphanumeric': 0.11632759520083463, 'fraction_numerical': 0.017214397496087636, 'mean_word_length': 2.387809187279152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '125462', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1169, 'n_words': 261}