def home(request):

    response = TemplateResponse(request, 'dashboard.html')

    response.add_post_render_callback(callback_Home)

    return response
Exemple #2
0
def check_notifications(request):
    user = get_user(request)
    notes = Notification.objects.filter(user=user).order_by('-message__date')
    response = TemplateResponse(request, 'notifications.html',
                                {'notifications': notes})
    response.add_post_render_callback(render_callback)
    return response
Exemple #3
0
def render_article(request, article, current_language, slug):
    """
    Renders an article
    """
    context = {}
    context['article'] = article
    context['lang'] = current_language
    context['current_article'] = article
    context['has_change_permissions'] = article.has_change_permission(request)

    response = TemplateResponse(request, article.template, context)
    response.add_post_render_callback(set_page_cache)

    # Add headers for X Frame Options - this really should be changed upon moving to class based views
    xframe_options = article.tree.get_xframe_options()
    # xframe_options can be None if there's no xframe information on the page
    # (eg. a top-level page which has xframe options set to "inherit")
    if xframe_options == Page.X_FRAME_OPTIONS_INHERIT or xframe_options is None:
        # This is when we defer to django's own clickjacking handling
        return response

    # We want to prevent django setting this in their middlewear
    response.xframe_options_exempt = True

    if xframe_options == Page.X_FRAME_OPTIONS_ALLOW:
        # Do nothing, allowed is no header.
        return response
    elif xframe_options == Page.X_FRAME_OPTIONS_SAMEORIGIN:
        response['X-Frame-Options'] = 'SAMEORIGIN'
    elif xframe_options == Page.X_FRAME_OPTIONS_DENY:
        response['X-Frame-Options'] = 'DENY'
    return response
Exemple #4
0
def template_response(request):
    response = TemplateResponse(request, 'views/index.html', {
        'data': 'context',
        'templatesresponse': True
    })
    response.add_post_render_callback(my_render_callback)
    print('hi')
    return response
Exemple #5
0
def report(request, slug_val):
    side_nav = SideNav.objects.filter(slug=slug_val)
    for i in side_nav:
        temp = i.template

    # a = render(request, "report/content.html", {'temp': temp, 'sideLinks': SideNav.objects.all, 'title': slug_val,
    # 'view': 'report'})

    data = {
        'html': temp.html,
        'css': temp.css,
        'js': temp.js,
        'title': side_nav[0].side_nav,
        'sideLinks': SideNav.objects.all,
    }

    response = TemplateResponse(request, 'report/detail.html', data)
    compress = cp.compress()
    response.app_name = request.resolver_match.app_name
    response.add_post_render_callback(compress.getLinks)

    return response
Exemple #6
0
def render_page(request, page, current_language, slug):
    """
    Renders a page
    """
    template_name = get_template_from_request(request, page, no_current_page=True)
    # fill the context
    context = {}
    context["lang"] = current_language
    context["current_page"] = page
    context["has_change_permissions"] = user_can_change_page(request.user, page)
    context["has_view_permissions"] = user_can_view_page(request.user, page)

    if not context["has_view_permissions"]:
        return _handle_no_page(request, slug)

    response = TemplateResponse(request, template_name, context)
    response.add_post_render_callback(set_page_cache)

    # Add headers for X Frame Options - this really should be changed upon moving to class based views
    xframe_options = page.get_xframe_options()
    # xframe_options can be None if there's no xframe information on the page
    # (eg. a top-level page which has xframe options set to "inherit")
    if xframe_options == Page.X_FRAME_OPTIONS_INHERIT or xframe_options is None:
        # This is when we defer to django's own clickjacking handling
        return response

    # We want to prevent django setting this in their middlewear
    response.xframe_options_exempt = True

    if xframe_options == Page.X_FRAME_OPTIONS_ALLOW:
        # Do nothing, allowed is no header.
        return response
    elif xframe_options == Page.X_FRAME_OPTIONS_SAMEORIGIN:
        response["X-Frame-Options"] = "SAMEORIGIN"
    elif xframe_options == Page.X_FRAME_OPTIONS_DENY:
        response["X-Frame-Options"] = "DENY"
    return response
Exemple #7
0
def teadetail_response(request):
    response = TemplateResponse(request, "customapp/detail.html", {})
    response.add_post_render_callback(teadetails)