Пример #1
0
def serve(request, path, document_root):
    storage = OverwritingStorage()

    if not storage.exists(path):
        storage.get_remote_file(path)
    
    return static_serve(request, path, document_root)
Пример #2
0
 def serve_media(*args, **kwargs):
     response = static_serve(*args, **kwargs)
     response['Access-Control-Allow-Origin'] = '*'
     if ((settings.BUNDLE_BROTLI_COMPRESS
          and kwargs['path'].startswith(settings.MEDIA_BUNDLES_ROOT))):
         response['Content-Encoding'] = 'br'
     return response
Пример #3
0
def serve(request, project_object, path):
    if len(path.split('/')) == 2 and path.split('/')[0] in (settings.ORIGINAL_LANGUAGE,settings.TRANSLATION_LANGUAGE) and path.split('/')[1] == '':
        for index_name in index_names:
            print os.path.join(settings.WEB_DOCS_DIR, project_object.slug, path.split('/')[0], index_name)
            if os.path.exists(os.path.join(settings.WEB_DOCS_DIR, project_object.slug, path.split('/')[0], index_name)):
                return HttpResponseRedirect(request.path + index_name)
    return static_serve(request, path, document_root=os.path.join(settings.WEB_DOCS_DIR, project_object.slug), show_indexes=False)
Пример #4
0
 def serve_media(*args, **kwargs):
     response = static_serve(*args, **kwargs)
     response['Access-Control-Allow-Origin'] = '*'
     if ((settings.BUNDLE_BROTLI_COMPRESS and
          kwargs['path'].startswith(settings.MEDIA_BUNDLES_ROOT))):
         response['Content-Encoding'] = 'br'
     return response
Пример #5
0
def serve_dir_or_index(request, path, document_root):
    if len(path) == 0:
        path = 'index.html'

    try:
        return static_serve(request, path, document_root)
    except Http404:
        return HttpResponse(
            "User interface file not found, check that the Calamari user interface is properly installed.",
            status=404)
Пример #6
0
def serve(request, path, document_root=None, show_indexes=False):
    """
    Static file serving for Forge releases; should only be used when DEBUG
    is set -- it deletes 'Content-Encoding' header so that module tarball
    data isn't extracted twice by the Puppet module tool.
    """
    response = static_serve(request, path,
                            document_root=document_root,
                            show_indexes=show_indexes)
    if path.endswith('.tar.gz'):
        del response['Content-Encoding']
    return response
Пример #7
0
def do_serve_file_no_auth(request,
                          fname=None,
                          folder=REPORT_FOLDER,
                          as_attachment=False):
    if settings.SERVE_AUDIO_FILES:
        return static_serve(request, fname, folder, True)
    response = HttpResponse()
    del response['content-type']
    target = 'protected_dl' if as_attachment else 'protected'
    response['X-Accel-Redirect'] = "/{target}/{fname}".format(target=target,
                                                              fname=fname)
    return response
Пример #8
0
def serve(request, project_object, path):
    if len(path.split('/')) == 2 and path.split('/')[0] in (
            settings.ORIGINAL_LANGUAGE,
            settings.TRANSLATION_LANGUAGE) and path.split('/')[1] == '':
        for index_name in index_names:
            print os.path.join(settings.WEB_DOCS_DIR, project_object.slug,
                               path.split('/')[0], index_name)
            if os.path.exists(
                    os.path.join(settings.WEB_DOCS_DIR, project_object.slug,
                                 path.split('/')[0], index_name)):
                return HttpResponseRedirect(request.path + index_name)
    return static_serve(request,
                        path,
                        document_root=os.path.join(settings.WEB_DOCS_DIR,
                                                   project_object.slug),
                        show_indexes=False)
