Skip to content

Commit

Permalink
updated customizing example
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Stefan Cassola committed Sep 24, 2014
1 parent 9aeaefc commit a8f2cfc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
9 changes: 7 additions & 2 deletions cmsplugin_contact/cms_plugins.py
Expand Up @@ -43,7 +43,8 @@ class ContactPlugin(CMSPluginBase):
'fields': ('thanks', 'redirect_url' ),
} ),
(_('Spam Protection'), {
'fields': ('spam_protection_method', 'akismet_api_key', 'recaptcha_public_key', 'recaptcha_private_key', 'recaptcha_theme')
'fields': ('spam_protection_method', 'akismet_api_key',
'recaptcha_public_key', 'recaptcha_private_key', 'recaptcha_theme')
})
)

Expand Down Expand Up @@ -118,7 +119,11 @@ class ContactForm(ContactFormBase, HoneyPotContactForm):
form = FormClass(request, data=request.POST, files=request.FILES)
else:
form = FormClass(request)
form.fields['my_name'] = forms.CharField(max_length=len(instance.form_name), widget=forms.HiddenInput, label='', initial=instance.form_name)
form.fields['my_name'] = forms.CharField(max_length=len(instance.form_name),
widget=forms.HiddenInput,
label='',
initial=instance.form_name,
required=False)
return form

def send(self, form, form_name, site_email, attachments=None):
Expand Down
29 changes: 18 additions & 11 deletions examples/cmsplugin_custom_contact/cms_plugins.py
Expand Up @@ -4,29 +4,36 @@

from cmsplugin_contact.cms_plugins import ContactPlugin
from models import CustomContact
from forms import CustomContactForm

class CustomContactPlugin(ContactPlugin):
name = _("Custom Contact Form")

model = CustomContact
contact_form = CustomContactForm

# We're using the original cmsplugin_contact templates here which

# Important: You have to add the following to your settings.py
# CMSPLUGIN_CONTACT_FORMS = (
# ('cmsplugin_contact.forms.ContactForm', _('default')),
# ('cmsplugin_custom_contact.forms.CustomContactForm', _('custom')),
# )
# if you're only using your custom plugin you can omit the first line

# We're using the original cmsplugin_contact render templates here which
# works fine but requires that the original plugin is in INSTALLED_APPS.
render_template = "cmsplugin_contact/contact.html"
email_template = "cmsplugin_contact/email.txt"

# Custom email template to incorporate you custom data
email_template = "cmsplugin_custom_contact/email.txt"

fieldsets = (
(None, {
'fields': ('site_email', 'email_label', 'custom_label',
'subject_label', 'content_label', 'thanks',
'submit'),
'fields': ('form_name', 'form_layout', 'site_email', 'submit', 'custom_label'),
}),
(_('Redirection'), {
'fields': ('thanks', 'redirect_url' ),
} ),
(_('Spam Protection'), {
'fields': ('spam_protection_method', 'akismet_api_key',
'recaptcha_public_key', 'recaptcha_private_key',
'recaptcha_theme')
'fields': ('spam_protection_method', 'akismet_api_key',
'recaptcha_public_key', 'recaptcha_private_key', 'recaptcha_theme')
})
)

Expand Down
@@ -0,0 +1,6 @@
{% load i18n %}{% trans "Message from" %}: {{ data.email }}

{{ data.content|safe }}

The awesome custom value:
{{ data.custom }}

0 comments on commit a8f2cfc

Please sign in to comment.