EDIT
finally I use window.onpopstate event to prevent user go back it works with Firefox but not with Chrome 79 (and other browsers?)
I have read many posts and official documentation that seems to say that this 'bug' was fixed after Chrome 34... but doesn't seems to be to be honest, event reading the documentation, I do not really understand this event and the behavior so far...
How can I resolve this?
I know this topic has been already discuss but none of solutions resolve my problem.
I have 3 forms that update the same models. I would like to manage/prevent user going back using back arrow.
I tried using window.location, window.onhashchange = function () {}, flag session variable but nothing works and I am lost
When user click on back arrow from 2nd form to go back to 1st form, I would like either the event is blocked (best), either user is redirected to home page
I notice that click on back arrow on the 2nd form do not call index view, reason why 'flag strategy' do not work
@login_required
@permission_required('unblind.can_unblind')
def index(request):
if request.method == "POST":
form = AveugleProcedureForm(request, data=request.POST or None)
if form.is_valid():
unblind = form.save()
# database treatment
return redirect('unblind:edit', pk = unblind.pk)
else:
form = AveugleProcedureForm(request)
return render(request, 'unblind/index.html', {'form': form})
@login_required
@permission_required('unblind.can_unblind')
def edit(request, pk):
if request.method == "POST":
form = AveugleForm(request, data=request.POST or None)
if form.is_valid():
# unblind = form.save()
# database treatment
unblind = Aveugle.objects.get(unb_ide = pk)
unblind.unb_pro = form.cleaned_data['unb_pro']
unblind.unb_nom_dem = form.cleaned_data['unb_nom_dem']
unblind.unb_nom_rea = form.cleaned_data['unb_nom_rea']
unblind.unb_dat = form.cleaned_data['unb_dat']
unblind.pat = form.cleaned_data['pat']
unblind.unb_num = form.cleaned_data['unb_num']
unblind.unb_mot = form.cleaned_data['unb_mot']
unblind.save()
# contrôler le couple numéro patient/boite de médicament
# récupération du traitement
treatment = Medicament.objects.get(med_num = unblind.unb_num).med_dru
# envoie d'un email de confirmation
if treatment == 1:
unblind_treatment = _('ASPIRIN')
else:
unblind_treatment = _('PLACEBO')
email(unblind.pat,unblind.unb_num,unblind_treatment,unblind.unb_mot)
return redirect('unblind:result', pk = unblind.pk)
else:
form = AveugleForm(request)
return render(request, 'unblind/edit.html', {'form': form,'pk': pk})
@login_required
@permission_required('unblind.can_unblind')
def result(request, pk):
# Récupération de l'enregistrement
unblind = Aveugle.objects.get(unb_ide = pk)
treatment = Medicament.objects.get(med_num = unblind.unb_num).med_dru
if request.method == "POST":
form = AveugleResultForm(request, data=request.POST or None)
if form.is_valid():
# database treatment
unblind.unb_rec = form.cleaned_data['unb_rec']
# unblind.unb_com = form.cleaned_data['unb_com']
unblind.unb_log_dat = datetime.now()
unblind.unb_log = request.user.username
unblind.unb_log_sit = request.session['selected_site']
unblind.save()
return redirect('home')
else:
form = AveugleResultForm(request)
return render(request, 'unblind/result.html', {'form': form,'unblind':unblind,'treatment':treatment})