From 43af14ad7736aaf23fe8915211bf0494dd446cbb Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Mon, 10 Apr 2023 17:26:30 +0200 Subject: [PATCH] Search juries by "{first_name} {last_name}" Signed-off-by: Emmy D'Anello --- participation/forms.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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