# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-19 19:35
from __future__ import unicode_literals

from django.apps import apps
from django.db import migrations

def exclude_admin_from_robots(apps, schema_editor):
    Site = apps.get_model('sites', 'Site')

    try:
        Rule = apps.get_model('robots', 'Rule')
    except LookupError:
        print('WARNING. Skipping migration. Robots not available. Was removed')
        return

    URL = apps.get_model('robots', 'URL')

    site = Site.objects.get(pk=1)
    url = URL.objects.create(pattern='/admin')
    rule = Rule.objects.create(robot='*')

    rule.sites.add(site)
    rule.disallowed.add(url)
    rule.save()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0018_auto_20170319_1856'),
    ]

    operations = [
        migrations.RunPython(exclude_admin_from_robots)
    ]
