Code

Changes between Version 4 and Version 5 of CustomUploadAndFilters


Ignore:
Timestamp:
09/09/06 04:46:41 (8 years ago)
Author:
anonymous
Comment:

if not os.path.exists(call_kwargssave_as?):

Legend:

Unmodified
Added
Removed
Modified
  • CustomUploadAndFilters

    v4 v5  
    241241Remember to adjust your paths to your project. 
    242242 
     243Update: Because it's not a very good idea to recreate a thumbnail everytime a page with thumbs is loaded, i've added a if not os.path.exists to the code. But dont forget to Overload the save() function of your Model to delete the thumbnail if the Object changes. 
     244 
    243245{{{ 
    244246#!python 
     
    305307    new_url = add_to_basename(url, extra) 
    306308    call_kwargs['save_as'] = os.path.join(settings.MEDIA_ROOT, new_url) 
    307      
    308     if crop: 
    309         # Make the cropping 
    310         ok = fit_crop(os.path.join(settings.MEDIA_ROOT, url), **call_kwargs) 
     309 
     310    if not os.path.exists(call_kwargs['save_as']): 
     311      if crop: 
     312          # Make the cropping 
     313          ok = fit_crop(os.path.join(settings.MEDIA_ROOT, url), **call_kwargs) 
     314      else: 
     315          # Create the thumbnail 
     316          ok = fit(os.path.join(settings.MEDIA_ROOT, url), **call_kwargs) 
    311317    else: 
    312         # Create the thumbnail 
    313         ok = fit(os.path.join(settings.MEDIA_ROOT, url), **call_kwargs) 
    314     # 
    315      
     318      ok = True 
     319    # 
     320         
    316321    # Something wrong with the image processing? 
    317322    if not ok: