Prévention des doublons de lieux de stage
This commit is contained in:
parent
0c70d1b76b
commit
db8b92f7ed
3 changed files with 24 additions and 3 deletions
|
@ -117,6 +117,14 @@
|
|||
console.log(lieu);
|
||||
console.log(lieu_focus);
|
||||
if(lieu_focus === undefined) {
|
||||
// Élimination des doublons
|
||||
var candidates = $("input.lieu-hidden");
|
||||
for (var i=0; i<candidates.length; i++) {
|
||||
if($(candidates[i]).val() == lieu.id) {
|
||||
lieu_select.closeWidget();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Créer un nouveau lieu
|
||||
var cnt = $("#id_lieux-TOTAL_FORMS");
|
||||
var i_form = cnt.val()*1;
|
||||
|
|
|
@ -29,7 +29,9 @@ def typonazisme(value):
|
|||
def avis_len(value):
|
||||
if value < 5:
|
||||
return "vide"
|
||||
elif value < 50:
|
||||
elif value < 30:
|
||||
return "court"
|
||||
elif value < 100:
|
||||
return "moyen"
|
||||
else:
|
||||
return "fourni"
|
||||
return "long"
|
||||
|
|
|
@ -174,7 +174,7 @@ def save_lieu(request):
|
|||
|
||||
# Validation et enregistrement
|
||||
if form.is_valid():
|
||||
lieu = form.save()
|
||||
lieu = form.save(commit=False)
|
||||
if jitter:
|
||||
cdx, cdy = lieu.coord.get_coords()
|
||||
ang = random.random() * 6.29;
|
||||
|
@ -183,6 +183,17 @@ def save_lieu(request):
|
|||
cdy += math.sin(ang) * rad;
|
||||
lieu.coord.set_coords((cdx, cdy))
|
||||
lieu.save()
|
||||
|
||||
# Élimination des doublons
|
||||
if pk is None or pk == "":
|
||||
olieux = Lieu.objects.filter(nom=lieu.nom, coord__distance_lte=(lieu.coord, 10))
|
||||
for olieu in olieux:
|
||||
if olieu.type_lieu == lieu.type_lieu and \
|
||||
olieu.ville == lieu.ville and \
|
||||
olieu.pays == lieu.pays:
|
||||
return JsonResponse({"success": True, "id": olieu.id})
|
||||
|
||||
lieu.save()
|
||||
return JsonResponse({"success": True, "id": lieu.id})
|
||||
else:
|
||||
return JsonResponse({"success": False,
|
||||
|
|
Loading…
Reference in a new issue