Update chrono details add function
This commit is contained in:
parent
05e130355a
commit
ca629fd1fb
|
@ -128,21 +128,31 @@ def remove_jump_chrono_value(request):
|
|||
@require_http_methods(["POST"])
|
||||
def add_jump_chrono_value(request):
|
||||
"""
|
||||
Recoit trois informations permettant d'ajouter le chrono d'un saut à un chrono.
|
||||
Receives three pieces of information to add the time of a jump to a <Chrono> record.
|
||||
"""
|
||||
chrono_id = request.POST.get("chrono_id", None)
|
||||
order = request.POST.get("order", None)
|
||||
value = request.POST.get("value", None)
|
||||
chrono_id = request.POST.get("chrono_id")
|
||||
order = request.POST.get("order")
|
||||
value = request.POST.get("value")
|
||||
|
||||
# Validate required parameters
|
||||
if not chrono_id or not order or value is None:
|
||||
return HttpResponse(400, "Missing required parameters.")
|
||||
|
||||
# Retrieve the Chrono object or return 404 if not found
|
||||
chrono = get_object_or_404(Chrono, pk=chrono_id)
|
||||
|
||||
# Attempt to create a new ChronoDetails record
|
||||
row, created = ChronoDetails.objects.get_or_create(
|
||||
# chrono=chrono, order=order, defaults={'value': value}
|
||||
chrono=chrono, order=order, value=value
|
||||
)
|
||||
|
||||
# Check if the record was created or just retrieved
|
||||
if created:
|
||||
return HttpResponse(200, (row, created)) # devrait être un 201
|
||||
|
||||
return HttpResponse(400, (row, created))
|
||||
return HttpResponse(201, f"New chrono detail added: {row}") # 201 Created
|
||||
else:
|
||||
# If the record was not created, it means it already exists with the same order and chrono
|
||||
return HttpResponse(409, f"Chrono detail already exists: {row}") # 409 Conflict
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue