Last active
August 29, 2015 14:06
-
-
Save nop33/27b6be6d2e1819d7441a 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 | |
from forms import CustomContactForm | |
class CustomContactPlugin(ContactPlugin): | |
name = _("Custom Contact Form") | |
model = CustomContact | |
contact_form = CustomContactForm | |
render_template = "cmsplugin_custom_contact/contact.html" | |
email_template = "cmsplugin_custom_contact/email.txt" | |
subject_template = "cmsplugin_custom_contact/subject.txt" | |
fieldsets = ( | |
(None, { | |
'fields': ('site_email', 'email_label', 'custom_label', | |
'subject_label', 'content_label', 'thanks', | |
'submit', 'mandatory_note_label'), | |
}), | |
(_('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): | |
custom = forms.CharField() | |
mandatory_note = forms.CharField() | |
##### models.py ##### | |
from django.db import models | |
from cmsplugin_contact.models import BaseContact | |
from django.utils.translation import ugettext_lazy as _ | |
class CustomContact(BaseContact): | |
custom_label = models.CharField( | |
_('Custom sender label'), | |
default=_('Your custom value'), 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.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.content_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 }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment