diff --git a/participation/forms.py b/participation/forms.py index e7848c7..a9fed47 100644 --- a/participation/forms.py +++ b/participation/forms.py @@ -13,6 +13,8 @@ from django import forms from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.core.validators import FileExtensionValidator +from django.db.models import CharField, Value +from django.db.models.functions import Concat from django.utils.translation import gettext_lazy as _ from pypdf import PdfReader @@ -301,10 +303,10 @@ class UploadNotesForm(forms.Form): _("The following note is higher of the maximum expected value:") + str(n) + " > " + str(max_n)) - first_name, last_name = tuple(name.replace('’', '\'').split(' ', 1)) - - jury = User.objects.filter(first_name=first_name, last_name=last_name, - registration__volunteerregistration__isnull=False) + # Search by "{first_name} {last_name}" + jury = User.objects.annotate(full_name=Concat('first_name', Value(' '), 'last_name', + output_field=CharField())) \ + .filter(full_name=name.replace('’', '\''), registration__volunteerregistration__isnull=False) if jury.count() != 1: self.add_error('file', _("The following user was not found:") + " " + name) continue