The answer was found here: https://djangosnippets.org/snippets/2541/
The problem was that cms-plugin can't return a responce object, where cookies need to bet set... So the trick is to throw a custom exception with HttpResponceRedirect
Question
Using Django 1.5.5, Django-CMS 2.4.2 I wrote a plugin for django-cms *(cms.plugin_base.CMSPluginBase)*. Plugin create a some form, that works fine. But I get a problem - after submitting a form - how can I set a cookie ?
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from poll.models import PagePoll
from poll.forms import PollForm
from django.http import HttpResponse
class PollPlugin(CMSPluginBase):
""" upload a poll """
model = PagePoll
name = u'Poll'
render_template = u"plugins/page_poll.html"
def render(self, context, instance, placeholder):
#upload poll form
request = context['request']
form = PollForm(instance.poll, request.POST)
#validate the form
if request.method == 'POST':
if form.is_valid():
form.save()
#=SAVE COOKIES HERE=
else:
form = PollForm(instance.poll)
context['form'] = form
return context
plugin_pool.register_plugin(PollPlugin)
Solution
The answer was found here: https://djangosnippets.org/snippets/2541/
The problem was that cms-plugin can't return a responce object, where cookies need to bet set... So the trick is to throw a custom exception with HttpResponceRedirect