pax_global_header00006660000000000000000000000064131241364630014515gustar00rootroot0000000000000052 comment=5212638f3a434112641be2c7fdbd1f9a0538fb17 django-contact-form-1.4.2/000077500000000000000000000000001312413646300153555ustar00rootroot00000000000000django-contact-form-1.4.2/.gitignore000066400000000000000000000001241312413646300173420ustar00rootroot00000000000000*.pyc __pycache__ *.egg-info docs/_build/ dist/ .coverage .python-version .tox/ *.shdjango-contact-form-1.4.2/.travis.yml000066400000000000000000000001761312413646300174720ustar00rootroot00000000000000language: python sudo: false python: - "3.6" - "3.5" - "3.4" - "3.3" - "2.7" install: pip install tox-travis script: tox django-contact-form-1.4.2/LICENSE000066400000000000000000000027631312413646300163720ustar00rootroot00000000000000Copyright (c) 2007-2017, James Bennett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. django-contact-form-1.4.2/MANIFEST.in000066400000000000000000000001401312413646300171060ustar00rootroot00000000000000include LICENSE include MANIFEST.in include README.rst include Makefile recursive-include docs *django-contact-form-1.4.2/Makefile000066400000000000000000000027601312413646300170220ustar00rootroot00000000000000PACKAGE_NAME=contact_form TESTING_VENV_NAME=${PACKAGE_NAME}_test ifndef PYTHON_VERSION PYTHON_VERSION=3.6.0 endif ifndef DJANGO_VERSION DJANGO_VERSION=1.10 endif .PHONY: clean clean: python setup.py clean rm -rf build/ rm -rf dist/ rm -rf *.egg*/ rm -rf ${PACKAGE_NAME}/__pycache__/ rm -rf ${PACKAGE_NAME}/tests/__pycache__/ find ${PACKAGE_NAME} -type f -name '*.pyc' -delete rm -f MANIFEST rm -rf coverage .coverage .coverage* pip uninstall -y Django .PHONY: venv venv: [ -e ~/.pyenv/versions/${TESTING_VENV_NAME} ] && \ echo "\033[1;33mA ${TESTING_VENV_NAME} pyenv already exists. Skipping pyenv creation.\033[0m" || \ pyenv virtualenv ${PYTHON_VERSION} ${TESTING_VENV_NAME} pyenv local ${TESTING_VENV_NAME} pip install --upgrade pip setuptools .PHONY: teardown teardown: clean pyenv uninstall -f ${TESTING_VENV_NAME} rm .python-version .PHONY: django django: pip install Django~=${DJANGO_VERSION}.0 .PHONY: test_dependencies test_dependencies: [ -e test_requirements.txt ] && \ pip install -r test_requirements.txt || \ echo "\033[1;33mNo test_requirements.txt found. Skipping install of test_requirements.txt.\033[0m" pip install -r test_requirements.txt .PHONY: lint lint: test_dependencies flake8 ${PACKAGE_NAME} .PHONY: test test: django lint [ -e requirements.txt ] \ && pip install -r requirements.txt || \ echo "\033[1;33mNo requirements.txt found. Skipping install of requirements.txt.\033[0m" pip install -e . coverage run ${PACKAGE_NAME}/runtests.py coverage report -m django-contact-form-1.4.2/README.rst000066400000000000000000000006531312413646300170500ustar00rootroot00000000000000.. -*-restructuredtext-*- .. image:: https://travis-ci.org/ubernostrum/django-contact-form.svg?branch=master :target: https://travis-ci.org/ubernostrum/django-contact-form This application provides extensible contact-form functionality for `Django `_ sites. Full documentation for all functionality is included and is also `available online `_.django-contact-form-1.4.2/contact_form/000077500000000000000000000000001312413646300200335ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/__init__.py000066400000000000000000000000001312413646300221320ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/akismet_urls.py000066400000000000000000000012361312413646300231110ustar00rootroot00000000000000""" Example URLConf for a contact form with Akismet spam filtering. If all you want is the basic contact-form plus spam filtering, include this URLConf somewhere in your URL hierarchy (for example, at ``/contact/``). """ from django.conf.urls import url from django.views.generic import TemplateView from .forms import AkismetContactForm from .views import ContactFormView urlpatterns = [ url(r'^$', ContactFormView.as_view( form_class=AkismetContactForm), name='contact_form'), url(r'^sent/$', TemplateView.as_view( template_name='contact_form/contact_form_sent.html'), name='contact_form_sent'), ] django-contact-form-1.4.2/contact_form/forms.py000066400000000000000000000135311312413646300215360ustar00rootroot00000000000000""" A base contact form for allowing users to send email messages through a web interface. """ import os from django import forms from django.conf import settings from django.contrib.sites.shortcuts import get_current_site from django.utils.translation import ugettext_lazy as _ from django.core.mail import send_mail from django.template import loader class ContactForm(forms.Form): """ The base contact form class from which all contact form classes should inherit. """ name = forms.CharField(max_length=100, label=_(u'Your name')) email = forms.EmailField(max_length=200, label=_(u'Your email address')) body = forms.CharField(widget=forms.Textarea, label=_(u'Your message')) from_email = settings.DEFAULT_FROM_EMAIL recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS] subject_template_name = "contact_form/contact_form_subject.txt" template_name = 'contact_form/contact_form.txt' def __init__(self, data=None, files=None, request=None, recipient_list=None, *args, **kwargs): if request is None: raise TypeError("Keyword argument 'request' must be supplied") self.request = request if recipient_list is not None: self.recipient_list = recipient_list super(ContactForm, self).__init__(data=data, files=files, *args, **kwargs) def message(self): """ Render the body of the message to a string. """ template_name = self.template_name() if \ callable(self.template_name) \ else self.template_name return loader.render_to_string( template_name, self.get_context(), request=self.request ) def subject(self): """ Render the subject of the message to a string. """ template_name = self.subject_template_name() if \ callable(self.subject_template_name) \ else self.subject_template_name subject = loader.render_to_string( template_name, self.get_context(), request=self.request ) return ''.join(subject.splitlines()) def get_context(self): """ Return the context used to render the templates for the email subject and body. By default, this context includes: * All of the validated values in the form, as variables of the same names as their fields. * The current ``Site`` object, as the variable ``site``. * Any additional variables added by context processors (this will be a ``RequestContext``). """ if not self.is_valid(): raise ValueError( "Cannot generate Context from invalid contact form" ) return dict(self.cleaned_data, site=get_current_site(self.request)) def get_message_dict(self): """ Generate the various parts of the message and return them in a dictionary, suitable for passing directly as keyword arguments to ``django.core.mail.send_mail()``. By default, the following values are returned: * ``from_email`` * ``message`` * ``recipient_list`` * ``subject`` """ if not self.is_valid(): raise ValueError( "Message cannot be sent from invalid contact form" ) message_dict = {} for message_part in ('from_email', 'message', 'recipient_list', 'subject'): attr = getattr(self, message_part) message_dict[message_part] = attr() if callable(attr) else attr return message_dict def save(self, fail_silently=False): """ Build and send the email message. """ send_mail(fail_silently=fail_silently, **self.get_message_dict()) class AkismetContactForm(ContactForm): """ Contact form which doesn't add any extra fields, but does add an Akismet spam check to the validation routine. Requires the Python Akismet library, and two configuration parameters: an Akismet API key and the URL the key is associated with. These can be supplied either as the settings AKISMET_API_KEY and AKISMET_BLOG_URL, or the environment variables PYTHON_AKISMET_API_KEY and PYTHON_AKISMET_BLOG_URL. """ SPAM_MESSAGE = _(u"Your message was classified as spam.") def _is_unit_test(self): """ Determine if we're in a test run. During test runs, Akismet should be passed the ``is_test`` argument to ensure no effect on training corpus. django-contact-form's tox.ini will set the environment variable ``CI`` to indicate this, as will most online continuous-integration systems. """ return os.getenv('CI') == 'true' def clean_body(self): if 'body' in self.cleaned_data: from akismet import Akismet akismet_api = Akismet( key=getattr(settings, 'AKISMET_API_KEY', None), blog_url=getattr(settings, 'AKISMET_BLOG_URL', None) ) akismet_kwargs = { 'user_ip': self.request.META['REMOTE_ADDR'], 'user_agent': self.request.META.get('HTTP_USER_AGENT'), 'comment_author': self.cleaned_data.get('name'), 'comment_author_email': self.cleaned_data.get('email'), 'comment_content': self.cleaned_data['body'], 'comment_type': 'contact-form', } if self._is_unit_test(): akismet_kwargs['is_test'] = 1 if akismet_api.comment_check(**akismet_kwargs): raise forms.ValidationError( self.SPAM_MESSAGE ) return self.cleaned_data['body'] django-contact-form-1.4.2/contact_form/runtests.py000066400000000000000000000051301312413646300222730ustar00rootroot00000000000000""" A standalone test runner script, configuring the minimum settings required for django-contact-form' tests to execute. Re-use at your own risk: many Django applications will require full settings and/or templates in order to execute their tests, while django-contact-form does not. """ import os import sys # Make sure the app is (at least temporarily) on the import path. APP_DIR = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, APP_DIR) # Minimum settings required for django-contact-form to work. SETTINGS_DICT = { 'BASE_DIR': APP_DIR, 'INSTALLED_APPS': ( 'contact_form', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sites', ), 'ROOT_URLCONF': 'contact_form.tests.test_urls', 'DATABASES': { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(APP_DIR, 'db.sqlite3'), }, }, 'MIDDLEWARE_CLASSES': ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', ), 'SITE_ID': 1, 'DEFAULT_FROM_EMAIL': 'contact@example.com', 'MANAGERS': [('Manager', 'noreply@example.com')], 'TEMPLATES': [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(APP_DIR, 'tests/templates')], 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], }, }], } def run_tests(): # Making Django run this way is a two-step process. First, call # settings.configure() to give Django settings to work with: from django.conf import settings settings.configure(**SETTINGS_DICT) # Then, call django.setup() to initialize the application cache # and other bits: import django if hasattr(django, 'setup'): django.setup() # Now we instantiate a test runner... from django.test.utils import get_runner TestRunner = get_runner(settings) # And then we run tests and return the results. test_runner = TestRunner(verbosity=2, interactive=True) failures = test_runner.run_tests(['contact_form.tests']) sys.exit(bool(failures)) if __name__ == '__main__': run_tests() django-contact-form-1.4.2/contact_form/tests/000077500000000000000000000000001312413646300211755ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/tests/__init__.py000066400000000000000000000000001312413646300232740ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/tests/templates/000077500000000000000000000000001312413646300231735ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/tests/templates/contact_form/000077500000000000000000000000001312413646300256515ustar00rootroot00000000000000django-contact-form-1.4.2/contact_form/tests/templates/contact_form/contact_form.html000066400000000000000000000000131312413646300312070ustar00rootroot00000000000000{{ body }} django-contact-form-1.4.2/contact_form/tests/templates/contact_form/contact_form.txt000066400000000000000000000000121312413646300310610ustar00rootroot00000000000000{{ body }}django-contact-form-1.4.2/contact_form/tests/templates/contact_form/contact_form_sent.html000066400000000000000000000000251312413646300322430ustar00rootroot00000000000000

