vendredi 27 octobre 2017

Django: How to handle duplicate form submission

How to handle second submission duplicate request If a user was trying to refresh the page because of the first submission is not finished yet.

  • client side disabling submit button to avoid multiple submits.
  • and handled Post/Redirect/Get pattern after form submit redirect to success view

I believe both are handled well.

class SomeView(View):
  def post(self, request, *args, **kwargs):
    if form.is_valid()
      if request_exists(request):
        # here I can raise the exception also 
        # But How I redirect the customer to sucess page 
        # If 1st submission got success response.
      else:
        # here I have called internal api to get/post some data.
        # user refreshes before this call has completed.
        ...
        # once getting respose its ALWAYS redirect to new page
        return HttpResponseRedirect('/thanks/') 

But how to handle the case If delay from getting a response from API call. I need to delay until the first submission finishes. Then I have to send the user to the thanks page.

Aucun commentaire:

Enregistrer un commentaire