<s> from django . contrib import messages <EOL> from django . http import Http404 , HttpResponse <EOL> from django . shortcuts import render <EOL> from corehq . apps . app_manager . dbaccessors import get_app <EOL> from corehq . apps . app_manager . decorators import require_deploy_apps , require_can_edit_apps <EOL> from corehq . apps . app_manager . xform import XForm <EOL> from corehq . util . view_utils import set_file_download <EOL> from dimagi . utils . logging import notify_exception <EOL> from dimagi . utils . subprocess_timeout import ProcessTimedOut <EOL> @ require_can_edit_apps <EOL> def multimedia_list_download ( request , domain , app_id ) : <EOL> app = get_app ( domain , app_id ) <EOL> include_audio = request . GET . get ( "<STR_LIT>" , True ) <EOL> include_images = request . GET . get ( "<STR_LIT>" , True ) <EOL> strip_jr = request . GET . get ( "<STR_LIT>" , True ) <EOL> filelist = [ ] <EOL> for m in app . get_modules ( ) : <EOL> for f in m . get_forms ( ) : <EOL> parsed = XForm ( f . source ) <EOL> parsed . validate ( version = app . application_version ) <EOL> if include_images : <EOL> filelist . extend ( parsed . image_references ) <EOL> if include_audio : <EOL> filelist . extend ( parsed . audio_references ) <EOL> if strip_jr : <EOL> filelist = [ s . replace ( "<STR_LIT>" , "<STR_LIT>" ) for s in filelist if s ] <EOL> response = HttpResponse ( ) <EOL> set_file_download ( response , '<STR_LIT>' ) <EOL> response . write ( "<STR_LIT:\n>" . join ( sorted ( set ( filelist ) ) ) ) <EOL> return response <EOL> @ require_deploy_apps <EOL> def multimedia_ajax ( request , domain , app_id , template = '<STR_LIT>' ) : <EOL> app = get_app ( domain , app_id ) <EOL> if app . get_doc_type ( ) == '<STR_LIT>' : <EOL> try : <EOL> multimedia_state = app . check_media_state ( ) <EOL> except ProcessTimedOut : <EOL> notify_exception ( request ) <EOL> messages . warning ( request , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) ) <EOL> multimedia_state = { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> context = { <EOL> '<STR_LIT>' : multimedia_state , <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : app , <EOL> } <EOL> return render ( request , template , context ) <EOL> else : <EOL> raise Http404 ( ) </s>
