Mikhail Korobov avatar Mikhail Korobov committed 7673513

Cleanup spaces.

Comments (0)

Files changed (5)

Add a comment to this file

docs/_build/doctrees/environment.pickle

Binary file modified.

Add a comment to this file

docs/_build/doctrees/index.doctree

Binary file modified.

docs/_build/html/index.html

 class </em><tt class="descclassname">photo_albums.forms.</tt><tt class="descname">UploadZipForm</tt><a class="headerlink" href="#photo_albums.forms.UploadZipForm" title="Permalink to this definition">¶</a></dt>
 <dd><p>A base form class for uploading several files packed as one .zip file.
 Extract files and provides hook for processing extracted files.
-During extraction it loads uncompressed files to memory by chunks so it 
+During extraction it loads uncompressed files to memory by chunks so it
 is safe to process zip archives with big files inside.</p>
 <dl class="method">
 <dt id="photo_albums.forms.UploadZipForm.clean_zip_file">
 <tt class="descname">clean_zip_file</tt><big>(</big><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipForm.clean_zip_file" title="Permalink to this definition">¶</a></dt>
-<dd>Checks if zip file is not corrupted, stores in-memory uploaded file 
+<dd>Checks if zip file is not corrupted, stores in-memory uploaded file
 to disk and returns path to stored file.</dd></dl>
 
 <dl class="method">
 <dt id="photo_albums.forms.UploadZipForm.needs_unpacking">
 <tt class="descname">needs_unpacking</tt><big>(</big><em>name</em>, <em>info</em><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipForm.needs_unpacking" title="Permalink to this definition">¶</a></dt>
-<dd>Returns True is file should be extracted from zip and 
+<dd>Returns True is file should be extracted from zip and
 False otherwise. Override in subclass to customize behaviour.
-Default is to unpack all files except directories and meta files 
+Default is to unpack all files except directories and meta files
 (names starts with &#8216;__&#8217;) .</dd></dl>
 
 <dl class="method">
 <dt id="photo_albums.forms.UploadZipForm.process_file">
 <tt class="descname">process_file</tt><big>(</big><em>path</em>, <em>name</em>, <em>info</em>, <em>file_num</em>, <em>files_count</em><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipForm.process_file" title="Permalink to this definition">¶</a></dt>
-<dd><p>Override this in subclass to do something useful with files extracted 
+<dd><p>Override this in subclass to do something useful with files extracted
 from uploaded zip archive.</p>
 <p>Params:</p>
 <ul class="simple">
 <dl class="method">
 <dt id="photo_albums.forms.UploadZipForm.process_zip_file">
 <tt class="descname">process_zip_file</tt><big>(</big><em>chunksize=65536</em><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipForm.process_zip_file" title="Permalink to this definition">¶</a></dt>
-<dd><p>Extract all files to temporary place and call process_file method 
+<dd><p>Extract all files to temporary place and call process_file method
 for each.</p>
-<p><tt class="docutils literal"><span class="pre">chunksize</span></tt> is the size of block in which compressed files are 
-read. Default is 64k. Do not set it below 64k because data from 
+<p><tt class="docutils literal"><span class="pre">chunksize</span></tt> is the size of block in which compressed files are
+read. Default is 64k. Do not set it below 64k because data from
 compressed files will be read in blocks &gt;= 64k anyway.</p>
 </dd></dl>
 
 <em class="property">
 class </em><tt class="descclassname">photo_albums.forms.</tt><tt class="descname">UploadZipAlbumForm</tt><big>(</big><em>user</em>, <em>obj</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipAlbumForm" title="Permalink to this definition">¶</a></dt>
 <dd><p>Bases: <a title="photo_albums.forms.UploadZipForm" class="reference" href="#photo_albums.forms.UploadZipForm"><tt class="xref docutils literal"><span class="pre">photo_albums.forms.UploadZipForm</span></tt></a></p>
-<p>Form for uploading several images packed as one .zip file. 
+<p>Form for uploading several images packed as one .zip file.
 Only valid images are stored. Uploaded images are marked as uploaded
 by <tt class="docutils literal"><span class="pre">user</span></tt> and are attached to <tt class="docutils literal"><span class="pre">obj</span></tt> model.</p>
 <dl class="method">
 <dl class="method">
 <dt id="photo_albums.forms.UploadZipAlbumForm.needs_unpacking">
 <tt class="descname">needs_unpacking</tt><big>(</big><em>name</em>, <em>info</em><big>)</big><a class="headerlink" href="#photo_albums.forms.UploadZipAlbumForm.needs_unpacking" title="Permalink to this definition">¶</a></dt>
-<dd>Returns True is file should be extracted from zip and 
+<dd>Returns True is file should be extracted from zip and
 False otherwise. Override in subclass to customize behaviour.
-Default is to skip directories, meta files 
+Default is to skip directories, meta files
 (names starts with <tt class="docutils literal"><span class="pre">'__'</span></tt>) and files with non-image extensions.</dd></dl>
 
 <dl class="method">

docs/_build/html/searchindex.js

-Search.setIndex({desctypes:{"0":"attribute","1":"class","2":"method","3":"function"},terms:{pluggabl:0,has_edit_permiss:0,obiwanu:0,skip:0,all:0,month:0,prefix:[],subclass:0,follow:0,alt:0,disk:0,photo_album:0,depend:[],readabl:0,string:0,place_slug:0,fals:0,account:0,util:0,context_processor:0,upload_zip_form_class:0,veri:[],contenttyp:0,ref:[],list:0,upload:0,iter:0,pleas:0,unmark:0,accounts_photo_sit:0,httpresponseredirect:0,second:0,pass:0,index:[],appear:0,ned:0,advanc:0,delet:0,version:0,account_imag:[],method:0,gener:0,here:0,errorlist:[],upload_form_class:0,path:0,becom:0,valu:0,search:[],error_class:[],vasia:0,"0x1a1bb30":[],app_util:[],chang:0,via:0,extra:0,modul:0,href:0,instal:0,should:0,regex:0,from:0,zip:0,memori:0,current_app:0,next:0,call:0,prev:0,type:0,reorder:0,more:0,upload_zip:0,peopl:0,relat:0,enhanc:0,accept:0,sorl:0,kmike:0,unpack:0,must:0,none:0,edit_imag:0,alia:[],setup:0,work:0,uniqu:0,annoi:0,archiv:0,can:0,existingfil:[],purpos:0,def:0,overrid:0,edit_form_class:0,want:0,process:0,view_us:[],templat:0,tag:0,smth:0,login_requir:[],wow:0,alwai:0,multipl:0,process_zip_fil:0,sever:0,instead:0,photoformset:0,clone:0,mai:0,infolist:0,data:0,exclud:0,issu:0,object_regex:0,allow:0,media:0,callabl:0,fallback:0,order:0,city_slug:0,becaus:0,clear_main_imag:0,"0x1a1caf0":[],paramet:0,write:0,thank:0,img:0,better:0,complex:0,media_root:0,main:0,edit_album:0,good:[],"return":0,thei:0,python:0,safe:0,dai:0,auth:0,mention:[],uploadzipform:0,name:0,get_plac:0,edit:0,photoalbumssit:0,revers:0,each:0,attachedimag:0,show_imag:0,chunk:0,process_fil:0,runtest:[],meta:0,my_fixtur:0,year:0,extract:0,special:0,album:0,upload_imag:0,test_auth_view:0,content:[],modelform:0,correct:0,common:0,namelist:0,urlpattern:0,insid:0,empty_permit:[],base:0,org:0,caption:0,place:0,temporari:0,assign:0,urlconf:0,lambda:0,info:0,instance_nam:0,template_nam:[],onc:0,number:0,hook:0,alreadi:0,installed_app:0,size:0,auto_id:[],differ:0,show_album:0,system:0,least:0,tou:0,attach:0,"0x1a1aaf0":[],test_forbidden_view:0,scheme:[],zipfil:0,store:0,modelformset_factori:0,option:0,namespac:0,copi:0,setuptool:0,kind:0,instanc:0,provid:0,project:0,success_url:0,initi:[],"0x1a14af0":[],queryset:0,ani:0,testcas:0,have:0,tabl:0,need:0,dedic:0,django:0,object_id:0,note:0,also:0,indic:[],necesseri:0,album_sit:0,endfor:0,usernam:0,object:0,compress:0,galleri:0,label_suffix:[],regular:0,deploi:0,lookup_field:0,"class":0,"_build":[],don:0,url:0,doc:0,request:0,doe:0,"100x50":0,enctyp:0,"64k":0,show:0,get_template_nam:[],model_nam:0,permiss:0,anywai:0,filefield:[],redirect:0,onli:0,explicitli:0,solut:0,temporary_file_path:[],dict:0,folder:0,extra_context:0,custom:0,variou:0,get:0,delete_imag:0,express:0,set_as_main_imag:0,report:0,requir:0,useralbumtest:0,attachedimageformformset:[],is_valid_imag:0,stuff:0,integr:0,contain:0,where:0,view:0,set:0,methodnam:[],see:0,multipart:0,arg:0,corrupt:0,close:[],modelformset:0,uploadzipalbumform:0,statu:0,correctli:0,pattern:0,someth:0,thumb:[],clean_zip_fil:0,won:0,"import":0,thumbnail:0,attribut:0,extend:[],image_id:0,entir:0,addit:0,behaviour:0,extens:0,admin:0,etc:0,excluded_view:0,context:0,com:[],load:0,inspir:[],upload_formset_class:0,reorder_imag:0,non:0,assum:0,files_count:0,city__slug:0,mark:0,basic:0,object_gett:0,imag:0,bulk:0,input:0,look:0,defin:0,fixtur:0,endblock:[],pack:0,them:0,my_object_slug:0,kwarg:0,"__init__":[],decor:[],develop:0,welcom:0,perform:0,suggest:0,make:0,same:[],html:0,document:0,complet:0,http:0,action:0,rais:0,album_us:0,user:0,extern:0,test_help:0,upload_main_imag:0,exampl:0,thi:0,album_for_kwarg:0,model:0,file_num:0,usual:0,photo:0,test_public_view:0,test_util:0,thees:[],easi:0,except:0,param:0,add:0,is_valid:0,els:0,save:0,app:0,applic:0,photoalbumsit:0,which:0,read:0,big:0,password:0,template_object_nam:0,like:0,success:0,resolv:0,"0x1a1baf0":[],albumtest:0,album_for_id:0,necessari:0,photologu:[],page:[],test_reord:0,creation:0,some:0,syncdb:0,librari:[],total:0,confirm:0,chunksiz:0,"0x1a19b70":[],tracker:0,pluggablesit:[],imageeditform:0,id_:[],previou:0,run:0,uncompress:0,usag:0,step:0,post:0,viewtest:0,slug:0,plug:0,src:0,obj:0,would:0,manag:0,user_imag:0,dialog:0,constructor:0,image_in_other_album_id:0,userprofile__slug:0,other:0,block:0,image2_in_album_id:0,photo_smal:[],set_image_ord:0,easy_instal:0,automat:0,your:0,per:0,submit:0,formset:0,avail:0,start:0,attachedimageform:0,includ:0,suit:0,"function":0,form:0,link:0,"true":0,bug:0,count:0,needs_unpack:0,possibl:0,"default":0,autoclass:[],googlecod:[],displai:0,below:0,site:0,otherwis:0,confirm_delet:0,app_nam:0,featur:0,pil:0,creat:0,"0x1a1bb70":[],dure:0,exist:0,file:0,pip:0,check:0,"_custom_url_schem":[],field:0,valid:0,lookup:0,test:0,you:0,variabl:0,image_in_album_id:0,get_profil:[],svn:0,"0x1a19bb0":[],bitbucket:0,directori:0,rule:0,generic_imag:0,generic_util:0},titles:["django-photo-albums&#8217;s documentation"],modules:{"photo_albums.views":0,"photo_albums.urls":0,"photo_albums.forms":0,"photo_albums.test_utils":0},descrefs:{"photo_albums.test_utils.AlbumTest":{username:[0,0],album_for_id:[0,0],image_in_other_album_id:[0,0],excluded_views:[0,0],test_auth_views:[0,2],image_in_album_id:[0,0],album_site:[0,0],test_public_views:[0,2],test_reorder:[0,2],test_forbidden_views:[0,2],fixtures:[0,0],password:[0,0],album_for_kwargs:[0,0],check:[0,2],image2_in_album_id:[0,0]},"photo_albums.urls":{PhotoAlbumSite:[0,1]},"photo_albums.forms.UploadZipForm":{process_zip_file:[0,2],clean_zip_file:[0,2],process_file:[0,2],needs_unpacking:[0,2]},"photo_albums.forms":{UploadZipAlbumForm:[0,1],UploadZipForm:[0,1]},"photo_albums.views":{upload_images:[0,0],edit_album:[0,0],set_as_main_image:[0,0],upload_zip:[0,0],edit_image:[0,0],upload_main_image:[0,0],delete_image:[0,0],show_album:[0,3],show_image:[0,3],clear_main_image:[0,0]},"photo_albums.test_utils":{AlbumTest:[0,1]},"photo_albums.forms.photo_albums.forms":{PhotoFormSet:[0,1],ImageEditForm:[0,1]},"photo_albums.forms.UploadZipAlbumForm":{is_valid_image:[0,2],process_file:[0,2],needs_unpacking:[0,2]}},filenames:["index"]})
+Search.setIndex({desctypes:{"0":"attribute","1":"class","2":"method","3":"function"},terms:{pluggabl:0,has_edit_permiss:0,obiwanu:0,skip:0,formset:0,all:0,month:0,prefix:[],"0x1a19b70":[],follow:0,alt:0,disk:0,photo_album:0,depend:[],readabl:0,string:0,place_slug:0,fals:0,account:0,util:0,context_processor:0,upload_zip_form_class:0,veri:[],contenttyp:0,ref:[],list:0,upload:0,iter:0,pleas:0,unmark:0,accounts_photo_sit:0,id_:[],second:0,pass:0,index:[],appear:0,ned:0,advanc:0,delet:0,version:0,account_imag:[],method:0,gener:0,here:0,errorlist:[],upload_form_class:0,path:0,becom:0,valu:0,search:[],error_class:[],vasia:0,"0x1a1bb30":[],action:0,chang:0,via:0,extra:0,modul:0,href:0,instal:0,should:0,regex:0,from:0,zip:0,memori:0,current_app:0,next:0,call:0,prev:0,type:0,reorder:0,more:0,src:0,peopl:0,relat:0,enhanc:0,accept:0,sorl:0,obj:0,unpack:0,must:0,none:0,edit_imag:0,alia:[],setup:0,work:0,uniqu:0,annoi:0,archiv:0,can:0,existingfil:[],purpos:0,def:0,overrid:0,edit_form_class:0,want:0,process:0,view_us:[],templat:0,tag:0,smth:0,login_requir:[],wow:0,alwai:0,multipl:0,write:0,"__init__":[],instead:0,photoformset:0,clone:0,mai:0,infolist:0,data:0,django:0,issu:0,object_regex:0,allow:0,media:0,callabl:0,fallback:0,order:0,city_slug:0,becaus:0,clear_main_imag:0,"0x1a1caf0":[],paramet:0,process_zip_fil:0,thank:0,img:0,better:0,complex:0,media_root:0,main:0,edit_album:0,good:[],"return":0,thei:0,python:0,safe:0,dai:0,auth:0,mention:[],uploadzipform:0,name:0,get_plac:0,edit:0,photoalbumssit:0,revers:0,each:0,attachedimag:0,show_imag:0,chunk:0,process_fil:0,runtest:[],meta:0,my_fixtur:0,year:0,extract:0,special:0,album:0,upload_imag:0,test_auth_view:0,content:[],modelform:0,correct:0,integr:0,namelist:0,urlpattern:0,insid:0,empty_permit:[],base:0,org:0,caption:0,place:0,temporari:0,assign:0,urlconf:0,lambda:0,instance_nam:0,template_nam:[],onc:0,number:0,hook:0,alreadi:0,installed_app:0,size:0,auto_id:[],differ:0,start:0,system:0,least:0,tou:0,attach:0,"0x1a1aaf0":[],test_forbidden_view:0,scheme:[],zipfil:0,store:0,modelformset_factori:0,option:0,namespac:0,copi:0,setuptool:0,kind:0,instanc:0,provid:0,project:0,success_url:0,initi:[],"0x1a14af0":[],queryset:0,ani:0,corrupt:0,have:0,tabl:0,need:0,dedic:0,exclud:0,object_id:0,note:0,also:0,indic:[],necesseri:0,album_sit:0,thi:0,usernam:0,object:0,compress:0,galleri:0,label_suffix:[],regular:0,deploi:0,lookup_field:0,"class":0,"_build":[],don:0,url:0,doc:0,request:0,doe:0,"100x50":0,enctyp:0,"64k":0,show:0,get_template_nam:[],model_nam:0,permiss:0,anywai:0,filefield:[],redirect:0,onli:0,explicitli:0,solut:0,temporary_file_path:[],dict:0,folder:0,extra_context:0,count:0,variou:0,get:0,delete_imag:0,express:0,set_as_main_imag:0,report:0,requir:0,useralbumtest:0,attachedimageformformset:[],is_valid_imag:0,stuff:0,common:0,contain:0,where:0,valid:0,view:0,set:0,methodnam:[],see:0,multipart:0,arg:0,testcas:0,close:[],modelformset:0,uploadzipalbumform:0,statu:0,correctli:0,pattern:0,someth:0,thumb:[],clean_zip_fil:0,won:0,"import":0,thumbnail:0,attribut:0,extend:[],image_id:0,entir:0,addit:0,behaviour:0,extens:0,admin:0,etc:0,excluded_view:0,context:0,com:[],load:0,inspir:[],upload_formset_class:0,reorder_imag:0,non:0,assum:0,files_count:0,city__slug:0,mark:0,basic:0,object_gett:0,imag:0,bulk:0,els:0,look:0,defin:0,fixtur:0,endblock:[],pack:0,them:0,kwarg:0,sever:0,decor:[],develop:0,welcom:0,perform:0,suggest:0,make:0,same:[],html:0,document:0,complet:0,http:0,app_util:[],rais:0,album_us:0,user:0,extern:0,test_help:0,upload_main_imag:0,exampl:0,endfor:0,album_for_kwarg:0,model:0,file_num:0,usual:0,photo:0,test_public_view:0,test_util:0,thees:[],easi:0,except:0,param:0,add:0,is_valid:0,input:0,save:0,app:0,applic:0,photoalbumsit:0,which:0,read:0,big:0,password:0,template_object_nam:0,like:0,success:0,resolv:0,"0x1a1baf0":[],albumtest:0,album_for_id:0,necessari:0,photologu:[],page:[],test_reord:0,creation:0,some:0,syncdb:0,librari:[],total:0,confirm:0,chunksiz:0,subclass:0,tracker:0,pluggablesit:[],imageeditform:0,httpresponseredirect:0,previou:0,run:0,uncompress:0,usag:0,step:0,post:0,viewtest:0,slug:0,plug:0,upload_zip:0,kmike:0,would:0,manag:0,user_imag:0,dialog:0,constructor:0,image_in_other_album_id:0,userprofile__slug:0,block:0,image2_in_album_id:0,photo_smal:[],set_image_ord:0,easy_instal:0,automat:0,your:0,per:0,submit:0,custom:0,avail:0,show_album:0,attachedimageform:0,includ:0,suit:0,"function":0,form:0,"0x1a19bb0":[],link:0,"true":0,bug:0,info:0,needs_unpack:0,possibl:0,"default":0,autoclass:[],googlecod:[],displai:0,below:0,site:0,otherwis:0,confirm_delet:0,app_nam:0,featur:0,pil:0,creat:0,"0x1a1bb70":[],dure:0,exist:0,file:0,pip:0,check:0,"_custom_url_schem":[],field:0,other:0,lookup:0,test:0,you:0,variabl:0,image_in_album_id:0,get_profil:[],svn:0,my_object_slug:0,bitbucket:0,directori:0,rule:0,generic_imag:0,generic_util:0},titles:["django-photo-albums&#8217;s documentation"],modules:{"photo_albums.views":0,"photo_albums.urls":0,"photo_albums.forms":0,"photo_albums.test_utils":0},descrefs:{"photo_albums.test_utils.AlbumTest":{username:[0,0],album_for_id:[0,0],image_in_other_album_id:[0,0],excluded_views:[0,0],test_auth_views:[0,2],image_in_album_id:[0,0],album_site:[0,0],test_public_views:[0,2],test_reorder:[0,2],test_forbidden_views:[0,2],fixtures:[0,0],password:[0,0],album_for_kwargs:[0,0],check:[0,2],image2_in_album_id:[0,0]},"photo_albums.urls":{PhotoAlbumSite:[0,1]},"photo_albums.forms.UploadZipForm":{process_zip_file:[0,2],clean_zip_file:[0,2],process_file:[0,2],needs_unpacking:[0,2]},"photo_albums.forms":{UploadZipAlbumForm:[0,1],UploadZipForm:[0,1]},"photo_albums.views":{upload_images:[0,0],edit_album:[0,0],set_as_main_image:[0,0],upload_zip:[0,0],edit_image:[0,0],upload_main_image:[0,0],delete_image:[0,0],show_album:[0,3],show_image:[0,3],clear_main_image:[0,0]},"photo_albums.test_utils":{AlbumTest:[0,1]},"photo_albums.forms.photo_albums.forms":{PhotoFormSet:[0,1],ImageEditForm:[0,1]},"photo_albums.forms.UploadZipAlbumForm":{is_valid_image:[0,2],process_file:[0,2],needs_unpacking:[0,2]}},filenames:["index"]})

photo_albums/forms.py

 # Incremental approach for unzipping files in only supported in python >= 2.6.
 # Use backported zipfile.py library for python < 2.6
 
-try: 
+try:
     from zipfile import ZipFile, BadZipfile
     from zipfile import ZipExtFile # <- this will fail on python < 2.6
-except ImportError: 
+except ImportError:
     from photo_albums.lib.zipfile import ZipFile, BadZipfile
 
 
     class Meta:
         model = AttachedImage
         fields = ['caption']
- 
+
 PhotoFormSet = modelformset_factory(AttachedImage, extra=3, fields = ['image', 'caption'])
 
 class _ExistingFile(UploadedFile):
     ''' Utility class for importing existing files to FileField's. '''
-    
+
     def __init__(self, path, *args, **kwargs):
         self.path = path
         super(_ExistingFile, self).__init__(*args, **kwargs)
-        
+
     def temporary_file_path(self):
         return self.path
-    
+
     def close(self):
         pass
 
     '''  Converts InMemoryUploadedFile to on-disk file so it will have path. '''
     try:
         return uploaded_file.temporary_file_path()
-    except AttributeError:            
+    except AttributeError:
         fileno, path = tempfile.mkstemp()
-        temp_file = os.fdopen(fileno,'w+b')        
+        temp_file = os.fdopen(fileno,'w+b')
         for chunk in uploaded_file.chunks():
             temp_file.write(chunk)
         temp_file.close()
         return path
-        
-    
+
+
 class UploadZipForm(forms.Form):
     '''
         A base form class for uploading several files packed as one .zip file.
         Extract files and provides hook for processing extracted files.
-        During extraction it loads uncompressed files to memory by chunks so it 
+        During extraction it loads uncompressed files to memory by chunks so it
         is safe to process zip archives with big files inside.
     '''
-        
+
     zip_file = forms.FileField()
-    
+
     def clean_zip_file(self):
-        ''' Checks if zip file is not corrupted, stores in-memory uploaded file 
-            to disk and returns path to stored file. 
+        ''' Checks if zip file is not corrupted, stores in-memory uploaded file
+            to disk and returns path to stored file.
         '''
         path = _file_path(self.cleaned_data['zip_file'])
         try:
             zf = ZipFile(path)
             bad_file = zf.testzip()
             if bad_file:
-                raise forms.ValidationError(_('"%s" in the .zip archive is corrupt.') % bad_file)                
+                raise forms.ValidationError(_('"%s" in the .zip archive is corrupt.') % bad_file)
             zf.close()
         except BadZipfile:
             raise forms.ValidationError(_('Uploaded file is not a zip file.'))
-                    
+
         return path
-    
 
-    def needs_unpacking(self, name, info):  
-        ''' Returns True is file should be extracted from zip and 
+
+    def needs_unpacking(self, name, info):
+        ''' Returns True is file should be extracted from zip and
             False otherwise. Override in subclass to customize behaviour.
-            Default is to unpack all files except directories and meta files 
+            Default is to unpack all files except directories and meta files
             (names starts with '__') .
         '''
-        #skip directory entries      
+        #skip directory entries
         isdir = info.external_attr & DIR_BIT
         if isdir:
             return False
-                
+
         # skip meta files
-        if name.startswith('__'): 
+        if name.startswith('__'):
             return False
-        
+
         return True
-    
-        
+
+
     def process_file(self, path, name, info, file_num, files_count):
         '''
-        Override this in subclass to do something useful with files extracted 
+        Override this in subclass to do something useful with files extracted
         from uploaded zip archive.
-        
-        Params:        
-        
+
+        Params:
+
         * ``path``: path to temporary file. It's on developer to delete this file.
         * ``name``: name of file in zip archive, returned by ZipFile.namelist()
         * ``info``: file info, returned by ZipFile.infolist()
         * ``files_count``: total files count
         '''
         raise NotImplementedError
-        
+
     def process_zip_file(self, chunksize=1024*64):
         '''
-            Extract all files to temporary place and call process_file method 
+            Extract all files to temporary place and call process_file method
             for each.
-                        
-            ``chunksize`` is the size of block in which compressed files are 
-            read. Default is 64k. Do not set it below 64k because data from 
+
+            ``chunksize`` is the size of block in which compressed files are
+            read. Default is 64k. Do not set it below 64k because data from
             compressed files will be read in blocks >= 64k anyway.
         '''
-        
+
         zip_filename = self.cleaned_data['zip_file'] #should contain zip file path
-        
+
         zf = ZipFile(zip_filename)
 
         names = zf.namelist()
         infos = zf.infolist()
-            
+
         files_to_unpack = []
-        
+
         for name, info in zip(names, infos):
             if self.needs_unpacking(name, info):
                 files_to_unpack.append((name, info))
-        
+
         for counter, (name, info,) in enumerate(files_to_unpack):
-                        
-            # extract file to temporary place            
+
+            # extract file to temporary place
             fileno, path = tempfile.mkstemp()
             outfile = os.fdopen(fileno,'w+b')
-            
+
             stream = zf.open(info)
             while True:
                 hunk = stream.read(chunksize)
                 if not hunk:
                     break
                 outfile.write(hunk)
-                
+
             outfile.close()
-            
+
             # do something with extracted file
             self.process_file(path, name, info, counter, len(files_to_unpack))
-            
+
         zf.close()
         os.unlink(zip_filename)
-        
-                
+
+
 class UploadZipAlbumForm(UploadZipForm):
-    ''' Form for uploading several images packed as one .zip file. 
+    ''' Form for uploading several images packed as one .zip file.
         Only valid images are stored. Uploaded images are marked as uploaded
         by ``user`` and are attached to ``obj`` model.
     '''
     def __init__(self, user, obj, *args, **kwargs):
         super(UploadZipAlbumForm, self).__init__(*args, **kwargs)
-        
+
         self.user = user
         self.obj = obj
-        self.order = AttachedImage.objects.for_model(obj).aggregate(max_order=Max('order'))['max_order']        
-        
+        self.order = AttachedImage.objects.for_model(obj).aggregate(max_order=Max('order'))['max_order']
+
         self.fields['zip_file'].label = _('images file (.zip)')
         self.fields['zip_file'].help_text = _('Select a .zip file of images to upload.')
-        
-                
-                
+
+
+
     def needs_unpacking(self, name, info):
-        ''' Returns True is file should be extracted from zip and 
+        ''' Returns True is file should be extracted from zip and
             False otherwise. Override in subclass to customize behaviour.
-            Default is to skip directories, meta files 
+            Default is to skip directories, meta files
             (names starts with ``'__'``) and files with non-image extensions.
         '''
-        for ext in ['.jpg', '.jpeg', '.png', '.gif']:            
+        for ext in ['.jpg', '.jpeg', '.png', '.gif']:
             if name.lower().endswith(ext):
                 return super(UploadZipAlbumForm, self).needs_unpacking(name, info)
         return False
-    
+
 
     def is_valid_image(self, path):
         ''' Check if file is readable by PIL. '''
-        from PIL import Image        
-                
+        from PIL import Image
+
         try:
             trial_image = Image.open(path)
             trial_image.verify()
             raise
         except Exception: # Python Imaging Library doesn't recognize it as an image
             return False
-        
+
         return True
-        
-                
+
+
     def process_file(self, path, name, info, file_num, files_count):
         ''' Create AttachedImage instance if file is a valid image. '''
-        
+
         # flatten directories
         fname = os.path.split(name)[1]
-        
+
         # only process valid images
         if self.is_valid_image(path):
             self.order += 1
             image = AttachedImage(user = self.user, caption = '',
                                   order = self.order, content_object = self.obj)
-            
+
             # do not generate tons of SQL queries
             image.send_signal = False
             image.get_file_name = lambda filename: str(self.order)
-            
-            # Move file to proper place (without copying if it is possible) and 
+
+            # Move file to proper place (without copying if it is possible) and
             # create record in database
             image.image.save(image.get_upload_path(fname), _ExistingFile(path))
-        else:             
+        else:
             # image is invalid, we should delete temp file
-            os.unlink(path)               
-            
-        # Because ImageCountField fields where disabled we have to 
-        # recalculate denormalised values 
+            os.unlink(path)
+
+        # Because ImageCountField fields where disabled we have to
+        # recalculate denormalised values
         is_last = (file_num == (files_count-1))
-        if is_last: 
+        if is_last:
             force_recalculate(self.obj)
-             
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.