Created
September 24, 2014 22:39
-
-
Save nop33/81df80c3e95703c13a01 to your computer and use it in GitHub Desktop.
cmsplugin_custom_contact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### cms_plugins.py ##### | |
from django.utils.translation import ugettext_lazy as _ | |
from cms.plugin_pool import plugin_pool | |
from cmsplugin_contact.cms_plugins import ContactPlugin | |
from models import CustomContact | |
class CustomContactPlugin(ContactPlugin): | |
name = _("Custom Contact Form") | |
model = CustomContact | |
render_template = "cmsplugin_custom_contact/contact.html" | |
email_template = "cmsplugin_custom_contact/email.txt" | |
subject_template = "cmsplugin_custom_contact/subject.txt" | |
fieldsets = ( | |
(None, { | |
'fields': ('form_name', 'form_layout', 'site_email', 'submit', 'mandatory_note_label', 'sender_email_label', | |
'subject_label', 'message_label'), | |
}), | |
(_('Redirection'), { | |
'fields': ('thanks', 'redirect_url' ), | |
} ), | |
(_('Spam Protection'), { | |
'fields': ('spam_protection_method', 'akismet_api_key', | |
'recaptcha_public_key', 'recaptcha_private_key', 'recaptcha_theme') | |
}) | |
) | |
plugin_pool.register_plugin(CustomContactPlugin) | |
##### forms.py ##### | |
from django import forms | |
from cmsplugin_contact.forms import ContactForm | |
class CustomContactForm(ContactForm): | |
sender_email = forms.CharField() | |
subject = forms.CharField() | |
message = forms.CharField() | |
mandatory_note = forms.CharField() | |
template = "cmsplugin_custom_contact/contact.html" | |
##### models.py ##### | |
from django.db import models | |
from cmsplugin_contact.models import BaseContact | |
from django.utils.translation import ugettext_lazy as _ | |
class CustomContact(BaseContact): | |
sender_email_label = models.CharField( | |
_('Sender email label'), | |
default=_('Your email'), max_length=20) | |
subject_label = models.CharField( | |
_('Subject label'), | |
default=_('Subject'), max_length=20) | |
message_label = models.CharField( | |
_('Message label'), | |
default=_('Your message'), max_length=20) | |
mandatory_note_label = models.CharField( | |
_('Mandatory note'), | |
default=_('mandatory fields'), max_length=128) | |
##### templates/cmsplugin_custom_contact/contact.html ##### | |
# took it from here: https://gist.github.com/nikolayhg/7000624 | |
{% load i18n widget_tweaks %} | |
{% if form %} | |
<form action="." method="post"> | |
<div id="div_{{ form.email.auto_id }}" class="row form-group{% if form.email.errors %} has-error{% endif %}"> | |
<label for="{{ form.email.auto_id }}" | |
class="control-label clearboth pad-top-s textalignright col-lg-3 col-md-3 requiredField"> | |
{{ contact.sender_email_label }}<span class="asteriskField">*</span> | |
</label> | |
<div class="controls pad-bottom col-lg-9 col-md-9"> | |
{{ form.email|add_class:"form-control" }} | |
{% if form.email.errors %} | |
{% for error in form.email.errors %} | |
<span class="help-block"><strong>{{ error }}</strong></span> | |
{% endfor %} | |
{% endif %} | |
</div> | |
</div> | |
<div id="div_{{ form.subject.auto_id }}" class="row form-group{% if form.subject.errors %} has-error{% endif %}"> | |
<label for="{{ form.subject.auto_id }}" | |
class="control-label clearboth pad-top-s textalignright col-lg-3 col-md-3"> | |
{{ contact.subject_label }} | |
</label> | |
<div class="controls pad-bottom col-lg-9 col-md-9"> | |
{{ form.subject|add_class:"form-control" }} | |
{% if form.subject.errors %} | |
{% for error in form.subject.errors %} | |
<span class="help-block" class="help-block"><strong>{{ error }}</strong></span> | |
{% endfor %} | |
{% endif %} | |
</div> | |
</div> | |
<div id="div_{{ form.content.auto_id }}" class="row form-group{% if form.content.errors %} has-error{% endif %}"> | |
<label for="{{ form.content.auto_id }}" | |
class="control-label clearboth pad-top-s textalignright col-lg-3 col-md-3 requiredField"> | |
{{ contact.message_label }} <span class="asteriskField">*</span> | |
</label> | |
<div class="controls pad-bottom col-lg-9 col-md-9"> | |
{{ form.content|add_class:"form-control" }} | |
{% if form.content.errors %} | |
{% for error in form.content.errors %} | |
<span class="help-block"><strong>{{ error }}</strong></span> | |
{% endfor %} | |
{% endif %} | |
</div> | |
</div> | |
{% if form.recaptcha_challenge_field %} | |
<div{% if form.recaptcha_response_field.errors %} class="error"{% endif %}> | |
{{ form.recaptcha_challenge_field }} | |
{% if form.recaptcha_theme == "custom" %} | |
<div id="recaptcha_widget" style="display:none"> | |
<div id="recaptcha_image"></div> | |
<span class="recaptcha_only_if_incorrect_sol error_msg">{% trans "Incorrect please try again" %}</span> | |
<label> | |
<span class="recaptcha_only_if_image">{% trans "Enter the words above:" %}</span> | |
<span class="recaptcha_only_if_audio">{% trans "Enter the numbers you hear:" %}</span> | |
</label> | |
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field"/> | |
<div><a href="javascript:Recaptcha.reload()">{% trans "Get another CAPTCHA" %}</a></div> | |
<div class="recaptcha_only_if_image"><a | |
href="javascript:Recaptcha.switch_type('audio')">{% trans "Get an audio CAPTCHA" %}</a></div> | |
<div class="recaptcha_only_if_audio"><a | |
href="javascript:Recaptcha.switch_type('image')">{% trans "Get an image CAPTCHA" %}</a></div> | |
<div><a href="javascript:Recaptcha.showhelp()">{% trans "Help" %}</a> | |
</div> | |
{% endif %} | |
{% if form.recaptcha_response_field.label %}<label class="contact_field"> | |
{{ form.recaptcha_response_field.label }}</label>{% endif %} | |
{{ form.recaptcha_response_field }} | |
{% if form.recaptcha_response_field.errors %} | |
{% for error in form.recaptcha_response_field.errors %} | |
<span class="error_msg">{% trans error %}</span> | |
{% endfor %} | |
{% endif %} | |
</div> | |
{% endif %} | |
{% if form.accept_terms %} | |
{{ form.accept_terms }} | |
{% endif %} | |
<div class="clearboth pad-top-s textalignright col-lg-3 col-md-3"></div> | |
<div class="pad-bottom col-lg-9 col-md-9"> | |
* - {{ contact.mandatory_note_label|safe }}. | |
</div> | |
<div class="clearboth col-lg-3 col-md-3"> </div> | |
<div class="pad-bottom col-lg-9 col-md-9"> | |
<button type="submit" class="btn btn-lg btn-green">{{ contact.submit }}</button> | |
</div> | |
{% csrf_token %} | |
</form> | |
{% else %} | |
{{ contact.thanks|safe }} | |
{% endif %} | |
##### templates/cmsplugin_custom_contact/email.txt ##### | |
{{ data.content }} | |
##### templates/cmsplugin_custom_contact/subject.txt ##### | |
[Contactform] {{ subject }} | |
##### /settings.py ##### | |
CMSPLUGIN_CONTACT_FORMS = ( | |
('cmsplugin_contact.forms.ContactForm', _('default')), | |
('cmsplugin_custom_contact.forms.CustomContactForm', _('custom')), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment