# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-07 15:31
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models

import pretix.base.validators


def merge_names(apps, schema_editor):
    User = apps.get_model('pretixbase', 'User')
    for u in User.objects.all():
        if u.givenname:
            if u.familyname:
                u.fullname = u.givenname + " " + u.familyname
            else:
                u.fullname = u.givenname
        elif u.familyname:
            u.fullname = u.familyname
        u.save()


class Migration(migrations.Migration):

    dependencies = [
        ('pretixbase', '0056_auto_20170107_1251'),
    ]

    operations = [
        migrations.AddField(
            model_name='user',
            name='fullname',
            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Full name'),
        ),
        migrations.AlterField(
            model_name='organizer',
            name='slug',
            field=models.CharField(max_length=50, db_index=True, help_text='Should be short, only contain lowercase letters and numbers, and must be unique among your events. This is being used in addresses and bank transfer references.', validators=[django.core.validators.RegexValidator(message='The slug may only contain letters, numbers, dots and dashes.', regex='^[a-zA-Z0-9.-]+$'), pretix.base.validators.OrganizerSlugBanlistValidator()], verbose_name='Short form'),
        ),
        migrations.RunPython(merge_names, migrations.RunPython.noop)
    ]
