Permalink
Browse files

display a WYSIWYG widget for "thank you" message

The code is based on django-cms.plugins.text.cms_plugins
  • Loading branch information...
william-gr committed May 15, 2011
1 parent 85aaa47 commit 74c2caea1e66b5300c4c77b6ab0b6844ac6da8ee
Showing with 47 additions and 3 deletions.
  1. +46 −2 cmsplugin_contact/cms_plugins.py
  2. +1 −1 cmsplugin_contact/templates/cmsplugin_contact/contact.html
@@ -1,11 +1,15 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.forms.fields import CharField
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.template.loader import render_to_string
from cms.plugins.text.settings import USE_TINYMCE
from cms.plugins.text.widgets.wymeditor_widget import WYMEditor
from models import Contact
from forms import AkismetContactForm, RecaptchaContactForm, HoneyPotContactForm
from django.core.mail import EmailMessage
from admin import ContactAdminForm
class ContactPlugin(CMSPluginBase):
@@ -25,6 +29,46 @@ class ContactPlugin(CMSPluginBase):
change_form_template = "cmsplugin_contact/admin/plugin_change_form.html"
def get_editor_widget(self, request, plugins):
"""
Returns the Django form Widget to be used for
the text area
"""
if USE_TINYMCE and "tinymce" in settings.INSTALLED_APPS:
from cms.plugins.text.widgets.tinymce_widget import TinyMCEEditor
return TinyMCEEditor(installed_plugins=plugins)
else:
return WYMEditor(installed_plugins=plugins)
def get_form_class(self, request, plugins):
"""
Returns a subclass of Form to be used by this plugin
"""
# We avoid mutating the Form declared above by subclassing
class TextPluginForm(self.form):
pass
widget = self.get_editor_widget(request, plugins)
TextPluginForm.declared_fields["thanks"] = CharField(widget=widget, required=False)
return TextPluginForm
def get_form(self, request, obj=None, **kwargs):
plugins = plugin_pool.get_text_enabled_plugins(self.placeholder, self.page)
form = self.get_form_class(request, plugins)
kwargs['form'] = form # override standard form
return super(ContactPlugin, self).get_form(request, obj, **kwargs)
def get_editor_widget(self, request, plugins):
"""
Returns the Django form Widget to be used for
the text area
"""
if USE_TINYMCE and "tinymce" in settings.INSTALLED_APPS:
from cms.plugins.text.widgets.tinymce_widget import TinyMCEEditor
return TinyMCEEditor(installed_plugins=plugins)
else:
return WYMEditor(installed_plugins=plugins)
def create_form(self, instance, request):
if instance.get_spam_protection_method_display() == 'Akismet':
AkismetContactForm.aksimet_api_key = instance.akismet_api_key
@@ -74,5 +74,5 @@
</form>
{% else %}
<h2>{{ contact.thanks }}</h2>
{{ contact.thanks|safe }}
{% endif %}

0 comments on commit 74c2cae

Please sign in to comment.