#NEWLINE# def render( self , name , value , attrs = None ) : #NEWLINE# #INDENT# output = [ ] #NEWLINE# if ( value and getattr ( value , 'url' , None ) ) : #NEWLINE# #INDENT# size = '200x200' #NEWLINE# ( x , y ) = [ int ( x ) for x in size . split ( 'x' ) ] #NEWLINE# try : #NEWLINE# #INDENT# ( filehead , filetail ) = os . path . split ( value . path ) #NEWLINE# ( basename , format ) = os . path . splitext ( filetail ) #NEWLINE# miniature = ( ( ( basename + '_' ) + size ) + format ) #NEWLINE# filename = value . path #NEWLINE# miniature_filename = os . path . join ( filehead , miniature ) #NEWLINE# ( filehead , filetail ) = os . path . split ( value . url ) #NEWLINE# miniature_url = ( ( filehead + '/' ) + miniature ) #NEWLINE# if ( os . path . exists ( miniature_filename ) and ( os . path . getmtime ( filename ) > os . path . getmtime ( miniature_filename ) ) ) : #NEWLINE# #INDENT# os . unlink ( miniature_filename ) #NEWLINE# #UNINDENT# if ( not os . path . exists ( miniature_filename ) ) : #NEWLINE# #INDENT# image = Image . open ( filename ) #NEWLINE# image . thumbnail ( [ x , y ] , Image . ANTIALIAS ) #NEWLINE# try : #NEWLINE# #INDENT# image . save ( miniature_filename , image . format , quality = 100 , optimize = 1 ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# image . save ( miniature_filename , image . format , quality = 100 ) #NEWLINE# #UNINDENT# #UNINDENT# output . append ( ( ' <div><a href="%s" target="_blank"><img src="%s" alt="%s" /></a></div>' % ( miniature_url , miniature_url , miniature_filename ) ) ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# output . append ( super ( AdminFileWidget , self ) . render ( name , value , attrs ) ) #NEWLINE# return mark_safe ( '' . join ( y ) )