<commit_before># -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-11-08 16:56
from __future__ import unicode_literals

from django.db import migrations
from osf.models import Collection
from django.contrib.contenttypes.models import ContentType


def reverse_func(state, schema):
    preprint_content_type = ContentType.objects.get(app_label='osf', model='preprint')
    collections = Collection.objects.filter(collected_types__in=[preprint_content_type.id])
    for collection in collections:
        collection.collected_types.remove(preprint_content_type)


def add_preprint_type_to_collections(state, schema):
    preprint_content_type = ContentType.objects.get(app_label='osf', model='preprint')
    collections = Collection.objects.exclude(collected_types__in=[preprint_content_type.id])
    for collection in collections:
        collection.collected_types.add(preprint_content_type)


class Migration(migrations.Migration):

    dependencies = [
        ('osf', '0144_merge_20181113_1420'),
    ]
<commit_msg>Use the Collection.collected_types through table to bulk add preprints as a valid collected_type for existing collections.<commit_after># -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-11-08 16:56
from __future__ import unicode_literals

from django.db import migrations
from osf.models import Collection
from django.contrib.contenttypes.models import ContentType


def reverse_func(state, schema):
    preprint_content_type = ContentType.objects.get(app_label='osf', model='preprint')
    ThroughModel = Collection.collected_types.through
    ThroughModel.objects.filter(contenttype_id=preprint_content_type.id).delete()


def add_preprint_type_to_collections(state, schema):
    ThroughModel = Collection.collected_types.through
    preprint_ct_id = ContentType.objects.get(app_label='osf', model='preprint').id

    through_objects = []
    collections = Collection.objects.exclude(collected_types__in=[preprint_ct_id])
    for collection in collections:
        through_objects.append(ThroughModel(collection_id=collection.id, contenttype_id=preprint_ct_id))

    ThroughModel.objects.bulk_create(through_objects)


class Migration(migrations.Migration):

    dependencies = [
        ('osf', '0144_merge_20181113_1420'),
    ]

{'fraction_non_alphanumeric': 0.09282886053673559, 'fraction_numerical': 0.029916410030796304, 'mean_word_length': 5.441926345609065, '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': '2559757', 'n_tokens_mistral': 722, 'n_tokens_neox': 667, 'n_words': 130}