Message sent!

django-contact-form-1.4.2/contact_form/tests/templates/contact_form/contact_form_subject.txt000066400000000000000000000000241312413646300326030ustar00rootroot00000000000000Contact form messagedjango-contact-form-1.4.2/contact_form/tests/templates/contact_form/test_callable_template_name.html000066400000000000000000000000351312413646300342260ustar00rootroot00000000000000Callable template_name used. django-contact-form-1.4.2/contact_form/tests/test_forms.py000066400000000000000000000143001312413646300237320ustar00rootroot00000000000000import os import unittest from django.conf import settings from django.core import mail from django.test import RequestFactory, TestCase from django.utils.six import text_type from ..forms import AkismetContactForm, ContactForm class ContactFormTests(TestCase): """ Tests the base ContactForm. """ valid_data = {'name': 'Test', 'email': 'test@example.com', 'body': 'Test message'} def request(self): return RequestFactory().request() def test_request_required(self): """ Can't instantiate without an HttpRequest. """ self.assertRaises(TypeError, ContactForm) def test_valid_data_required(self): """ Can't try to build the message dict unless data is valid. """ data = {'name': 'Test', 'body': 'Test message'} form = ContactForm(request=self.request(), data=data) self.assertRaises(ValueError, form.get_message_dict) self.assertRaises(ValueError, form.get_context) def test_send(self): """ Valid form can and does in fact send email. """ form = ContactForm(request=self.request(), data=self.valid_data) self.assertTrue(form.is_valid()) form.save() self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertTrue(self.valid_data['body'] in message.body) self.assertEqual(settings.DEFAULT_FROM_EMAIL, message.from_email) self.assertEqual(form.recipient_list, message.recipients()) def test_no_sites(self): """ Sites integration works with or without installed contrib.sites. """ with self.modify_settings( INSTALLED_APPS={ 'remove': ['django.contrib.sites'], }): form = ContactForm(request=self.request(), data=self.valid_data) self.assertTrue(form.is_valid()) form.save() self.assertEqual(1, len(mail.outbox)) def test_recipient_list(self): """ Passing recipient_list when instantiating ContactForm properly overrides the list of recipients. """ recipient_list = ['recipient_list@example.com'] form = ContactForm(request=self.request(), data=self.valid_data, recipient_list=recipient_list) self.assertTrue(form.is_valid()) form.save() self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertEqual(recipient_list, message.recipients()) def test_callable_template_name(self): """ When a template_name() method is defined, it is used and preferred over a 'template_name' attribute. """ class CallableTemplateName(ContactForm): def template_name(self): return 'contact_form/test_callable_template_name.html' form = CallableTemplateName(request=self.request(), data=self.valid_data) self.assertTrue(form.is_valid()) form.save() self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertTrue('Callable template_name used.' in message.body) def test_callable_message_parts(self): """ Message parts implemented as methods are called and preferred over attributes. """ overridden_data = { 'from_email': 'override@example.com', 'message': 'Overridden message.', 'recipient_list': ['override_recpt@example.com'], 'subject': 'Overridden subject', } class CallableMessageParts(ContactForm): def from_email(self): return overridden_data['from_email'] def message(self): return overridden_data['message'] def recipient_list(self): return overridden_data['recipient_list'] def subject(self): return overridden_data['subject'] form = CallableMessageParts(request=self.request(), data=self.valid_data) self.assertTrue(form.is_valid()) self.assertEqual(overridden_data, form.get_message_dict()) @unittest.skipUnless( getattr( settings, 'AKISMET_API_KEY', os.getenv('PYTHON_AKISMET_API_KEY') ) is not None, "AkismetContactForm requires Akismet configuration" ) class AkismetContactFormTests(TestCase): """ Tests the Akismet contact form. """ def request(self): return RequestFactory().request() def test_akismet_form_test_detection(self): """ The Akismet contact form correctly detects a test environment. """ form = AkismetContactForm(request=self.request()) self.assertTrue(form._is_unit_test()) try: old_environ = os.getenv('CI') os.environ['CI'] = '' form = AkismetContactForm(request=self.request()) self.assertFalse(form._is_unit_test()) finally: if old_environ is not None: os.environ['CI'] = old_environ def test_akismet_form_spam(self): """ The Akismet contact form correctly rejects spam. """ data = {'name': 'viagra-test-123', 'email': 'email@example.com', 'body': 'This is spam.'} form = AkismetContactForm( request=self.request(), data=data ) self.assertFalse(form.is_valid()) self.assertTrue( text_type(form.SPAM_MESSAGE) in form.errors['body'] ) def test_akismet_form_ham(self): """ The Akismet contact form correctly accepts non-spam. """ data = {'name': 'Test', 'email': 'email@example.com', 'body': 'Test message.'} form = AkismetContactForm( request=self.request(), data=data ) self.assertTrue(form.is_valid()) django-contact-form-1.4.2/contact_form/tests/test_urls.py000066400000000000000000000014211312413646300235710ustar00rootroot00000000000000""" URLConf for testing django-contact-form. """ from django.conf.urls import url from django.views.generic import TemplateView from ..forms import AkismetContactForm from ..views import ContactFormView urlpatterns = [ url(r'^$', ContactFormView.as_view(), name='contact_form'), url(r'^sent/$', TemplateView.as_view( template_name='contact_form/contact_form_sent.html' ), name='contact_form_sent'), url(r'^test_recipient_list/$', ContactFormView.as_view( recipient_list=['recipient_list@example.com']), name='test_recipient_list'), url(r'^test_akismet_form/$', ContactFormView.as_view( form_class=AkismetContactForm ), name='test_akismet_form'), ] django-contact-form-1.4.2/contact_form/tests/test_views.py000066400000000000000000000105601312413646300237450ustar00rootroot00000000000000import os import unittest from django.conf import settings from django.core import mail from django.test import RequestFactory, TestCase from django.test.utils import override_settings from ..forms import ContactForm try: from django.urls import reverse except ImportError: # pragma: no cover from django.core.urlresolvers import reverse # pragma: no cover @override_settings(ROOT_URLCONF='contact_form.tests.test_urls') class ContactFormViewTests(TestCase): def test_get(self): """ HTTP GET on the form view just shows the form. """ contact_url = reverse('contact_form') response = self.client.get(contact_url) self.assertEqual(200, response.status_code) self.assertTemplateUsed(response, 'contact_form/contact_form.html') def test_send(self): """ Valid data through the view results in a successful send. """ contact_url = reverse('contact_form') data = {'name': 'Test', 'email': 'test@example.com', 'body': 'Test message'} response = self.client.post(contact_url, data=data) self.assertRedirects(response, reverse('contact_form_sent')) self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertTrue(data['body'] in message.body) self.assertEqual(settings.DEFAULT_FROM_EMAIL, message.from_email) form = ContactForm(request=RequestFactory().request) self.assertEqual(form.recipient_list, message.recipients()) def test_invalid(self): """ Invalid data doesn't work. """ contact_url = reverse('contact_form') data = {'name': 'Test', 'body': 'Test message'} response = self.client.post(contact_url, data=data) self.assertEqual(200, response.status_code) self.assertFormError(response, 'form', 'email', 'This field is required.') self.assertEqual(0, len(mail.outbox)) def test_recipient_list(self): """ Passing recipient_list when instantiating ContactFormView properly overrides the list of recipients. """ contact_url = reverse('test_recipient_list') data = {'name': 'Test', 'email': 'test@example.com', 'body': 'Test message'} response = self.client.post(contact_url, data=data) self.assertRedirects(response, reverse('contact_form_sent')) self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertEqual(['recipient_list@example.com'], message.recipients()) @unittest.skipUnless( getattr( settings, 'AKISMET_API_KEY', os.getenv('PYTHON_AKISMET_API_KEY') ) is not None, "AkismetContactForm requires Akismet configuration" ) class AkismetContactFormViewTests(TestCase): """ Tests the views with the Akismet contact form. """ def test_akismet_view_spam(self): """ The Akismet contact form errors on spam. """ contact_url = reverse('test_akismet_form') data = {'name': 'viagra-test-123', 'email': 'email@example.com', 'body': 'This is spam.'} response = self.client.post(contact_url, data=data) self.assertEqual(200, response.status_code) self.assertFalse(response.context['form'].is_valid()) self.assertTrue(response.context['form'].has_error('body')) def test_akismet_view_ham(self): contact_url = reverse('test_akismet_form') data = {'name': 'Test', 'email': 'email@example.com', 'body': 'Test message.'} response = self.client.post(contact_url, data=data) self.assertRedirects(response, reverse('contact_form_sent')) self.assertEqual(1, len(mail.outbox)) message = mail.outbox[0] self.assertEqual(['noreply@example.com'], message.recipients()) django-contact-form-1.4.2/contact_form/urls.py000066400000000000000000000010761312413646300213760ustar00rootroot00000000000000""" Example URLConf for a contact form. If all you want is the basic ContactForm with default behavior, include this URLConf somewhere in your URL hierarchy (for example, at ``/contact/``) """ from django.conf.urls import url from django.views.generic import TemplateView from contact_form.views import ContactFormView urlpatterns = [ url(r'^$', ContactFormView.as_view(), name='contact_form'), url(r'^sent/$', TemplateView.as_view( template_name='contact_form/contact_form_sent.html'), name='contact_form_sent'), ] django-contact-form-1.4.2/contact_form/views.py000066400000000000000000000026411312413646300215450ustar00rootroot00000000000000""" View which can render and send email from a contact form. """ from django.views.generic.edit import FormView from .forms import ContactForm try: from django.urls import reverse except ImportError: # pragma: no cover from django.core.urlresolvers import reverse # pragma: no cover class ContactFormView(FormView): form_class = ContactForm recipient_list = None template_name = 'contact_form/contact_form.html' def form_valid(self, form): form.save() return super(ContactFormView, self).form_valid(form) def get_form_kwargs(self): # ContactForm instances require instantiation with an # HttpRequest. kwargs = super(ContactFormView, self).get_form_kwargs() kwargs.update({'request': self.request}) # We may also have been given a recipient list when # instantiated. if self.recipient_list is not None: kwargs.update({'recipient_list': self.recipient_list}) return kwargs def get_success_url(self): # This is in a method instead of the success_url attribute # because doing it as an attribute would involve a # module-level call to reverse(), creating a circular # dependency between the URLConf (which imports this module) # and this module (which would need to access the URLConf to # make the reverse() call). return reverse('contact_form_sent') django-contact-form-1.4.2/docs/000077500000000000000000000000001312413646300163055ustar00rootroot00000000000000django-contact-form-1.4.2/docs/Makefile000066400000000000000000000127601312413646300177530ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-contact-form.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-contact-form.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/django-contact-form" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-contact-form" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." django-contact-form-1.4.2/docs/conf.py000066400000000000000000000012351312413646300176050ustar00rootroot00000000000000import os on_rtd = os.environ.get('READTHEDOCS', None) == 'True' extensions = [] templates_path = ['_templates'] source_suffix = '.rst' master_doc = 'index' project = u'django-contact-form' copyright = u'2007-2017, James Bennett' version = '1.4' release = '1.4.2' exclude_trees = ['_build'] pygments_style = 'sphinx' html_static_path = ['_static'] htmlhelp_basename = 'django-contact-formdoc' latex_documents = [ ('index', 'django-contact-form.tex', u'django-contact-form Documentation', u'James Bennett', 'manual'), ] if not on_rtd: import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] django-contact-form-1.4.2/docs/faq.rst000066400000000000000000000113761312413646300176160ustar00rootroot00000000000000.. _faq: Frequently asked questions ========================== The following notes answer some common questions, and may be useful to you when installing, configuring or using django-contact-form. What versions of Django and Python are supported? ------------------------------------------------- As of django-contact-form |release|, Django 1.8, 1.10, and 1.11 are supported, on Python 2.7, 3.3, (Django 1.8 only), 3.4, 3.5, or 3.6 (Django 1.11 only). Although Django 1.8 supported Python 3.2 at initial release, Python 3.2 is now at its end-of-life and django-contact-form no longer supports it. What license is django-contact-form under? ---------------------------------------------- django-contact-form is offered under a three-clause BSD-style license; this is `an OSI-approved open-source license `_, and allows you a large degree of freedom in modifiying and redistributing the code. For the full terms, see the file ``LICENSE`` which came with your copy of django-contact-form; if you did not receive a copy of this file, you can view it online at . Why aren't there any default templates I can use? ------------------------------------------------- Usable default templates, for an application designed to be widely reused, are essentially impossible to produce; variations in site design, block structure, etc. cannot be reliably accounted for. As such, django-contact-form provides bare-bones (i.e., containing no HTML structure whatsoever) templates in its source distribution to enable running tests, and otherwise just provides good documentation of all required templates and the context made available to them. Why am I getting a bunch of ``BadHeaderError`` exceptions? ---------------------------------------------------------- Most likely, you have an error in your :class:`~contact_form.forms.ContactForm` subclass. Specifically, one or more of :attr:`~contact_form.forms.ContactForm.from_email`, :attr:`~contact_form.forms.ContactForm.recipient_list` or :meth:`~contact_form.forms.ContactForm.subject` are returning values which contain newlines. As a security precaution against email header injection attacks (which allow spammers and other malicious users to manipulate email and potentially cause automated systems to send mail to unintended recipients), `Django's email-sending framework does not permit newlines in message headers `_. ``BadHeaderError`` is the exception Django raises when a newline is detected in a header. Note that this only applies to the headers of an email message; the message body can (and usually does) contain newlines. I found a bug or want to make an improvement! --------------------------------------------- The canonical development repository for django-contact-form is online at . Issues and pull requests can both be filed there. If you'd like to contribute to django-contact-form, that's great! Just please remember that pull requests should include tests and documentation for any changes made, and that following `PEP 8 `_ is mandatory. Pull requests without documentation won't be merged, and PEP 8 style violations or test coverage below 100% are both configured to break the build. I'm getting errors about "akismet" when trying to run tests? ------------------------------------------------------------ The full test suite of django-contact-form exercises all of its functionality, including the spam-filtering :class:`~contact_forms.forms.AkismetContactForm`. That class uses `the Wordpress Akismet spam-detection service `_ to perform spam filtering, and so requires the Python ``akismet`` module to communicate with the Akismet service, and some additional configuration (in the form of a valid Akismet API key and associated URL). By default, the tests for :class:`~contact_forms.forms.AkismetContactForm` will be skipped unless the required configuration (in the form of either a pair of Django settings, or a pair of environment variables) is detected. However, if you have supplied Akismet configuration but do *not* have the Python ``akismet`` module, you will see test errors from attempts to import ``akismet``. You can resolve this by running:: pip install akismet or (if you do not intend to use :class:`~contact_forms.forms.AkismetContactForm`) by no longer configuring the Django settings/environment variables used by Akismet. Additionally, if the :class:`~contact_forms.forms.AkismetContactForm` tests are skipped, the default code-coverage report will fail due to the relevant code not being exercised during the test run.django-contact-form-1.4.2/docs/forms.rst000066400000000000000000000202261312413646300201670ustar00rootroot00000000000000.. _forms: .. module:: contact_form.forms Contact form classes ==================== There are two contact-form classes included in django-contact-form; one provides all the infrastructure for a contact form, and will usually be the base class for subclasses which want to extend or modify functionality. The other is a subclass which adds spam filtering to the contact form. The ContactForm class --------------------- .. class:: ContactForm The base contact form class from which all contact form classes should inherit. If you don't need any customization, you can use this form to provide basic contact-form functionality; it will collect name, email address and message. The :class:`~contact_form.views.ContactFormView` included in this application knows how to work with this form and can handle many types of subclasses as well (see below for a discussion of the important points), so in many cases it will be all that you need. If you'd like to use this form or a subclass of it from one of your own views, here's how: 1. When you instantiate the form, pass the current ``HttpRequest`` object as the keyword argument ``request``; this is used internally by the base implementation, and also made available so that subclasses can add functionality which relies on inspecting the request (such as spam filtering). 2. To send the message, call the form's ``save`` method, which accepts the keyword argument ``fail_silently`` and defaults it to ``False``. This argument is passed directly to Django's ``send_mail()`` function, and allows you to suppress or raise exceptions as needed for debugging. The ``save`` method has no return value. Other than that, treat it like any other form; validity checks and validated data are handled normally, through the ``is_valid()`` method and the ``cleaned_data`` dictionary. Under the hood, this form uses a somewhat abstracted interface in order to make it easier to subclass and add functionality. The following attributes play a role in determining behavior, and any of them can be implemented as an attribute or as a method (for example, if you wish to have ``from_email`` be dynamic, you can implement a method named ``from_email()`` instead of setting the attribute ``from_email``): .. attribute:: from_email The email address to use in the ``From:`` header of the message. By default, this is the value of the setting ``DEFAULT_FROM_EMAIL``. .. attribute:: recipient_list The list of recipients for the message. By default, this is the email addresses specified in the setting ``MANAGERS``. .. attribute:: subject_template_name The name of the template to use when rendering the subject line of the message. By default, this is ``contact_form/contact_form_subject.txt``. .. attribute:: template_name The name of the template to use when rendering the body of the message. By default, this is ``contact_form/contact_form.txt``. And two methods are involved in producing the contents of the message to send: .. method:: message() Returns the body of the message to send. By default, this is accomplished by rendering the template name specified in :attr:`template_name`. .. method:: subject() Returns the subject line of the message to send. By default, this is accomplished by rendering the template name specified in :attr:`subject_template_name`. Finally, the message itself is generated by the following two methods: .. method:: get_message_dict() This method loops through :attr:`from_email`, :attr:`recipient_list`, :meth:`message` and :meth:`subject`, collecting those parts into a dictionary with keys corresponding to the arguments to Django's ``send_mail`` function, then returns the dictionary. Overriding this allows essentially unlimited customization of how the message is generated. Note that for compatibility, implementations which override this should support callables for the values of ``from_email`` and ``recipient_list``. .. method:: get_context() For methods which render portions of the message using templates (by default, :meth:`message` and :meth:`subject`), generates the context used by those templates. The default context will be a ``RequestContext`` (using the current HTTP request, so user information is available), plus the contents of the form's ``cleaned_data`` dictionary, and one additional variable: ``site`` If ``django.contrib.sites`` is installed, the currently-active ``Site`` object. Otherwise, a ``RequestSite`` object generated from the request. Meanwhile, the following attributes/methods generally should not be overridden; doing so may interfere with functionality, may not accomplish what you want, and generally any desired customization can be accomplished in a more straightforward way through overriding one of the attributes/methods listed above. .. attribute:: request The ``HttpRequest`` object representing the current request. This is set automatically in ``__init__()``, and is used both to generate a ``RequestContext`` for the templates and to allow subclasses to engage in request-specific behavior. .. method:: save If the form has data and is valid, will send the email, by calling :meth:`get_message_dict` and passing the result to Django's ``send_mail`` function. Note that subclasses which override ``__init__`` or :meth:`save` need to accept ``*args`` and ``**kwargs``, and pass them via ``super``, in order to preserve behavior (each of those methods accepts at least one additional argument, and this application expects and requires them to do so). The Akismet (spam-filtering) contact form class ----------------------------------------------- .. class:: AkismetContactForm A subclass of :class:`ContactForm` which adds spam filtering, via `the Wordpress Akismet spam-detection service `_. Use of this class requires you to provide configuration for the Akismet web service; you'll need to obtain an Akismet API key, and you'll need to associate it with the site you'll use the contact form on. You can do this at . Once you have, you can configure in either of two ways: 1. Put your Akismet API key in the Django setting ``AKISMET_API_KEY``, and the URL it's associated with in the setting ``AKISMET_BLOG_URL``, or 2. Put your Akismet API key in the environment variable ``PYTHON_AKISMET_API_KEY``, and the URL it's associated with in the environment variable ``PYTHON_AKISMET_BLOG_URL``. You will also need `the Python Akismet module `_ to communicate with the Akismet web service. You can install it by running ``pip install akismet``, or django-contact-form can install it automatically for you if you run ``pip install django-contact-form[akismet]``. Once you have an Akismet API key and URL configured, and the ``akismet`` module installed, you can drop in ``AkismetContactForm`` anywhere you would have used :class:`ContactForm`. For example, you could define a view (subclassing :class:`~contact_form.views.ContactFormView`) like so, and then point a URL at it: .. code-block:: python from contact_form.forms import AkismetContactForm from contact_form.views import ContactFormView class AkismetContactFormView(ContactFormView): form_class = AkismetContactForm Or directly specify the form in your URLconf: .. code-block:: python from django.conf.urls import url from contact_form.forms import AkismetContactForm from contact_form.views import ContactFormView urlpatterns = [ # other URL patterns... url(r'^contact-form/$', ContactForm.as_view( form_class=AkismetContactForm ), name='contact_form'), ] django-contact-form-1.4.2/docs/index.rst000066400000000000000000000015211312413646300201450ustar00rootroot00000000000000django-contact-form |release| ============================= django-contact-form provides customizable contact-form functionality for `Django `_-powered Web sites. Basic functionality (collecting a name, email address and message) can be achieved out of the box by setting up a few templates and adding one line to your site's root URLconf: .. code-block:: python url(r'^contact/', include('contact_form.urls')), For notes on getting started quickly, and on how to customize django-contact-form's behavior, read through the full documentation below. Contents: .. toctree:: :caption: Installation and configuration :maxdepth: 1 install quickstart .. toctree:: :caption: For developers :maxdepth: 1 forms views .. toctree:: :caption: Other documentation :maxdepth: 1 faqdjango-contact-form-1.4.2/docs/install.rst000066400000000000000000000052701312413646300205110ustar00rootroot00000000000000.. _install: Installation guide ================== Before installing django-contact-form, you'll need to have a copy of `Django `_ already installed. For information on obtaining and installing Django, consult the `Django download page `_, which offers convenient packaged downloads and installation instructions. The |release| release of django-contact-form supports Django 1.8, 1.10, and 1.11 on the following Python versions (matching the versions supported by Django itself): * Django 1.8 supports Python 2.7, 3.3, 3.4, and 3.5. * Django 1.10 supports Python 2.7, 3.4, and 3.5. * Django 1.11 supports Python 2.7, 3.4, 3.5, and 3.6 .. important:: **Python 3.2** Although Django 1.8 supported Python 3.2 at the time of its release, the Python 3.2 series has reached end-of-life, and as a result support for Python 3.2 has been dropped from django-contact-form. Normal installation ------------------- The preferred method of installing django-contact-form is via ``pip``, the standard Python package-installation tool. If you don't have ``pip``, instructions are available for `how to obtain and install it `_. If you're using Python 2.7.9 or later (for Python 2) or Python 3.4 or later (for Python 3), ``pip`` came bundled with your installation of Python. Once you have ``pip``, type:: pip install django-contact-form If you plan to use the included spam-filtering contact form class, :class:`~contact_form.forms.AkismetContactForm`, you will also need the Python ``akismet`` module. You can manually install it via ``pip install akismet``, or tell ``django-contact-form`` to install it for you, by running:: pip install django-contact-form[akismet] Installing from a source checkout --------------------------------- If you want to work on django-contact-form, you can obtain a source checkout. The development repository for django-contact-form is at . If you have `git `_ installed, you can obtain a copy of the repository by typing:: git clone https://github.com/ubernostrum/django-contact-form.git From there, you can use normal git commands to check out the specific revision you want, and install it using ``pip install -e .`` (the ``-e`` flag specifies an "editable" install, allowing you to change code as you work on django-contact-form, and have your changes picked up automatically). Configuration and use --------------------- Once you have Django and django-contact-form installed, check out :ref:`the quick start guide ` to see how to get your contact form up and running.django-contact-form-1.4.2/docs/make.bat000066400000000000000000000120021312413646300177050ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-contact-form.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-contact-form.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) :end django-contact-form-1.4.2/docs/quickstart.rst000066400000000000000000000123131312413646300212310ustar00rootroot00000000000000.. _quickstart: Quick start guide ================= First you'll need to have Django and django-contact-form installed; for details on that, see :ref:`the installation guide `. Once that's done, you can start setting up django-contact-form. Since it doesn't provide any database models or use any other application-config mechanisms, you do *not* need to add django-contact-form to your ``INSTALLED_APPS`` setting; you can begin using it right away. URL configuration ----------------- The quicket way to set up the views in django-contact-form is to use the provided URLconf, found at ``contact_form.urls``. You can include it wherever you like in your site's URL configuration; for example, to have it live at the URL ``/contact/``: .. code-block:: python from django.conf.urls import include, url urlpatterns = [ # ... other URL patterns for your site ... url(r'^contact/', include('contact_form.urls')), ] If you'll be using a custom form class, you'll need to manually set up your URLs so you can tell django-contact-form about your form class. For example: .. code-block:: python from django.conf.urls import include, url from django.views.generic import TemplateView from contact_form.views import ContactFormView from yourapp.forms import YourCustomFormClass urlpatterns = [ # ... other URL patterns for your site ... url(r'^contact/$', ContactFormView.as_view( form_class=YourCustomFormClass ), name='contact_form'), url(r'^contact/sent/$', TemplateView.as_view( template_name='contact_form/contact_form_sent.html' ), name='contact_form_sent'), ] .. important:: **Where to put custom forms and views** When writing a custom form class (or custom ``ContactFormView`` subclass), **don't** put your custom code inside django-contact-form. Instead, put your custom code in the appropriate place (a ``forms.py`` or ``views.py`` file) in an application you've written. Required templates ------------------ The two views above will need two templates to be created: ``contact_form/contact_form.html`` This is used to display the contact form. It has a ``RequestContext`` (so any context processors will be applied), and also provides the form instance as the context variable ``form``. ``contact_form/contact_form_sent.html`` This is used after a successful form submission, to let the user know their message has been sent. It has a ``RequestContext``, but provides no additional context variables of its own. You'll also need to create at least two more templates to handle the rendering of the message: ``contact_form/contact_form_subject.txt`` for the subject line of the email to send, and ``contact_form/contact_form.txt`` for the body (note that the file extension for these is ``.txt``, not ``.html``!). Both of these will receive a ``RequestContext`` with a set of variables named for the fields of the form (by default: ``name``, ``email`` and ``body``), as well as one more variable: ``site``, representing the current site (either a ``Site`` or ``RequestSite`` instance, depending on whether `Django's sites framework `_ is installed). .. warning:: **Subject must be a single line** In order to prevent `header injection attacks `_, the subject *must* be only a single line of text, and Django's email framework will reject any attempt to send an email with a multi-line subject. So it's a good idea to ensure your ``contact_form_subject.txt`` template only produces a single line of output when rendered; as a precaution, however, django-contact-form will split the output of this template at line breaks, then forcibly re-join it into a single line of text. Using a spam-filtering contact form ----------------------------------- Spam filtering is a common desire for contact forms, due to the large amount of spam they can attract. There is a spam-filtering contact form class included in django-contact-form: :class:`~contact_forms.forms.AkismetContactForm`, which uses `the Wordpress Akismet spam-detection service `_. To use this form, you will need to do the following things: 1. Install the Python ``akismet`` module to allow django-contact-form to communicate with the Akismet service. You can do this via ``pip install akismet``, or as you install django-contact-form via ``pip install django-contact-form[akismet]``. 2. Obtain an Akismet API key from , and associate it with the URL of your site. 3. Supply the API key and URL for django-contact-form to use. You can either place them in the Django settings ``AKISMET_API_KEY`` and ``AKISMET_BLOG_URL``, or in the environment variables ``PYTHON_AKISMET_API_KEY`` and ``PYTHON_AKISMET_BLOG_URL``. Then you can replace the suggested URLconf above with the following: .. code-block:: python from django.conf.urls import include, url urlpatterns = [ # ... other URL patterns for your site ... url(r'^contact/', include('contact_form.akismet_urls')), ] django-contact-form-1.4.2/docs/views.rst000066400000000000000000000054731312413646300202050ustar00rootroot00000000000000.. _views: .. module:: contact_form.views Built-in views ============== .. class:: ContactFormView The base view class from which most custom contact-form views should inherit. If you don't need any custom functionality, and are content with the default :class:`~contact_form.forms.ContactForm` class, you can also use it as-is (and the provided URLConf, ``contact_form.urls``, does exactly this). This is a subclass of `Django's FormView `_, so refer to the Django documentation for a list of attributes/methods which can be overridden to customize behavior. One non-standard attribute is defined here: .. attribute:: recipient_list The list of email addresses to send mail to. If not specified, defaults to the :attr:`~contact_form.forms.ContactForm.recipient_list` of the form. Additionally, the following standard (from ``FormView``) methods and attributes are commonly useful to override (all attributes below can also be passed to ``as_view()`` in the URLconf, permitting customization without the need to write a full custom subclass of ``ContactFormView``): .. attribute:: form_class The form class to use. By default, will be :class:`~contact_form.forms.ContactForm`. This can also be overridden as a method named ``form_class()``; this permits, for example, per-request customization (by inspecting attributes of ``self.request``). .. attribute:: template_name The template to use when rendering the form. By default, will be ``contact_form/contact_form.html``. .. method:: get_success_url() The URL to redirect to after successful form submission. By default, this is the named URL ``contact_form.sent``. In the default URLconf provided with django-contact-form, that URL is mapped to ``TemplateView`` rendering the template ``contact_form/contact_form_sent.html``. .. method:: get_form_kwargs() Returns additional keyword arguments (as a dictionary) to pass to the form class on initialization. By default, this will return a dictionary containing the current ``HttpRequest`` (as the key ``request``) and, if :attr:`~ContactFormView.recipient_list` was defined, its value (as the key ``recipient_list``). .. warning:: If you override ``get_form_kwargs()``, you **must** ensure that, at the very least, the keyword argument ``request`` is still provided, or ``ContactForm`` initialization will raise ``TypeError``. The easiest approach is to use ``super()`` to call the base implementation in ``ContactFormView``, and modify the dictionary it returns. django-contact-form-1.4.2/setup.cfg000066400000000000000000000004031312413646300171730ustar00rootroot00000000000000[wheel] universal = 1 [coverage:run] include = contact_form/* omit = contact_form/tests/* [coverage:report] fail_under = 100 omit = contact_form/runtests.py [flake8] exclude = __pycache__,.pyc,templates max-complexity = 10 [isort] lines_after_imports = 2 django-contact-form-1.4.2/setup.py000066400000000000000000000031541312413646300170720ustar00rootroot00000000000000import os from setuptools import setup setup(name='django-contact-form', version='1.4.2', zip_safe=False, # eggs are the devil. description='A generic contact-form application for Django', long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(), author='James Bennett', author_email='james@b-list.org', url='https://github.com/ubernostrum/django-contact-form/', packages=['contact_form', 'contact_form.tests'], test_suite='contact_form.runtests.run_tests', classifiers=['Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', 'Framework :: Django :: 1.8', 'Framework :: Django :: 1.10', 'Framework :: Django :: 1.11', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Topic :: Utilities'], extras_require={ 'akismet': ['akismet'], }, ) django-contact-form-1.4.2/test_requirements.txt000066400000000000000000000000271312413646300216770ustar00rootroot00000000000000coverage flake8 akismetdjango-contact-form-1.4.2/tox.ini000066400000000000000000000016341312413646300166740ustar00rootroot00000000000000# Tox (https://tox.readthedocs.io/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] envlist = {py27}-django{18,110,111} {py33}-django{18} {py34,py35}-django{18,110,111} {py36}-django{111} docs [testenv:docs] basepython = python changedir = docs deps = sphinx sphinx_rtd_theme commands= sphinx-build -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [testenv] commands = coverage run setup.py test coverage report -m flake8 contact_form deps = -rtest_requirements.txt django18: Django>=1.8,<1.9 django110: Django>=1.10,<1.11 django111: Django>=1.11 passenv = PYTHON_AKISMET_API_KEY PYTHON_AKISMET_BLOG_URL setenv = CI=true [travis] python = 2.7: py27 3.3: py33 3.4: py34 3.5: py35 3.6: py36, docs