def download_for_offline(request, enc, flowgram): compound_file = CompoundFile() # Adding the Flowgram metadata. flowgram_json = str(simplejson.dumps(encode.flowgram_encoder.to_dict(flowgram, True, None), ensure_ascii=True).encode('utf-8')) compound_file.add('flowgram_meta.json', flowgram_json) # Adding background audio if any. if flowgram.background_audio: (audio_content, content_type) = helpers.download_url( 'http://%s/%s.flv' % (localsettings.S3_BUCKETS[localsettings.S3_BUCKET_AUDIO], flowgram.background_audio.id), use_unicode=False) compound_file.add('audio_%s.flv' % flowgram.background_audio.id, audio_content) # Adding the avatar. try: (avatar_image, content_type) = helpers.download_url( 'http://%s/api/getfgavatar-32/%s/' % (localsettings.MASTER_DOMAIN_NAME, flowgram.id), use_unicode=False) compound_file.add('avatar', avatar_image) except helpers.DownloadException: pass images = {} # Adding data for each page. pages = models.Page.objects.filter(flowgram=flowgram) for page in pages: # Adding the page's HTML. page_html = str(controller.page_contents(page).encode('utf-8')) page_html = process_html_for_image_downloading(page_html, images) page_html = process_css_for_image_downloading(page_html, images) compound_file.add('page_%s.html' % page.id, page_html) # Adding the page's thumbnail image. try: (thumbnail_data, content_type) = helpers.download_url( 'http://%s/%s_150_100.jpg' % (localsettings.S3_BUCKETS[localsettings.S3_BUCKET_THUMB], page.id), use_unicode=False) compound_file.add('thumb_%s.jpg' % page.id, thumbnail_data) except helpers.DownloadException: pass # Adding the page's audio file(s). audio = models.Audio.objects.filter(page=page) for audio_item in audio: (audio_content, content_type) = helpers.download_url( 'http://%s/%s.flv' % (localsettings.S3_BUCKETS[localsettings.S3_BUCKET_AUDIO], audio_item.id), use_unicode=False) compound_file.add('audio_%s.flv' % audio_item.id, audio_content) # Adding the page's CSS file(s). css = models.GetCssRequest.objects.filter(page=page) for css_item in css: (css_content, content_type) = helpers.download_url( 'http://%s/css/%s/' % (localsettings.MASTER_DOMAIN_NAME, css_item.id), use_unicode=False) css_content = process_css_for_image_downloading(css_content, images) compound_file.add('css_%s.css' % css_item.id, css_content) for filename in images.keys(): compound_file.add(filename, images[filename]) response = HttpResponse(compound_file.to_string(), 'application/octet-stream') response['Content-Disposition'] = 'attachment; filename="%s.flowgram"' % \ (flowgram.title or 'untitled') #response = HttpResponse(compound_file.to_string(), 'text/plain') return response
def get_highlighted_page(request, page): try: html = controller.page_hl_contents(page) except IOError: html = controller.page_contents(page) return HttpResponse(html)
def get_page(request, page): # If the page was deleted. if not page.flowgram_id: raise Http404 return HttpResponse(controller.page_contents(page))