From 7f5a100fd07af4b8be51f524b81ae9d8776ca9b0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 9 Apr 2018 19:06:10 +0200 Subject: Profile: default->current --- .../migrations/0040_auto_20180409_1821.py | 55 ---------------------- .../migrations/0040_auto_20180409_1900.py | 55 ++++++++++++++++++++++ .../migrations/0041_auto_20180409_1759.py | 51 -------------------- .../migrations/0041_auto_20180409_1901.py | 51 ++++++++++++++++++++ 4 files changed, 106 insertions(+), 106 deletions(-) delete mode 100644 ishtar_common/migrations/0040_auto_20180409_1821.py create mode 100644 ishtar_common/migrations/0040_auto_20180409_1900.py delete mode 100644 ishtar_common/migrations/0041_auto_20180409_1759.py create mode 100644 ishtar_common/migrations/0041_auto_20180409_1901.py (limited to 'ishtar_common/migrations') diff --git a/ishtar_common/migrations/0040_auto_20180409_1821.py b/ishtar_common/migrations/0040_auto_20180409_1821.py deleted file mode 100644 index bdf27cfc2..000000000 --- a/ishtar_common/migrations/0040_auto_20180409_1821.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-09 18:21 -from __future__ import unicode_literals - -import django.core.validators -from django.db import migrations, models -import django.db.models.deletion -import ishtar_common.models -import re - - -class Migration(migrations.Migration): - - dependencies = [ - ('auth', '0009_merge_20170821_1827'), - ('ishtar_common', '0039_auto_20180405_1923'), - ] - - operations = [ - migrations.CreateModel( - name='ProfileType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('label', models.TextField(verbose_name='Label')), - ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), - ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), - ('available', models.BooleanField(default=True, verbose_name='Available')), - ('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), - ], - options={ - 'ordering': ('label',), - 'verbose_name': 'Profile type', - 'verbose_name_plural': 'Profile types', - }, - bases=(ishtar_common.models.Cached, models.Model), - ), - migrations.CreateModel( - name='UserProfile', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('default', models.BooleanField(default=False, verbose_name='Default profile')), - ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='profiles', to='ishtar_common.Person', verbose_name='Person')), - ('profile_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ProfileType', verbose_name='Profile type')), - ], - options={ - 'verbose_name': 'User profile', - 'verbose_name_plural': 'User profiles', - }, - ), - migrations.AlterField( - model_name='import', - name='state', - field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'), - ), - ] diff --git a/ishtar_common/migrations/0040_auto_20180409_1900.py b/ishtar_common/migrations/0040_auto_20180409_1900.py new file mode 100644 index 000000000..a8cf51e33 --- /dev/null +++ b/ishtar_common/migrations/0040_auto_20180409_1900.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-09 19:00 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import ishtar_common.models +import re + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0009_merge_20170821_1827'), + ('ishtar_common', '0039_auto_20180405_1923'), + ] + + operations = [ + migrations.CreateModel( + name='ProfileType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('label', models.TextField(verbose_name='Label')), + ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), + ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), + ], + options={ + 'ordering': ('label',), + 'verbose_name': 'Profile type', + 'verbose_name_plural': 'Profile types', + }, + bases=(ishtar_common.models.Cached, models.Model), + ), + migrations.CreateModel( + name='UserProfile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('current', models.BooleanField(default=False, verbose_name='Current profile')), + ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='profiles', to='ishtar_common.Person', verbose_name='Person')), + ('profile_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ProfileType', verbose_name='Profile type')), + ], + options={ + 'verbose_name': 'User profile', + 'verbose_name_plural': 'User profiles', + }, + ), + migrations.AlterField( + model_name='import', + name='state', + field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'), + ), + ] diff --git a/ishtar_common/migrations/0041_auto_20180409_1759.py b/ishtar_common/migrations/0041_auto_20180409_1759.py deleted file mode 100644 index 2ea56823a..000000000 --- a/ishtar_common/migrations/0041_auto_20180409_1759.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-04-09 17:29 -from __future__ import unicode_literals - -from django.db import migrations - - -def initialize_profiles(apps, schema_editor): - # Migrate PersonType -> ProfileType - PersonType = apps.get_model('ishtar_common', 'PersonType') - ProfileType = apps.get_model('ishtar_common', 'ProfileType') - UserProfile = apps.get_model('ishtar_common', 'UserProfile') - Person = apps.get_model('ishtar_common', 'Person') - - # create profile types from person types - profile_types = {} - for person_type in PersonType.objects.all(): - default = { - 'label': person_type.label, - 'comment': person_type.comment, - 'available': person_type.available, - } - pt, created = ProfileType.objects.get_or_create( - txt_idx=person_type.txt_idx, defaults=default) - if created: - for gp in person_type.groups.all(): - pt.groups.add(gp) - profile_types[pt.txt_idx] = pt - - # match profile type with person types - for person in Person.objects.filter(ishtaruser__isnull=False): - # is default if only one person_type is concerned - default = person.person_types.count() == 1 - # only person with an account are concerned - for person_type in person.person_types.all(): - UserProfile.objects.create( - profile_type=profile_types[person_type.txt_idx], - person=person, - default=default - ) - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0040_auto_20180409_1821'), - ] - - operations = [ - migrations.RunPython(initialize_profiles), - ] diff --git a/ishtar_common/migrations/0041_auto_20180409_1901.py b/ishtar_common/migrations/0041_auto_20180409_1901.py new file mode 100644 index 000000000..cc34bb91c --- /dev/null +++ b/ishtar_common/migrations/0041_auto_20180409_1901.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-04-09 17:29 +from __future__ import unicode_literals + +from django.db import migrations + + +def initialize_profiles(apps, schema_editor): + # Migrate PersonType -> ProfileType + PersonType = apps.get_model('ishtar_common', 'PersonType') + ProfileType = apps.get_model('ishtar_common', 'ProfileType') + UserProfile = apps.get_model('ishtar_common', 'UserProfile') + Person = apps.get_model('ishtar_common', 'Person') + + # create profile types from person types + profile_types = {} + for person_type in PersonType.objects.all(): + default = { + 'label': person_type.label, + 'comment': person_type.comment, + 'available': person_type.available, + } + pt, created = ProfileType.objects.get_or_create( + txt_idx=person_type.txt_idx, defaults=default) + if created: + for gp in person_type.groups.all(): + pt.groups.add(gp) + profile_types[pt.txt_idx] = pt + + # match profile type with person types + for person in Person.objects.filter(ishtaruser__isnull=False): + # is current if only one person_type is concerned + current = person.person_types.count() == 1 + # only person with an account are concerned + for person_type in person.person_types.all(): + UserProfile.objects.create( + profile_type=profile_types[person_type.txt_idx], + person=person, + current=current + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0040_auto_20180409_1900'), + ] + + operations = [ + migrations.RunPython(initialize_profiles), + ] -- cgit v1.2.3