Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 40 lines (33 sloc) 1.21 KB
# -*- coding: utf-8 -*-
Edit Toolbar middleware
from cms.cms_toolbar import CMSToolbar
from django.http import HttpResponse
from django.template.loader import render_to_string
def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
data = {
'instance': instance,
'rendered_content': rendered_content
output = render_to_string(instance.get_plugin_class().frontend_edit_template, original_context)
return output
class ToolbarMiddleware(object):
Middleware to set up CMS Toolbar.
def process_request(self, request):
If we should show the toolbar for this request, put it on
request.toolbar. Then call the request_hook on the toolbar.
if 'edit' in request.GET and not request.session.get('cms_edit', False):
request.session['cms_edit'] = True
request.toolbar = CMSToolbar(request)
def process_view(self, request, view_func, view_args, view_kwarg):
response = request.toolbar.request_hook()
if isinstance(response, HttpResponse):
return response
Jump to Line
Something went wrong with that request. Please try again.