def get_file_arch(request, id): sfile = get_object_or_404(POFileSubmit, pk=id) logger.debug("Get archived file %s" % id) from files.external import get_external_url url = get_external_url(sfile) if url: logger.debug('Redirect to ' + url) response = redirect(url) else: content = sfile.handler.get_content() response = HttpResponse(content, content_type='application/x-gettext; charset=UTF-8') attach = "attachment;" response['Content-Disposition'] = '%s filename=%s' % (attach, sfile.filename) return response
def get_pot_file(request, slug): pofile = get_object_or_404(POFile, slug=slug) try: potfile = pofile.potfile.get() except: potfile = None if not potfile: logger.error("POTFile not found") raise Http404 from files.external import get_external_url url = get_external_url(potfile) if url: logger.debug('Redirect to ' + url) response = redirect(url) else: try: content = potfile.handler.get_content() except Exception, e: logger.error(e) raise Http404 response = HttpResponse(content, content_type='application/x-gettext; charset=UTF-8') attach = "attachment;" response['Content-Disposition'] = '%s filename=%s' % (attach, potfile.name)
data = {'body': pygments.highlight(text, lexer, formatter), 'style': formatter.get_style_defs(), 'pofile': file, 'submit': submit, 'user': request.user, 'request': request, 'title': "%s: %s" % (file.component.name, file.filename)} response = render_to_response('files/file_view.html', data, context_instance = RequestContext(request)) cache.set(ckey, response) return response else: from files.external import get_external_url url = get_external_url(fileElement) if url: logger.debug('Redirect to ' + url) response = redirect(url) else: if submit: content = handler.get_content() else: content = handler.get_content(not view) response = HttpResponse(content, content_type='application/x-gettext; charset=UTF-8') attach = "attachment;" response['Content-Disposition'] = '%s filename=%s' % (attach, file.filename) return response @login_required @check_status