From 0bb94c2e850a856c04c3551fe577101d2fd97797 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Wed, 5 Jul 2023 15:11:57 +0200 Subject: [PATCH] fix repo creation for authors with accents --- .../management/commands/advance_git_repos.py | 2 +- scipost_django/production/models.py | 9 +++++++-- scipost_django/production/tests/test_models.py | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/scipost_django/production/management/commands/advance_git_repos.py b/scipost_django/production/management/commands/advance_git_repos.py index c9640dfa9..00c16f2d1 100644 --- a/scipost_django/production/management/commands/advance_git_repos.py +++ b/scipost_django/production/management/commands/advance_git_repos.py @@ -42,7 +42,7 @@ class Command(BaseCommand): def add_arguments(self, parser: CommandParser) -> None: parser.add_argument( "--id", - type=int, + type=str, required=False, help="The submission preprint identifier to handle a specific submission, leave blank to handle all", ) diff --git a/scipost_django/production/models.py b/scipost_django/production/models.py index 55023d88c..1840901a7 100644 --- a/scipost_django/production/models.py +++ b/scipost_django/production/models.py @@ -15,6 +15,8 @@ from django.db.models import Value from django.db.models.functions import Concat from django.conf import settings +from common.utils import latinise + from .constants import ( PRODUCTION_STREAM_STATUS, PRODUCTION_STREAM_INITIATED, @@ -312,8 +314,11 @@ class ProofsRepository(models.Model): first_author_last_name = first_author_str.split(" ")[-1] else: first_author_last_name = first_author_profile.last_name - # Keep only the last of the last names - first_author_last_name = first_author_last_name.split(" ")[-1] + + # Remove accents from the last name to avoid encoding issues + # and join multiple last names into one + first_author_last_name = latinise(first_author_last_name).strip() + first_author_last_name = first_author_last_name.replace(" ", "-") return "{preprint_id}_{last_name}".format( preprint_id=self.stream.submission.preprint.identifier_w_vn_nr, diff --git a/scipost_django/production/tests/test_models.py b/scipost_django/production/tests/test_models.py index e35c6d72e..78a12ca5f 100644 --- a/scipost_django/production/tests/test_models.py +++ b/scipost_django/production/tests/test_models.py @@ -153,7 +153,7 @@ class TestProofRepository(TestCase): user_profile.last_name = "Usable User" user_profile.save() - self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Usable-User") def test_repo_name_two_authors(self): proofs_repo = ProofsRepository.objects.get( @@ -166,6 +166,20 @@ class TestProofRepository(TestCase): self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Person") + def test_repo_name_accented_authors(self): + proofs_repo = ProofsRepository.objects.get( + stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" + ) + + user_profile = Contributor.objects.get(user__username="testuser").profile + user_profile.first_name = "Some" + user_profile.last_name = "Pérsønüsær (陈)" + user_profile.save() + + proofs_repo.stream.submission.author_list = "Some Pérsønüsær (陈)" + + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Personusaer") + def test_repo_paths_scipostphys(self): proofs_repo = ProofsRepository.objects.get( stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" -- GitLab