#5361: Support pluggable backends for FileField
------------------------------------------------------------+---------------
          Reporter:  Marty Alchin <[EMAIL PROTECTED]>  |         Owner:  
Gulopine
            Status:  new                                    |     Milestone:  
1.0 beta
         Component:  Database wrapper                       |       Version:  
SVN     
        Resolution:                                         |      Keywords:    
      
             Stage:  Accepted                               |     Has_patch:  1 
      
        Needs_docs:  0                                      |   Needs_tests:  0 
      
Needs_better_patch:  0                                      |  
------------------------------------------------------------+---------------
Comment (by [EMAIL PROTECTED]):

 I'd like to propose adding a few methods that we use a lot at KI.  We have
 a similar setup (generic filesystem that can be local or remote) and I've
 found that they are very helpful.  I can add a patch once Gulopine updates
 his patches for the newest svn if people are interested.  Here are some of
 the functions we use for this kind of thing (in production) that we've
 found helpful:

 {{{
 def modtime(self, key):
                 return os.path.getmtime(os.path.join(self.root, key))

 def delete_by_prefix(self, prefix):
         for root, dirs, files in os.walk(self.root, topdown=False):
             for name in files:
                         if name.startswith(prefix):
                                 os.unlink(os.path.join(root, name))

 def list_dir(self, prefix=None):
         files = os.listdir(self.root)
         if prefix is not None:
                 return [x for x in files if x.startswith(prefix)]
         return files

 def copy(self, old_key, new_key):
                 import shutil
                 shutil.copy(
                         os.path.join(self.root, old_key),
                         os.path.join(self.root, new_key)
                 )
 }}}

 I'll comment the s3 implementations in that ticket.  delete_by_prefix is
 especially useful since we generate out thumbnails of images (our naming
 is model_id_field.ext so thumbnails might be model_id_field_399x233.ext).
 We generally use the local FS for testing and deployments use the S3
 backend.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5361#comment:66>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to