Esempio n. 1
0
# -*- coding: utf-8 -*-
"""
Edit Toolbar middleware
"""
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
from django.core.urlresolvers import resolve
from django.http import HttpResponse

from cms.toolbar.toolbar import CMSToolbar
from cms.utils.conf import get_cms_setting
from cms.utils.i18n import force_language
from cms.utils.request_ip_resolvers import get_request_ip_resolver
from menus.menu_pool import menu_pool

get_request_ip = get_request_ip_resolver()


def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
    toolbar = original_context['request'].toolbar

    instance.placeholder = placeholder

    with force_language(toolbar.toolbar_language):
        data = {
            'instance': instance,
            'rendered_content': rendered_content,
        }
        # TODO: Remove js_compat once get_action_urls is refactored.
        data.update(instance.get_action_urls(js_compat=False))

    original_context.update(data)
Esempio n. 2
0
"""
Edit Toolbar middleware
"""
from django import forms
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
from django.core.exceptions import ValidationError
from django.urls import resolve, Resolver404
from django.utils.deprecation import MiddlewareMixin

from cms.toolbar.toolbar import CMSToolbar
from cms.toolbar.utils import get_toolbar_from_request
from cms.utils.conf import get_cms_setting
from cms.utils.request_ip_resolvers import get_request_ip_resolver

get_request_ip = get_request_ip_resolver()


class ToolbarMiddleware(MiddlewareMixin):
    """
    Middleware to set up CMS Toolbar.
    """
    def is_cms_request(self, request):
        toolbar_hide = get_cms_setting('TOOLBAR_HIDE')
        internal_ips = get_cms_setting('INTERNAL_IPS')

        if internal_ips:
            client_ip = get_request_ip(request)
            try:
                client_ip = forms.GenericIPAddressField().clean(client_ip)
            except ValidationError:
                return False
Esempio n. 3
0
.. module:: cms_plugins
   :synopsis: Edit Toolbar middleware
"""
from django import forms
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
from django.core.exceptions import ValidationError
from django.core.urlresolvers import resolve
from django.utils.cache import add_never_cache_headers

from cms.toolbar.toolbar import CMSToolbar
from cms.toolbar.utils import get_toolbar_from_request
from cms.utils.conf import get_cms_setting
from cms.utils.compat.dj import MiddlewareMixin
from cms.utils.request_ip_resolvers import get_request_ip_resolver

GET_REQUEST_IP = get_request_ip_resolver()


class ToolbarMiddleware(MiddlewareMixin):
    """
    Middleware to set up CMS Toolbar.
    """
    @staticmethod
    def is_cms_request(request):
        """Determines using a varety of methods if the request should be shown a toolbar.
        Via configured source IPs, cookies, and url.
        """

        toolbar_hide = get_cms_setting('TOOLBAR_HIDE')
        internal_ips = get_cms_setting('INTERNAL_IPS')