fix: don't create a volunteer object when a person has already volunt… (#6809)

* fix: don't create a volunteer object when a person has already volunteered

* fix: safer create

* refactor: use shorthand from django

* fix: also protect volunteer from datatracker from race
This commit is contained in:
Robert Sparks 2023-12-18 16:49:27 -06:00 committed by GitHub
parent 661e11ff63
commit ca664c4162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -210,11 +210,14 @@ def api_new_meeting_registration(request):
except (NomCom.DoesNotExist, NomCom.MultipleObjectsReturned):
nomcom = None
if nomcom:
Volunteer.objects.create(
Volunteer.objects.get_or_create(
nomcom=nomcom,
person=object.person,
affiliation=data['affiliation'],
origin='registration')
defaults={
"affiliation": data["affiliation"],
"origin": "registration"
}
)
return HttpResponse(response, status=202, content_type='text/plain')
else:
return HttpResponse(status=405)

View file

@ -1373,7 +1373,7 @@ def volunteer(request):
form = VolunteerForm(person=person, data=request.POST)
if form.is_valid():
for nc in form.cleaned_data['nomcoms']:
nc.volunteer_set.create(person=person, affiliation=form.cleaned_data['affiliation'])
nc.volunteer_set.get_or_create(person=person, defaults={"affiliation": form.cleaned_data["affiliation"], "origin":"datatracker"})
return redirect('ietf.ietfauth.views.profile')
else:
form = VolunteerForm(person=person,initial=dict(nomcoms=can_volunteer, affiliation=suggest_affiliation(person)))