#NEWLINE# def save( self , delete_zip_import = True , * args , **kwargs ) : #NEWLINE# #INDENT# '\n        If a zip file is uploaded, extract any images from it and add\n        them to the gallery, before removing the zip file.\n        ' #NEWLINE# super ( BaseGallery , self ) . save ( * args , ** kwargs ) #NEWLINE# if self . zip_import : #NEWLINE# #INDENT# zip_file = ZipFile ( self . zip_import ) #NEWLINE# for name in zip_file . namelist ( ) : #NEWLINE# #INDENT# data = zip_file . read ( name ) #NEWLINE# try : #NEWLINE# #INDENT# from PIL import Image #NEWLINE# image = Image . open ( BytesIO ( data ) ) #NEWLINE# image . load ( ) #NEWLINE# image = Image . open ( BytesIO ( data ) ) #NEWLINE# image . verify ( ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# name = os . path . split ( name ) [ 1 ] #NEWLINE# if isinstance ( name , bytes ) : #NEWLINE# #INDENT# encoding = charsetdetect ( kwargs ) [ 'encoding' ] #NEWLINE# tempname = name . decode ( encoding ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tempname = name #NEWLINE# #UNINDENT# slug = ( self . slug if ( self . slug != '/' ) else '' ) #NEWLINE# path = os . path . join ( GALLERIES_UPLOAD_DIR , slug , tempname ) #NEWLINE# try : #NEWLINE# #INDENT# saved_path = default_storage . save ( path , ContentFile ( data ) ) #NEWLINE# #UNINDENT# except UnicodeEncodeError : #NEWLINE# #INDENT# from warnings import warn #NEWLINE# warn ( "A file was saved that contains unicode characters in its path, but somehow the current locale does not support utf-8. You may need to set 'LC_ALL' to a correct value, eg: 'en_US.UTF-8'." ) #NEWLINE# path = os . path . join ( GALLERIES_UPLOAD_DIR , slug , native ( str ( name , errors = 'ignore' ) ) ) #NEWLINE# saved_path = default_storage . save ( path , ContentFile ( data ) ) #NEWLINE# #UNINDENT# self . images . create ( file = saved_path ) #NEWLINE# #UNINDENT# if delete_zip_import : #NEWLINE# #INDENT# zip_file . close ( ) #NEWLINE# self . zip_import . delete ( save = True )