Thanks. Though I do not use a Custom Authentication Backend, it should be possible to inherit from the Default one and just overwrite the get_user Method. I will test it out.
On Friday, January 30, 2015 at 3:56:10 PM UTC+1, Tom Evans wrote: > > On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson <[email protected] > <javascript:>> 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/0a7e4a2e-2f05-45e4-9633-14d60dce78a8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

