Exemplo n.º 1
0
def handler(request, path=None):
    if path is None:
        path = request.path

    page = Page.objects.best_match_for_path(path, raise404=True)

    applicationcontents = page.applicationcontent_set.all()

    if request.path != page.get_absolute_url():
        # The best_match logic kicked in. See if we have at least one
        # application content for this page, and raise a 404 otherwise.

        if not applicationcontents:
            raise Http404

    # The monkey-patched reverse() method needs some information
    # for proximity analysis when determining the nearest
    # application integration point
    retrieve_page_information(page)

    response = page.setup_request(request)
    if response:
        return response

    for content in applicationcontents:
        r = content.process(request)
        if r and (r.status_code != 200 or request.is_ajax() or getattr(r, 'standalone', False)):
            return r

    response = _build_page_response(page, request)
    page.finalize_response(request, response)
    return response
Exemplo n.º 2
0
def build_page_response(page, request):
    from django.core.cache import cache as django_cache

    # Try to avoid the lookup of app contents by caching, since nodes
    # with app content are a rather rare occurrence, this is a win in
    # most cases.
    has_appcontent = True
    if settings.FEINCMS_USE_CACHE:
        ck = 'HAS-APP-CONTENT-' + page.cache_key()
        has_appcontent = django_cache.get(ck, True)

    if has_appcontent:
        applicationcontents = page.applicationcontent_set.all()
        has_appcontent = any(applicationcontents)
        if settings.FEINCMS_USE_CACHE:
            django_cache.set(ck, has_appcontent)

    if request.path != page.get_absolute_url():
        # The best_match logic kicked in. See if we have at least one
        # application content for this page, and raise a 404 otherwise.
        if not has_appcontent:
            raise Http404
        else:
            request._feincms_appcontent_parameters['in_appcontent_subpage'] = True

    # The monkey-patched reverse() method needs some information
    # for proximity analysis when determining the nearest
    # application integration point
    retrieve_page_information(page)

    response = page.setup_request(request)
    if response:
        return response

    if has_appcontent:
        for content in applicationcontents:
            r = content.process(request)
            if r and (r.status_code != 200 or request.is_ajax() or getattr(r, 'standalone', False)):
                return r

    response = _build_page_response(page, request)
    page.finalize_response(request, response)
    return response
Exemplo n.º 3
0
def build_page_response(page, request):
    has_appcontent = page_has_appcontent(page)

    if request.path != page.get_absolute_url():
        # The best_match logic kicked in. See if we have at least one
        # application content for this page, and raise a 404 otherwise.
        if not has_appcontent:
            if not settings.FEINCMS_ALLOW_EXTRA_PATH:
                raise Http404
        else:
            request._feincms_appcontent_parameters['in_appcontent_subpage'] = True

        extra_path = request.path[len(page.get_absolute_url()):]
        extra = extra_path.strip('/').split('/')
        request._feincms_appcontent_parameters['page_extra_path'] = extra
        request.extra_path = extra_path
    else:
        request.extra_path = ""

    # The monkey-patched reverse() method needs some information
    # for proximity analysis when determining the nearest
    # application integration point
    retrieve_page_information(page)

    response = page.setup_request(request)
    if response:
        return response

    if has_appcontent:
        for content in page.applicationcontent_set.all():
            r = content.process(request)
            if r and (r.status_code != 200 or request.is_ajax() or getattr(r, 'standalone', False)):
                return r

    response = _build_page_response(page, request)

    if has_appcontent:
        response['Cache-Control'] = 'no-cache, must-revalidate'

    page.finalize_response(request, response)

    return response
Exemplo n.º 4
0
def build_page_response(page, request):
    has_appcontent = page_has_appcontent(page)

    if request.path != page.get_absolute_url():
        # The best_match logic kicked in. See if we have at least one
        # application content for this page, and raise a 404 otherwise.
        if not has_appcontent:
            if not settings.FEINCMS_ALLOW_EXTRA_PATH:
                raise Http404
        else:
            request._feincms_appcontent_parameters[
                'in_appcontent_subpage'] = True

        extra_path = request.path[len(page.get_absolute_url()):]
        extra = extra_path.strip('/').split('/')
        request._feincms_appcontent_parameters['page_extra_path'] = extra
        request.extra_path = extra_path
    else:
        request.extra_path = ""

    # The monkey-patched reverse() method needs some information
    # for proximity analysis when determining the nearest
    # application integration point
    retrieve_page_information(page)

    response = page.setup_request(request)
    if response:
        return response

    if has_appcontent:
        for content in page.applicationcontent_set.all():
            r = content.process(request)
            if r and (r.status_code != 200 or request.is_ajax()
                      or getattr(r, 'standalone', False)):
                return r

    response = _build_page_response(page, request)
    page.finalize_response(request, response)

    return response