Re: FilePathField and stale choices

2011-07-07 Thread Daniel Swarbrick
On Jul 7, 1:04 am, Luke Plant  wrote:
> That sounds like a reasonable idea to me, since doing it by default
> could impose a serious performance hit. In it's most naive form (i.e.
> making the 'choices' attribute a lazy list using
> django.utils.functional.lazy) this wouldn't be too hard to implement.
>
> Feel free to open a ticket for this.
>

Done - https://code.djangoproject.com/ticket/16429

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



Re: FilePathField and stale choices

2011-07-06 Thread Luke Plant
On 06/07/11 21:41, Daniel Swarbrick wrote:

> Or can we perhaps even add an option to FilePathField that would
> refresh the choices each time? I'm not entirely sure how that would
> work... proxy function maybe?

That sounds like a reasonable idea to me, since doing it by default
could impose a serious performance hit. In it's most naive form (i.e.
making the 'choices' attribute a lazy list using
django.utils.functional.lazy) this wouldn't be too hard to implement.

However, that would mean that *every* time it was accessed it would have
to walk the file system to get the choices, which could easily get
crazy. A better solution would add some level of caching. This sounds
like we need an option that specifies the number of seconds to cache
for. It would be OK to require that there is a cache backend active for
this to work. We could have a single setting that controls the two e.g.
cache_paths_for - if it was None (the default) then it would cache forever.

Feel free to open a ticket for this.

Luke

-- 
 A mosquito cried out in pain:
 "A chemist has poisoned my brain!"
 The cause of his sorrow
 was para-dichloro-
 diphenyltrichloroethane

Luke Plant || http://lukeplant.me.uk/

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



FilePathField and stale choices

2011-07-06 Thread Daniel Swarbrick
This problem was raised at least twice [1] [2] back in 2009 on django-
users, and neither post was answered.

If FilePathField is used declaratively for a form's field(s), it does
not get called for each instantiation of that form - only the first
time the form is used. Consequently, the choices may show files that
have since been deleted, and fail to show files that have since been
added to the directory. One of the users who raised this issue wrote
that he has to reload his server... to get updated files to show.

Should the docs perhaps reflect this, and maybe advise people to
dynamically add FilePathFields to their form.__init__() if they want
them to always be minty fresh?

Or can we perhaps even add an option to FilePathField that would
refresh the choices each time? I'm not entirely sure how that would
work... proxy function maybe?

[1]: 
http://groups.google.com/group/django-users/browse_thread/thread/6778fa138b848996
[2]: 
http://groups.google.com/group/django-users/browse_thread/thread/403d872cf9433905

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