#NEWLINE# def export_zipfile( site , queryset ) : #NEWLINE# #INDENT# now = timezone . now ( ) #NEWLINE# zip_name = ( 'export_%s_%04d%02d%02d.zip' % ( slugify ( site . domain ) , now . year , now . month , now . day ) ) #NEWLINE# zip_data = open ( os . path . join ( django_settings . MEDIA_ROOT , zip_name ) , 'w' ) #NEWLINE# zip_file = zipfile . ZipFile ( zip_data , 'w' , allowZip64 = True ) #NEWLINE# used_categories = set ( ) #NEWLINE# for mf in queryset : #NEWLINE# #INDENT# for cat in mf . categories . all ( ) : #NEWLINE# #INDENT# used_categories . update ( cat . path_list ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# info = { #NEWLINE# #INDENT# 'export_magic' : export_magic , #NEWLINE# 'categories' : [ { #NEWLINE# #INDENT# 'id' : cat . id , #NEWLINE# 'title' : cat . title , #NEWLINE# 'slug' : cat . slug , #NEWLINE# 'parent' : ( cat . parent_id or 0 ) , #NEWLINE# 'level' : len ( cat . path_list ( ) ) , #NEWLINE# #UNINDENT# } for cat in used_categories ] , #NEWLINE# #UNINDENT# } #NEWLINE# zip_file . comment = json . dumps ( info ) #NEWLINE# for mf in queryset : #NEWLINE# #INDENT# ctime = time . localtime ( os . stat ( mf . file . path ) . st_ctime ) #NEWLINE# info = json . dumps ( { #NEWLINE# #INDENT# 'copyright' : mf . copyright , #NEWLINE# 'categories' : [ cat . id for cat in mf . categories . all ( ) ] , #NEWLINE# 'translations' : [ { #NEWLINE# #INDENT# 'lang' : t . language_code , #NEWLINE# 'caption' : t . caption , #NEWLINE# 'description' : t . description , #NEWLINE# #UNINDENT# } for t in mf . translations . all ( ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# with open ( mf . file . path , 'r' ) as file_data : #NEWLINE# #INDENT# zip_info = zipfile . ZipInfo ( filename = zip_file . file . name , date_time = ( ctime . tm_year , ctime . tm_mon , ctime . tm_mday , ctime . tm_hour , ctime . tm_min , ctime . tm_sec ) ) #NEWLINE# zip_info . comment = info #NEWLINE# zip_file . writestr ( zip_info , file_data . read ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return zip_name