<commit_before># -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-27 21:07
from __future__ import unicode_literals
import logging

from django.db import migrations, connection
from django.core.management.sql import emit_post_migrate_signal
from bulk_update.helper import bulk_update

logger = logging.getLogger(__name__)

def reverse_func(apps, schema_editor):
    # Reverse data migration - written in Django for now, can rewrite in SQL if necessary
    AbstractNode = apps.get_model('osf.AbstractNode')
    Contributor = apps.get_model('osf.Contributor')
    Group = apps.get_model('auth.Group')

    contributors = []

    for node in AbstractNode.objects.all():
        read_group = Group.objects.get(name='node_{}_read'.format(node.id))
        write_group = Group.objects.get(name='node_{}_write'.format(node.id))
        admin_group = Group.objects.get(name='node_{}_admin'.format(node.id))

        for user in read_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = False
            contributor.admin = False
            contributors.append(contributor)

        for user in write_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = True
            contributor.admin = False
            contributors.append(contributor)

        for user in admin_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = True
            contributor.admin = True
            contributors.append(contributor)

        read_group.delete()<commit_msg>Manually delete GuardianObjectPermission in reverse data migration for adding guardian to nodes.<commit_after># -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-27 21:07
from __future__ import unicode_literals
import logging

from django.db import migrations, connection
from django.core.management.sql import emit_post_migrate_signal
from guardian.models import GroupObjectPermission
from bulk_update.helper import bulk_update

logger = logging.getLogger(__name__)

def reverse_func(apps, schema_editor):
    # Reverse data migration - written in Django for now, can rewrite in SQL if necessary
    AbstractNode = apps.get_model('osf.AbstractNode')
    Contributor = apps.get_model('osf.Contributor')
    Group = apps.get_model('auth.Group')

    contributors = []

    for node in AbstractNode.objects.all():
        read_group = Group.objects.get(name='node_{}_read'.format(node.id))
        write_group = Group.objects.get(name='node_{}_write'.format(node.id))
        admin_group = Group.objects.get(name='node_{}_admin'.format(node.id))

        for user in read_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = False
            contributor.admin = False
            contributors.append(contributor)

        for user in write_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = True
            contributor.admin = False
            contributors.append(contributor)

        for user in admin_group.user_set.all():
            contributor = Contributor.objects.get(user_id=user.id, node=node)
            contributor.read = True
            contributor.write = True
            contributor.admin = True
            contributors.append(contributor)

        node_groups = Group.objects.filter(id__in=[read_group.id, write_group.id, admin_group.id])
        GroupObjectPermission.objects.filter(group__id__in=node_groups).delete()
        read_group.delete()
{'fraction_non_alphanumeric': 0.09685663174035267, 'fraction_numerical': 0.009200102223358037, 'mean_word_length': 2.9938775510204083, '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': '7548359', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1079, 'n_words': 235}