On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson <[email protected]> wrote:
> Hi,
>
> If you use a custom authentication backend, you could update it every time
> get_user(request) is called.
>

HTTP is stateless, authentication happens every request, so that gets
called on every request, causing session modification on each request.

How about:

    from django.utils import timezone

    class DailyLoginMiddleware(object):
        def process_request(self, request):
            if request.user.is_authenticated():
                today = timezone.now().strftime('%Y%m%d')
                if request.session.get('last_seen') != today:
                    request.session['last_seen'] = today
                    setattr(request, 'new_today', True)

Store todays date in the session, check to see if it is changed, only
modify the session if the date has changed, set an attribute on the
request so that later views can include that information.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1JE6ZrMzLAdxCuOowe3hL3%3DmOZOPRx13YAzFqKSfufG4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to