def combo_view(request, location, default_redirect=None, encoding='utf8'): """Handle a request for combining a set of files. The files are searched in the absolute location `abs_location` (if defined) or in the relative location `rel_location`. """ fnames = parse_qs(request.META.get("QUERY_STRING", "")) if fnames: if fnames[0].endswith('.js'): content_type = 'text/javascript; charset=UTF-8' elif fnames[0].endswith('.css'): content_type = 'text/css' elif default_redirect is not None and len(fnames) == 1: return HttpResponseRedirect( "%s%s" % (default_redirect, fnames[0])) else: return HttpResponseBadRequest( "Invalid file type requested.", content_type="text/plain; charset=UTF-8") content = "".join( [content.decode(encoding) for content in combine_files( fnames, location, resource_prefix='/', rewrite_urls=True)]) return HttpResponse( content_type=content_type, status=200, content=content) return HttpResponseNotFound()
def combo_view(request, location, default_redirect=None, encoding='utf8'): """Handle a request for combining a set of files. The files are searched in the absolute location `abs_location` (if defined) or in the relative location `rel_location`. """ fnames = parse_qs(request.META.get("QUERY_STRING", "")) if fnames: if fnames[0].endswith('.js'): content_type = 'text/javascript; charset=UTF-8' elif fnames[0].endswith('.css'): content_type = 'text/css' elif default_redirect is not None and len(fnames) == 1: return HttpResponseRedirect( "%s%s" % (default_redirect, fnames[0])) else: return HttpResponseBadRequest("Invalid file type requested.") content = "".join( [content.decode(encoding) for content in combine_files( fnames, location, resource_prefix='/', rewrite_urls=True)]) return HttpResponse( content_type=content_type, status=200, content=content) return HttpResponseNotFound()
def merge_view(request, filename): """Merge the `files` from `location` into one file. Return the HTTP response with `content_type`. """ merge_info = MERGE_VIEWS.get(filename, None) if merge_info is None: return HttpResponseNotFound() location = merge_info.get("location", None) if location is None: location = get_absolute_location() content = "".join( [content.decode('utf-8') for content in combine_files( merge_info["files"], location, resource_prefix='/', rewrite_urls=True)]) return HttpResponse( content_type=merge_info["content_type"], status=200, content=content)
def combo_view(request): """Handle a request for combining a set of files.""" fnames = parse_qs(request.META.get("QUERY_STRING", "")) content_type = "text/plain" if fnames: if fnames[0].endswith(".js"): content_type = "text/javascript" elif fnames[0].endswith(".css"): content_type = "text/css" content = combine_files( fnames, os.path.abspath(settings.STATIC_ROOT), resource_prefix=settings.STATIC_URL, rewrite_urls=True) return HttpResponse( content_type=content_type, status=200, content="".join(content)) return HttpResponse(content_type=content_type, status=404)