Пример #9
0
    def serve(request, path, document_root=None, show_indexes=False):
        """
        An override to `django.views.static.serve` that will allow us to add our
        own headers for development.

        Like `django.views.static.serve`, this should only ever be used in
        development, and never in production.

        NOTE: Use `runserver --nostatic` to avoid staticfiles automatically add urlconf.
        """
        response = static_serve(request,
                                path,
                                document_root=document_root,
                                show_indexes=show_indexes)

        response['Access-Control-Allow-Origin'] = '*'
        return response
Пример #10
0
def fileserve(request, path):
    """
    Rewrite URLs to use current language as folder root prefix.
    TODO: Could be done with ``mod_rewrite`` at deployment.
    """

    if '.geojson' not in mimetypes.types_map:
        mimetypes.add_type('application/json', '.geojson')
    if '.gpx' not in mimetypes.types_map:
        mimetypes.add_type('application/gpx+xml', '.gpx')
    if '.kml' not in mimetypes.types_map:
        mimetypes.add_type('application/vnd.google-earth.kml+xml', '.kml')
    if '.kmz' not in mimetypes.types_map:
        mimetypes.add_type('application/vnd.google-earth.kmz', '.kmz')

    path = path[1:] if path.startswith('/') else path
    if not os.path.exists(os.path.join(settings.INPUT_DATA_ROOT, path)):
        path = os.path.join(request.LANGUAGE_CODE, path)
    return static_serve(request, path, document_root=settings.INPUT_DATA_ROOT)
Пример #11
0
 def serve_media(*args, **kwargs):
     response = static_serve(*args, **kwargs)
     response['Access-Control-Allow-Origin'] = '*'
     return response
Пример #12
0
 def serve_media(*args, **kwargs):
     response = static_serve(*args, **kwargs)
     response['Access-Control-Allow-Origin'] = '*'
     return response
Пример #13
0
def server_error_404_subdomain(request, template_name='404.html'):
    """
    Handler for 404 pages on subdomains.

    Check if the project associated has a custom ``404.html`` and serve this
    page. First search for a 404 page in the current version, then continues
    with the default version and finally, if none of them are found, the Read
    the Docs default page (Maze Found) is rendered by Django and served.
    """

    def resolve_404_path(project, version_slug=None, language=None):
        """
        Helper to resolve the path of ``404.html`` for project.

        The resolution is based on ``project`` object, version slug and
        language.

        :returns: tuple containing the (basepath, filename)
        :rtype: tuple
        """
        filename = resolve_path(
            project,
            version_slug=version_slug,
            language=language,
            filename='404.html',
            subdomain=True,  # subdomain will make it a "full" path without a URL prefix
        )

        # This breaks path joining, by ignoring the root when given an "absolute" path
        if filename[0] == '/':
            filename = filename[1:]

        version = None
        if version_slug:
            version_qs = project.versions.filter(slug=version_slug)
            if version_qs.exists():
                version = version_qs.first()

        private = any([
            version and version.privacy_level == PRIVATE,
            not version and project.privacy_level == PRIVATE,
        ])
        if private:
            symlink = PrivateSymlink(project)
        else:
            symlink = PublicSymlink(project)
        basepath = symlink.project_root
        fullpath = os.path.join(basepath, filename)
        return (basepath, filename, fullpath)

    project, full_path = project_and_path_from_request(request, request.get_full_path())

    if project:
        language = None
        version_slug = None
        schema, netloc, path, params, query, fragments = urlparse(full_path)
        if not project.single_version:
            language, version_slug, path = language_and_version_from_path(path)

        # Firstly, attempt to serve the 404 of the current version (version_slug)
        # Secondly, try to serve the 404 page for the default version (project.get_default_version())
        for slug in (version_slug, project.get_default_version()):
            basepath, filename, fullpath = resolve_404_path(project, slug, language)
            if os.path.exists(fullpath):
                log.debug(
                    'serving 404.html page current version: [project: %s] [version: %s]',
                    project.slug,
                    slug,
                )
                r = static_serve(request, filename, basepath)
                r.status_code = 404
                return r

    # Finally, return the default 404 page generated by Read the Docs
    r = render(request, template_name)
    r.status_code = 404
    return r
