model sends two requests

21 views
Skip to first unread message

jonas peters

unread,
Jul 9, 2012, 12:26:15 PM7/9/12
to django...@googlegroups.com
hi!

I have a model and use standard django administration, when a user clicks the save button it sends the request, it takes time to respond and the user clicks the save button again and then sends another request, and creating two records. have some setting in django to avoid this problem? I thought about locking the save button when it is clicked so the user does not click more than once to complete the request.

Sorry my english Thanks!
Message has been deleted

jonas peters

unread,
Jul 10, 2012, 7:22:31 AM7/10/12
to django...@googlegroups.com
Thanks, helped me a lot.



Em segunda-feira, 9 de julho de 2012 17h53min23s UTC-3, Dennis Lee Bieber escreveu:
On Mon, 9 Jul 2012 09:26:15 -0700 (PDT), jonas peters
<jonas.p...@gmail.com> declaimed the following in
gmane.comp.python.django.user:
        In general (that is, not Django specific), my experience is that
potentially slow sites in which an extra submittal would cause problems
tend to include a warning message to only click once (the sites I've
seen this on tend to be online markets -- where the warning is that
double clicking could result in a second order charged to the credit
card.

        The other general solution would be to collect the data, send it to
a separate worker thread/process and immediately return a "please wait"
type response -- this response should have an automatic redirect (using
a cookie to identify the worker) to a page that will either find the
worker thread has finished and can return the real next page -- or if
the worker is still busy resend the "please wait" page.

        More specific modes:
http://www.turnkeylinux.org/blog/prevent-double-click-form-submission
(general search: prevent double click form submit
http://www.google.com/#hl=en&sclient=psy-ab&q=prevent+double+click+form+submit&oq=prevent+double+click+form+submit&gs_l=serp.3..0i30j0i5i30.8464.23704.0.23926.28.25.2.1.1.6.503.4601.0j21j3j5-1.25.0...0.0.c3W_7yOZRzI&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=9da4b66dc5fd8e9a&biw=1044&bih=748
)


        
> Sorry my english Thanks!
--
        Wulfraed                 Dennis Lee Bieber         AF6VN
        wlf...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Jani Tiainen

unread,
Jul 11, 2012, 12:30:03 PM7/11/12
to django...@googlegroups.com
In one public site we ended up doing both, server side re-submission checks and client side javascript with timeout re-enable "hack".

We just store magic key to cache which is checked on every submission. If magic key is missing submission is valid (first one) and key is set if
form was valid:

if request.method == 'POST':
        if cache.get('%s.%s' % (request.session.session_key, data['unique_id'])):
            if form.is_valid():
                cache.set(('%s.%s' % (request.session.session_key, data['unique_id']), true) # Block subsequent requests
            else:
                pass # Output error messages about form
        else:
            # Key is in the cache, fail
            return HttpResponseBadRequest()
    

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ZU-HtLFqcp4J.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

Reply all
Reply to author
Forward
0 new messages