From cfafe2f0b3c9d1af1d24c05aa0084958ada0cd87 Mon Sep 17 00:00:00 2001 From: lokses Date: Mon, 21 Sep 2026 15:52:57 +0300 Subject: [PATCH] =?UTF-8?q?hiring:=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5=20<=D0=B1?= =?UTF-8?q?=D1=83=D0=BA=D0=B2=D0=B0=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8>.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Иван Иванов -> i.ivanov (транслит pytils, нижний регистр, коллизия +счётчик). Раньше slugify('Фамилия.Имя') терял точку и давал ivanovivan. Единый формат в найме (_generate_username) и в импорте (transliterate_username). Co-Authored-By: Claude Opus 4.8 --- .../management/commands/import_employees_json.py | 4 +++- apps/hiring/services.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/employees/management/commands/import_employees_json.py b/apps/employees/management/commands/import_employees_json.py index 3d6f45e..2a5e4fa 100644 --- a/apps/employees/management/commands/import_employees_json.py +++ b/apps/employees/management/commands/import_employees_json.py @@ -58,7 +58,9 @@ DEPT_73_NAME_TO_CODE = { def transliterate_username(last_name, first_name, taken): from pytils.translit import slugify - base = slugify(f'{last_name}.{first_name}') or 'user' + # Формат: <первая буква имени>.<фамилия> (Иван Иванов -> i.ivanov). + ln, fn = slugify(last_name), slugify(first_name) + base = f'{fn[:1]}.{ln}'.strip('.') or 'user' username = base counter = 1 while username in taken or Employee.objects.filter(username=username).exists(): diff --git a/apps/hiring/services.py b/apps/hiring/services.py index 57469c9..82451a0 100644 --- a/apps/hiring/services.py +++ b/apps/hiring/services.py @@ -11,8 +11,17 @@ from apps.employees.models.base import Employee from apps.hiring.models import HiringRequest, InternAccount +def _username_base(last_name, first_name): + """Формат логина: <первая буква имени>.<фамилия>, транслит, нижний регистр. + Иван Иванов -> i.ivanov.""" + ln = slugify(last_name) + fn = slugify(first_name) + initial = fn[:1] + return f'{initial}.{ln}'.strip('.') or 'user' + + def _generate_username(last_name, first_name): - base = slugify(f'{last_name}.{first_name}') or 'user' + base = _username_base(last_name, first_name) username = base counter = 1 while Employee.objects.filter(username=username).exists():