Пример #14
0
 def serve(self, request, file_path, *args, **kwargs):
     """Backend serve command for serving the asset as a response."""
     dirname = path.dirname(file_path)
     basename = path.basename(file_path)
     return static_serve(request, basename, dirname)
Пример #15
0
def server_error_404_subdomain(request, template_name='404.html'):
    """
    Handler for 404 pages on subdomains.

    Check if the project associated has a custom ``404.html`` and serve this
    page. First search for a 404 page in the current version, then continues
    with the default version and finally, if none of them are found, the Read
    the Docs default page (Maze Found) is rendered by Django and served.
    """

    def resolve_404_path(project, version_slug=None, language=None, filename='404.html'):
        """
        Helper to resolve the path of ``404.html`` for project.

        The resolution is based on ``project`` object, version slug and
        language.

        :returns: tuple containing the (basepath, filename)
        :rtype: tuple
        """
        filename = resolve_path(
            project,
            version_slug=version_slug,
            language=language,
            filename=filename,
            subdomain=True,  # subdomain will make it a "full" path without a URL prefix
        )

        # This breaks path joining, by ignoring the root when given an "absolute" path
        if filename[0] == '/':
            filename = filename[1:]

        version = None
        if version_slug:
            version_qs = project.versions.filter(slug=version_slug)
            if version_qs.exists():
                version = version_qs.first()

        private = any([
            version and version.privacy_level == PRIVATE,
            not version and project.privacy_level == PRIVATE,
        ])
        if private:
            symlink = PrivateSymlink(project)
        else:
            symlink = PublicSymlink(project)
        basepath = symlink.project_root
        fullpath = os.path.join(basepath, filename)
        return (basepath, filename, fullpath)

    project, full_path = project_and_path_from_request(request, request.get_full_path())

    if project:
        language = None
        version_slug = None
        schema, netloc, path, params, query, fragments = urlparse(full_path)
        if not project.single_version:
            language, version_slug, path = language_and_version_from_path(path)

        # Firstly, attempt to serve the 404 of the current version (version_slug)
        # Secondly, try to serve the 404 page for the default version
        # (project.get_default_version())
        for slug in (version_slug, project.get_default_version()):
            for tryfile in ('404.html', '404/index.html'):
                basepath, filename, fullpath = resolve_404_path(project, slug, language, tryfile)
                if os.path.exists(fullpath):
                    log.debug(
                        'serving 404.html page current version: [project: %s] [version: %s]',
                        project.slug,
                        slug,
                    )
                    r = static_serve(request, filename, basepath)
                    r.status_code = 404
                    return r

    # Finally, return the default 404 page generated by Read the Docs
    r = render(request, template_name)
    r.status_code = 404
    return r
Пример #16
0
def serve_dir_or_index(request, path, document_root):
    if len(path) == 0:
        path = 'index.html'
    return static_serve(request, path, document_root)
Пример #17
0
def serve_dir_or_index(request, path, document_root):
    if len(path) == 0:
        path = 'index.html'
    return static_serve(request, path, document_root)
Пример #18
0
def get_image(request, filename):
    # serve a single uploaded image
    response = static_serve(request, filename, document_root="radon_server/static/uploaded", show_indexes=False)

    response['Access-Control-Allow-Origin'] = "*"
    return response
Пример #19
0
 def serve_media(*args, **kwargs):
     response = static_serve(*args, **kwargs)
     response['Access-Control-Allow-Origin'] = '*'
     if settings.BUNDLE_BROTLI_COMPRESS:
         response['Content-Encoding'] = 'br'
     return response
Пример #20
0
def index(request):
    return static_serve(request, 'index.html', '/home/sjappelodorus/verifikatorc1/static')
Пример #21
0
def index(request):
    return static_serve(request, 'index.html',
                        '/home/sjappelodorus/verifikatorc1/static')
Пример #22
0
def favicon(request):
    file = finders.find("images/favicons/favicon.ico")
    return static_serve(request, file, document_root="/")