Allow check-in searches on multiple words to be split
authorMagnus Hagander <magnus@hagander.net>
Tue, 7 Oct 2025 12:49:57 +0000 (14:49 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 7 Oct 2025 12:56:26 +0000 (14:56 +0200)
Previously a search for "first last" would require it to be specified
exactly like that as part of either first or last name, and thus
unlikely ever match anything.

Change that to split the search string on whitespace and search
individually for each of the names.

Fixes #191

postgresqleu/confreg/checkin.py

index c38d35f12449374a51bb0d7482d0644afd8b8d49..84dde1e49d9ca464816ba1af061dba3f325949e9 100644 (file)
@@ -314,9 +314,15 @@ def api(request, urlname, regtoken, what):
         return _json_response({'reg': _get_reg_json(r)})
     elif what == 'search':
         s = request.GET.get('search').strip()
+        q = Q()
+        for n in s.split():
+            # For each part of the given string, search both first and last name
+            # When two or more name parts are specified, require that they all match,
+            # but don't care which one matches which part.
+            q = q & (Q(firstname__icontains=n) | Q(lastname__icontains=n))
         return _json_response({
             'regs': [_get_reg_json(r) for r in ConferenceRegistration.objects.filter(
-                Q(firstname__icontains=s) | Q(lastname__icontains=s),
+                q,
                 conference=conference, payconfirmedat__isnull=False, canceledat__isnull=True,
             )],
         })