[helloasso] Manage duplicate users + ignore invalid users
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
3e46d06817
commit
14de6cf824
|
@ -5,6 +5,7 @@ import os
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
|
from django.db.models import Q
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,15 +47,30 @@ class Command(BaseCommand):
|
||||||
email = payer["email"]
|
email = payer["email"]
|
||||||
last_name = payer["lastName"]
|
last_name = payer["lastName"]
|
||||||
first_name = payer["firstName"]
|
first_name = payer["firstName"]
|
||||||
qs = User.objects.filter(email=email)
|
base_filter = Q(
|
||||||
|
registration__participantregistration__isnull=False,
|
||||||
|
registration__participantregistration__team__isnull=False,
|
||||||
|
registration__participantregistration__team__participation__valid=True,
|
||||||
|
)
|
||||||
|
qs = User.objects.filter(
|
||||||
|
base_filter,
|
||||||
|
email=email,
|
||||||
|
)
|
||||||
if not qs.exists():
|
if not qs.exists():
|
||||||
qs = User.objects.filter(last_name__icontains=last_name)
|
qs = User.objects.filter(
|
||||||
|
base_filter,
|
||||||
|
last_name__icontains=last_name,
|
||||||
|
)
|
||||||
if qs.count() >= 2:
|
if qs.count() >= 2:
|
||||||
qs = qs.filter(first_name__icontains=first_name)
|
qs = qs.filter(first_name__icontains=first_name)
|
||||||
if not qs.exists():
|
if not qs.exists():
|
||||||
self.stderr.write(f"Warning: a payment was found by {first_name} {last_name} ({email}), "
|
self.stderr.write(f"Warning: a payment was found by {first_name} {last_name} ({email}), "
|
||||||
"but this user is unknown.")
|
"but this user is unknown.")
|
||||||
continue
|
continue
|
||||||
|
if qs.count() > 1:
|
||||||
|
self.stderr.write(f"Warning: a payment was found by {first_name} {last_name} ({email}), "
|
||||||
|
f"but there are {qs.count()} matching users.")
|
||||||
|
continue
|
||||||
user = qs.get()
|
user = qs.get()
|
||||||
if not user.registration.participates:
|
if not user.registration.participates:
|
||||||
self.stderr.write(f"Warning: a payment was found by the email address {email}, "
|
self.stderr.write(f"Warning: a payment was found by the email address {email}, "
|
||||||
|
|
Loading…
Reference in New Issue