diff options
-rw-r--r-- | ishtar_common/migrations/0040_auto_20180409_1821.py | 55 | ||||
-rw-r--r-- | ishtar_common/models.py | 44 |
2 files changed, 99 insertions, 0 deletions
diff --git a/ishtar_common/migrations/0040_auto_20180409_1821.py b/ishtar_common/migrations/0040_auto_20180409_1821.py new file mode 100644 index 000000000..bdf27cfc2 --- /dev/null +++ b/ishtar_common/migrations/0040_auto_20180409_1821.py @@ -0,0 +1,55 @@ +# -*- 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/models.py b/ishtar_common/models.py index b92614e08..7c2069309 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2470,6 +2470,24 @@ class Person(Address, Merge, OwnPerms, ValueGetter): [unicode(getattr(self, attr)) for attr in ['title', 'salutation'] if getattr(self, attr)]) + @property + def default_profile(self): + q = self.profiles.filter(default=True) + if q.count(): + return q.all()[0] + q = self.profiles + nb = q.count() + if not nb: + return + if nb > 1: + # arbitrary return the first one + return q.all()[0] + # if there is only one it is the default + profile = q.all()[0] + profile.default = True + profile.save() + return profile + def simple_lbl(self): values = [unicode(getattr(self, attr)) for attr in ('surname', 'name') if getattr(self, attr)] @@ -2630,6 +2648,32 @@ class Person(Address, Merge, OwnPerms, ValueGetter): =user.ishtaruser) +class ProfileType(GeneralType): + groups = models.ManyToManyField(Group, verbose_name=_(u"Groups"), + blank=True) + + class Meta: + verbose_name = _(u"Profile type") + verbose_name_plural = _(u"Profile types") + ordering = ('label',) + + +post_save.connect(post_save_cache, sender=ProfileType) +post_delete.connect(post_save_cache, sender=ProfileType) + + +class UserProfile(models.Model): + profile_type = models.ForeignKey( + ProfileType, verbose_name=_(u"Profile type")) + default = models.BooleanField(_(u"Default profile"), default=False) + person = models.ForeignKey( + Person, verbose_name=_(u"Person"), related_name='profiles') + + class Meta: + verbose_name = _(u"User profile") + verbose_name_plural = _(u"User profiles") + + class IshtarUser(FullSearch): TABLE_COLS = ('username', 'person__name', 'person__surname', 'person__email', 'person__person_types_list', |