Hi,
I am programming a middleware that keeps track of the visits made to
my webpage. I keep track of the IP addresses and I add to this a Visit
each time a user comes back. I consider a visit is new when a given
interval (30 minutes,...) passes between visits.
In order to keep track of the last visit, I use the sessions
middleware, and i keep in memory the last visited date.
The problem is, I modify my request.session in the middleware, but the
value does not seem to be kept in memory. I've tried several
solutions, but I can not understand what I am doing wrong. Any help
appreciated.
My code is at the end.
Thanks a lot,
Guille
from datetime import *
from sysvortex.ips.models import Ipaddress, Visit
INTERVAL = 1
class IpMiddleware:
def _add_ip(this_ip):
try:
ip=Ipaddress.objects.get(ip=this_ip)
except:
ip=Ipaddress(ip=this_ip)
ip.save()
ip.visit_set.create()
def process_view(self, request, view_func, view_args, view_kwargs):
last_visit=request.session.get('sysvortex_last_visit', datetime.now())
difference=datetime.now()-last_visit
if difference > timedelta(minutes=INTERVAL):
self._add_ip(request.META['REMOTE_ADDR'])
return None
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---