Cherrypy and view variables caching?

2009-03-05 Thread John M

I'm  having a strange problem with running django on a Cherrypy
server.

in my views.py, I setup a variable called oneweekago, and set it to
today() - (days=7) (it's obviously a date type variable), then in my
query, I ask for all records that are __LTE=oneweekago.

This code works perfect the day I start my server, but the next day,
if there are records that meet the criteria, it doesn't.  Like the
variable oneweekago is not getting recalculated.  If I restart the
server, it works great.

Here's the actual code in question:

oneweekago = datetime.date.today() - datetime.timedelta(days=7)

disablehost_dict = {

'queryset' : unixhost.objects.all().filter( hostsetting__sshkeys =
True,


hostsetting__userlist = True,


hostsetting__installed = True,


hostsetting__delayed=False,


hostsetting__installdate__lte=oneweekago,


unixuser__enabled = True,


unixuser__user__disable = True


).distinct(),

}

I don't know if the local server has the same issue, since I don't run
that for more than a day.

I'm using runcpserver management plugin to run it under cherrypy.
http://lincolnloop.com/blog/2008/mar/25/serving-django-cherrypy/, and
it's great (except for this :)

Any help is appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cherrypy and view variables caching?

2009-03-05 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 14:54 -0800, John M wrote:
> I'm  having a strange problem with running django on a Cherrypy
> server.
> 
> in my views.py, I setup a variable called oneweekago, and set it to
> today() - (days=7) (it's obviously a date type variable), then in my
> query, I ask for all records that are __LTE=oneweekago.
> 
> This code works perfect the day I start my server, but the next day,
> if there are records that meet the criteria, it doesn't.  Like the
> variable oneweekago is not getting recalculated.  If I restart the
> server, it works great.
> 
> Here's the actual code in question:
> 
> oneweekago = datetime.date.today() - datetime.timedelta(days=7)

If all this indentation is correct (and the email has screwed things up
pretty badly here, so you might want to use dpaste next time -- and
switch to spaces instead of tabs for your Python code, which is pretty
normal), then this line is going to be a problem. It's evaluated once,
when the file is imported. If the file isn't imported again (which would
happen if the server didn't restart), the value won't change just
because the date did.

You'd be better off doing that computation each time you need it (once
per function). It's hardly a huge timesink to do the computation.

Regards,
Malcolm
=


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cherrypy and view variables caching?

2009-03-05 Thread John M

Malcolm, thanks for the reply and I figured that was my issue.

Which leads me to another question, does everyone put all view code
into views.py even though a simple generic view is all that's used?

THanks again

John

On Mar 5, 4:05 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-03-05 at 14:54 -0800, John M wrote:
> > I'm  having a strange problem with running django on a Cherrypy
> > server.
>
> > in my views.py, I setup a variable called oneweekago, and set it to
> > today() - (days=7) (it's obviously a date type variable), then in my
> > query, I ask for all records that are __LTE=oneweekago.
>
> > This code works perfect the day I start my server, but the next day,
> > if there are records that meet the criteria, it doesn't.  Like the
> > variable oneweekago is not getting recalculated.  If I restart the
> > server, it works great.
>
> > Here's the actual code in question:
>
> > oneweekago = datetime.date.today() - datetime.timedelta(days=7)
>
> If all this indentation is correct (and the email has screwed things up
> pretty badly here, so you might want to use dpaste next time -- and
> switch to spaces instead of tabs for your Python code, which is pretty
> normal), then this line is going to be a problem. It's evaluated once,
> when the file is imported. If the file isn't imported again (which would
> happen if the server didn't restart), the value won't change just
> because the date did.
>
> You'd be better off doing that computation each time you need it (once
> per function). It's hardly a huge timesink to do the computation.
>
> Regards,
> Malcolm
> =
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cherrypy and view variables caching?

2009-03-05 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 18:32 -0800, John M wrote:
> Malcolm, thanks for the reply and I figured that was my issue.
> 
> Which leads me to another question, does everyone put all view code
> into views.py even though a simple generic view is all that's used?

That question doesn't really make sense. If you're only using a simple
generic view, then what does "all view code" mean, since there isn't
anything else?

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cherrypy and view variables caching?

2009-03-05 Thread John M

Well, given my example, i would think it does.  I put the generic's in
the URL.PY file and it's not performing as planned, I'm not sure how I
would keep the generic view inside the URL and get what I want?

Either way, doesn't matter, I'm going to put all 'view' code into
views.py eitherway.

J

On Mar 5, 6:33 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-03-05 at 18:32 -0800, John M wrote:
> > Malcolm, thanks for the reply and I figured that was my issue.
>
> > Which leads me to another question, does everyone put all view code
> > into views.py even though a simple generic view is all that's used?
>
> That question doesn't really make sense. If you're only using a simple
> generic view, then what does "all view code" mean, since there isn't
> anything else?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cherrypy and view variables caching?

2009-03-06 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 22:42 -0800, John M wrote:
> Well, given my example, i would think it does.

I'm sorry you think that, but if it was clear to me, I wouldn't have
asked the question. At no point in your earlier posts did you show any
examples of or mention using generic views.

>   I put the generic's in
> the URL.PY file and it's not performing as planned, I'm not sure how I
> would keep the generic view inside the URL and get what I want?

A generic view in a URL Conf file is just a function reference that is
called. It sounds like the problem is some initial data that you're
wanting to set up. You need that to be executed each time if it's ever
going to change (such as the concept of "one week ago"), so it also has
to be inside a function that is called, which means not just using
generic views.

A reasonably natural way to do that if you're using a generic view and
want to pass in extra information is to write a view function which does
all the initial setup and then passes the dynamic information via the
extra_context parameter to the generic view.

Here's an old blog post I wrote on this topic which has some concrete
code samples and is still valid today:

http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---