示例#1
0
    functions = list(reversed(functions))
    def _inner(*args, **kwargs):
        result = functions[0](*args, **kwargs)
        for f in functions[1:]:
            result = f(result)
        return result
    return _inner


full_decorator = compose(
    # djangocg.views.decorators.http
    require_http_methods(["GET"]),
    require_GET,
    require_POST,
    require_safe,
    condition(lambda r: None, lambda r: None),

    # djangocg.views.decorators.vary
    vary_on_headers('Accept-language'),
    vary_on_cookie,

    # djangocg.views.decorators.cache
    cache_page(60*15),
    cache_control(private=True),
    never_cache,

    # djangocg.contrib.auth.decorators
    # Apply user_passes_test twice to check #9474
    user_passes_test(lambda u:True),
    login_required,
    permission_required('change_world'),
示例#2
0
# -*- coding:utf-8 -*-
from __future__ import absolute_import

from djangocg.views.decorators.http import condition, etag, last_modified
from djangocg.http import HttpResponse

from .models import FULL_RESPONSE, LAST_MODIFIED, ETAG


def index(request):
    return HttpResponse(FULL_RESPONSE)
index = condition(lambda r: ETAG, lambda r: LAST_MODIFIED)(index)

def last_modified_view1(request):
    return HttpResponse(FULL_RESPONSE)
last_modified_view1 = condition(last_modified_func=lambda r: LAST_MODIFIED)(last_modified_view1)

def last_modified_view2(request):
    return HttpResponse(FULL_RESPONSE)
last_modified_view2 = last_modified(lambda r: LAST_MODIFIED)(last_modified_view2)

def etag_view1(request):
    return HttpResponse(FULL_RESPONSE)
etag_view1 = condition(etag_func=lambda r: ETAG)(etag_view1)

def etag_view2(request):
    return HttpResponse(FULL_RESPONSE)
etag_view2 = etag(lambda r: ETAG)(etag_view2)