diff options
| -rw-r--r-- | ishtar_common/forms_common.py | 14 | ||||
| -rw-r--r-- | ishtar_common/migrations/0111_ishtarsiteprofile_account_naming_style.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 9 | 
3 files changed, 39 insertions, 4 deletions
| diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 48d0fdc7b..eb4582c3e 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -857,9 +857,15 @@ class AccountForm(IshtarForm):          if 'person' in kwargs:              person = kwargs.pop('person')          super(AccountForm, self).__init__(*args, **kwargs) -        if person and person.raw_name: -            self.fields['username'].initial = \ -                person.raw_name.lower().replace(' ', '.') +        if person and (person.raw_name or (person.name and person.surname)): +            profile = models.IshtarSiteProfile.get_current_profile() +            if person.name and person.surname: +                values = [person.name.lower(), person.surname.lower()] +            else: +                values = person.raw_name.lower().split(" ") +            if profile.account_naming_style == "FN" and len(values) > 1: +                values = values[1:] + [values[0]] +            self.fields['username'].initial = ".".join(values)      def clean(self):          cleaned_data = self.cleaned_data @@ -916,7 +922,7 @@ class FinalAccountForm(forms.Form):      def __init__(self, *args, **kwargs):          self.is_hidden = True -        return super(FinalAccountForm, self).__init__(*args, **kwargs) +        super(FinalAccountForm, self).__init__(*args, **kwargs)  class ProfilePersonForm(forms.Form): diff --git a/ishtar_common/migrations/0111_ishtarsiteprofile_account_naming_style.py b/ishtar_common/migrations/0111_ishtarsiteprofile_account_naming_style.py new file mode 100644 index 000000000..ba08c82a1 --- /dev/null +++ b/ishtar_common/migrations/0111_ishtarsiteprofile_account_naming_style.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-09-16 17:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0110_auto_20190912_1517'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='ishtarsiteprofile', +            name='account_naming_style', +            field=models.CharField(choices=[('NF', 'name.firstname'), ('FN', 'firstname.name')], default='NF', max_length=2, verbose_name='Naming style for accounts'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index adf83bf8e..6f51a840e 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2673,6 +2673,11 @@ TRANSLATED_SITE_LABELS = {      },  } +ACCOUNT_NAMING_STYLE = ( +    ('NF', _("name.firstname")), +    ('FN', _("firstname.name")), +) +  class IshtarSiteProfile(models.Model, Cached):      slug_field = 'slug' @@ -2818,6 +2823,10 @@ class IshtarSiteProfile(models.Model, Cached):                                           default=True)      currency = models.CharField(_("Currency"), default="€",                                  choices=CURRENCY, max_length=5) +    account_naming_style = models.CharField( +        _("Naming style for accounts"), max_length=2, default="NF", +        choices=ACCOUNT_NAMING_STYLE +    )      default_center = models.PointField(          _("Maps - default center"),          default='SRID=4326;POINT(2.4397 46.5528)') | 
