Sunday, December 30, 2012

Re: Actions after logout

Michael,

How will the server know that they user has logged out?  If by clicking a logout link or button, fine, you can capture that and delete the data.

But it sounds like you also want to do this when the user "leaves the page".  That is much harder.  The user's browser does not tell the server when the user leaves the page.  So the server normally doesn't know that the user has left the page (or closed his browser, or shut down his computer).

It is possible to have JavaScript, which runs on the browser, send a "heartbeat" AJAX request to the server at regular intervals, so the server could assume that the user has "left the page" if after some amount of time, longer than the specified interval, it has not received such a request.  This is pretty messy, and won't work if JavaScript is not available in the user's browser.  It requires a process, one that is independent of Django receiving a request, to look at all such partial data sets, find the time that the JavaScript last contacted the server, and delete the data if it was too long ago.  You must have the timestamp of the AJAX access stored somewhere that persists between requests, either in the database with the data, or on the session (which can still wind up in the database).  So for each AJAX "ping" you have not only a request/response pair on the network, but a database access.  Also, your choice of interval must take into account that the user may have a very slow link, and that the network may be temporarily overloaded.

A more common way to expire partially completed form sequence data is to store a timestamp with the model collecting the data at each request that changes it (form submission).  Then limit the time allowed between steps, again using a background process that runs periodically to see if there are incomplete data sets whose last change time is longer ago than you allow per step, and if so, delete them.  Note that the time for a deletion to happen can be up to the sum of the allowed time and the period between runnings of the background task.  I have implemented this technique with rather long timeouts, running the background task once per day, but you can run it more often, at the expense of additional database traffic and server load.  Consider that your user may be called away to answer a phone call or some other urgency, and provide a reasonably long timeout.

A final approach is to not store any data, but return it to the browser in hidden fields of the next from.  This is fine if you are simply breaking things into steps for the purposes of presenting the user with an interface organized as bite sized pieces, but if you need to reserve something in an earlier step, e.g.; a user name during a sign up sequence, then you must make the reservation in the database.

Bill

On Sun, Dec 30, 2012 at 1:35 PM, r4m <4thegdlife@googlemail.com> wrote:
Hallo Ryan,

thank you for your advice.
What I meant by process is that I've developed a APP user can insert
data on 4 forms. If they do not complete them on the fourth form, I
want to delete the data after logout our leaving the page.

Greetings,
Michael

On Sat 29 Dec 2012 08:25:26 PM CET, Ryan Blunden wrote:
> When you say you haver a "process in place", do you mean code sitting
> in a file?
>
> If you haven't already, create a logout url and hook it up to your
> code to delete the log out data. Then just call
> *django.contrib.auth.logout() *somewhere in your logout view.
>
> Cheers,
> Ryan
>
> On 27/12/2012, at 6:50 AM, 4 The good Life we work
> <4thegdlife@googlemail.com <http://googlemail.com>> wrote:
>
>> Hallo,
>>
>> I would like to delete certain data + login data after logout.
>>
>> I have a process in place and would like to delete the
>> data inserted if the process is not followed to the last step.
>>
>> Thanks for your support,
>> Michael
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto:django-users@googlegroups.com>.
>> To unsubscribe from this group, send email to
>> django-users+unsubscribe@googlegroups.com
>> <mailto:django-users+unsubscribe@googlegroups.com>.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment