On Jul 9, 2006, at 6:56 AM, Guillermo Fernandez Castellanos wrote:
>
> class IpMiddleware:
> def _add_ip(this_ip):
> # Adds IP and Visit to database
> [...]
> 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=30):
> self._add_ip(request.META['REMOTE_ADDR'])
> return None
>
> My problem is, I can not make the request.session to store my value.
> No matter how many time I wait or what I do, 'difference' always is
> (almost) 0. It seems to me that when I do
> request.session.get('sysvortex_last_visit', datetime.now()) the value
> is not actually saved, which seems strange.
>
> I am struggling with this for a few days now, so any help or pointer
> is higly appreciated, thanks!
You're not showing where the sysvortex_last_visit is saved in the
session. A difference that is close to zero tells me that the get is
not finding the session variable and so is returning datetime.now().
Then in the next line you calculate the difference with another call
to datetime.now(), that difference would be very close to, if not, zero.
Referencing your similar post of a few weeks ago shows no code to
store the session variable. Above you mention that when you do a get,
the value is not saved. Getting a value from the session dictionary
does not save it there. You must explicitly assign the value:
request.session['sysvortex_last_visit'] = datetime.now()
Don
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---