On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson <
cmawe...@gmail.com> 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