SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 48fc66c8 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

feat: add initials to authorship matching filter

parent 526cee2b
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,13 @@ from ..constants import CHARACTER_ALTERNATIVES, CHARACTER_LATINISATIONS
import unicodedata
def initialize(name: str) -> str:
"""
Convert a full name to its initials.
"""
return " ".join([word.upper()[0] + "." for word in name.split()])
def unaccent(text: str) -> str:
"""
Remove accented characters in the given string (e.g. é -> e),
......
......@@ -11,6 +11,7 @@ from django.utils import timezone
from comments.models import Comment
from common.utils.db import SplitString
from common.utils.text import initialize
from .. import constants
......@@ -163,7 +164,14 @@ class SubmissionQuerySet(models.QuerySet):
return (
self.filter(
Q(author_list__unaccent__icontains=contributor.user.last_name)
& Q(author_list__unaccent__icontains=contributor.user.first_name)
& (
Q(author_list__unaccent__icontains=contributor.user.first_name)
| Q(
author_list__unaccent__icontains=initialize(
contributor.user.first_name
)
)
)
)
.exclude(authors=contributor)
.exclude(authors_claims=contributor)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment