#NEWLINE# @ staff_member_required #NEWLINE# def sponsor_zip_logo_files( request ) : #NEWLINE# #INDENT# 'Return a zip file of sponsor web and print logos' #NEWLINE# zip_stringio = StringIO ( ) #NEWLINE# zipfile = ZipFile ( zip_stringio , 'w' ) #NEWLINE# try : #NEWLINE# #INDENT# benefits = Benefit . objects . all ( ) #NEWLINE# for benefit in benefits : #NEWLINE# #INDENT# dir_name = benefit . name . lower ( ) . replace ( ' ' , '_' ) . replace ( '/' , '_' ) #NEWLINE# for level in SponsorLevel . objects . all ( ) : #NEWLINE# #INDENT# level_name = level . name . lower ( ) . replace ( ' ' , '_' ) . replace ( '/' , '_' ) #NEWLINE# for sponsor in Sponsor . objects . filter ( level = level , active = True ) : #NEWLINE# #INDENT# sponsor_name = sponsor . name . lower ( ) . replace ( ' ' , '_' ) . replace ( '/' , '_' ) #NEWLINE# full_dir = '/' . join ( [ dir_name , level_name , sponsor_name ] ) #NEWLINE# for sponsor_benefit in SponsorBenefit . objects . filter ( benefit = benefit , sponsor = sponsor , active = True ) . exclude ( upload = '' ) : #NEWLINE# #INDENT# if os . path . exists ( sponsor_benefit . upload . path ) : #NEWLINE# #INDENT# modtime = time . gmtime ( os . stat ( sponsor_benefit . upload . path ) . st_mtime ) #NEWLINE# with open ( sponsor_benefit . upload . path , 'rb' ) as f : #NEWLINE# #INDENT# fname = os . path . split ( sponsor_benefit . upload . name ) [ ( - 1 ) ] #NEWLINE# zipinfo = ZipInfo ( filename = ( ( full_dir + '/' ) + fname ) , date_time = modtime ) #NEWLINE# zipfile . writestr ( zipinfo , f . read ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . debug ( ( 'No such sponsor file: %s' % sponsor_benefit . upload . path ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# zipfile . close ( ) #NEWLINE# #UNINDENT# response = HttpResponse ( zip_stringio . getvalue ( ) , content_type = 'application/zip' ) #NEWLINE# prefix = settings . CONFERENCE_URL_PREFIXES [ settings . CONFERENCE_ID ] #NEWLINE# response [ 'Content-Disposition' ] = ( 'attachment; filename="%s_sponsorlogos.zip"' % prefix ) #NEWLINE# return response