Commit dd86a31c by Yvon Kerdoncuff

minimal refactoring + comments

parent 8d05ac97
Pipeline #4049 failed with stage
in 0 seconds
...@@ -394,7 +394,7 @@ def update_members_makeups(request): ...@@ -394,7 +394,7 @@ def update_members_makeups(request):
if is_connected_user is True: if is_connected_user is True:
members_data = json.loads(request.body.decode()) members_data = json.loads(request.body.decode())
# Make sure update would not unsubscribe member # Perform checks and compute some data in a loop on members.
cs = CagetteShift() cs = CagetteShift()
unsubscription_limit = api.get_system_param('lacagette_membership.points_limit_to_get_unsubscribed') unsubscription_limit = api.get_system_param('lacagette_membership.points_limit_to_get_unsubscribed')
for member_data in members_data: for member_data in members_data:
...@@ -408,14 +408,16 @@ def update_members_makeups(request): ...@@ -408,14 +408,16 @@ def update_members_makeups(request):
error["error"] = "L'opération de rattrapage a été annulée car le nombre de rattrapage cible est négatif." error["error"] = "L'opération de rattrapage a été annulée car le nombre de rattrapage cible est négatif."
return JsonResponse(error, status=400) return JsonResponse(error, status=400)
makeup_change_count = target_makeups_nb - cs.get_member_makeups_to_do(cm.id) makeup_change_count = target_makeups_nb - cs.get_member_makeups_to_do(cm.id)
members_data[member_data["member_id"]]["points_diff"] = - makeup_change_count
points_target = cm.get_member_points("standard") - makeup_change_count points_target = cm.get_member_points("standard") - makeup_change_count
if points_target <= unsubscription_limit: if points_target <= unsubscription_limit:
error = [] error = []
error["error"]\ error["error"]\
= "L'ajout de rattrapage a été annulé car il provoquerait la désinscription d'un membre." = "L'ajout de rattrapage a été annulé car il provoquerait la désinscription d'un membre."
return JsonResponse(error, status=400) return JsonResponse(error, status=400)
# Save computed data in member_data. It will be useful to update makeups and points.
members_data[member_data["member_id"]]["points_diff"] = - makeup_change_count
# Update makeups and points
res["res"] = [] res["res"] = []
update_members_makeups_core(members_data, res) update_members_makeups_core(members_data, res)
response = JsonResponse(res) response = JsonResponse(res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment