From 94af72cca80fdc26533a192074bc18bb7b4d0ef5 Mon Sep 17 00:00:00 2001 From: Jaap Joris Vens Date: Sun, 25 Dec 2022 21:52:42 +0100 Subject: [PATCH] Merry 1.1.1 This release fine-tunes the translations and offers a ready-to-use, spam resistant contact form. Submitting the form will open the user's mail app with an email addressed to the `href` field of the section. This method, although unconventional, has been tested by my mother on several of her devices, which proofs anyone can use it. It couldn't be easier and, best of all, no more spam! \o/ --- cms/__init__.py | 2 +- cms/forms.py | 4 +--- cms/locale/nl/LC_MESSAGES/django.mo | Bin 1496 -> 1360 bytes cms/locale/nl/LC_MESSAGES/django.po | 20 ++++++-------------- cms/views.py | 20 ++++++++++++++++++-- example/views.py | 20 ++++++-------------- pyproject.toml | 2 +- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/cms/__init__.py b/cms/__init__.py index 4cabf63..5569b33 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -1,2 +1,2 @@ -__version__ = "1.1.0" +__version__ = "1.1.1" default_app_config = "cms.apps.CmsConfig" diff --git a/cms/forms.py b/cms/forms.py index 2cfccca..81e715e 100644 --- a/cms/forms.py +++ b/cms/forms.py @@ -117,9 +117,7 @@ class ContactForm(forms.Form): Spam-resistant contact form. """ - body = forms.CharField( - label=_("Your message"), widget=forms.Textarea(), required=False - ) + body = forms.CharField(label=_("Message"), widget=forms.Textarea(), required=False) def save(self, address): """ diff --git a/cms/locale/nl/LC_MESSAGES/django.mo b/cms/locale/nl/LC_MESSAGES/django.mo index 0c84fea866d47dc663aa15280b3587b4a13da0a0..1e3a3d8d5fae8bfc5f01cc8291b4f68574d6df51 100644 GIT binary patch delta 572 zcmXxhJ4?e*6u|M@G&Q#IQR@q-kK!Z+sSOdKn{{&N<|s%h!N(B6bPyE!6$%#zM<+XU z5f>*%K@fCs&_$hf@UbiYPrM#-@=NaH+|%^Iz00(oa`urT#>h$XhMXb~6WoXooWM`) zLDy2s#vD30j=ea8F3w>QeO$l|Gv7v8e~c+SLF%;BDGyS(`!}G@&4LS*4VNefT$%Y> z<2_2DM;ydwtkUE=4)E?#T^d?Osb52>w}$<=9@|oChldga`?!Q1%-{>k#y9i+gaybi+E(KUT*rd-L96 d!7Eq%vOY_`>aIQQRD-?k##U2b+ie}Cf?w2CHx>W@ delta 693 zcmYk3zb`{k6vvNxine~#kE(>UiHL-V7KtB26F){Vk!T{3(pQ?OCa-OT#bmLFya{=JtL>sYWb-i1Hoz4%!b3l{T; z1YjI?!UXifC1}AFSO?S44|A{|?!XwlFy~LOh4=-k-UqA|*^^H;H6*;%KY{_M1%f6H zLp|??d>}ng3l5m`QNszS|4YCoI18t_!~$$4KB3!2cnP)9GW1ek?%6bucrdKMA>vm! z21BU&;5<};q=`46Hd-+8F60y0H~9m@BXfRg;&Z4MxrP??N)T5aZT{Ev=4x%YKF3rmi{47#M5mymRnvx;oP;#Mv@tau zrOf2FimA0?G?RC7?t4|A8}aN$lKGMowR5TLW;B&fJ9eQU->DqC)Vl4SdanGj_~7tF uG(IvpJnqg_zXcFcjnZb;cHFqt<1Sl=or~LlGN=gQs_kUgHj3_>mH7e!#Z909 diff --git a/cms/locale/nl/LC_MESSAGES/django.po b/cms/locale/nl/LC_MESSAGES/django.po index 12f21b4..becc9bc 100644 --- a/cms/locale/nl/LC_MESSAGES/django.po +++ b/cms/locale/nl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-01-29 13:27+0100\n" -"PO-Revision-Date: 2022-01-29 13:28+0100\n" +"POT-Creation-Date: 2022-12-25 21:40+0100\n" +"PO-Revision-Date: 2022-12-25 21:41+0100\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -21,21 +21,13 @@ msgstr "" msgid "Content Management System" msgstr "Content Beheer" -#: forms.py:57 +#: forms.py:58 msgid "Delete" msgstr "Verwijderen" -#: forms.py:115 -msgid "Your email address" -msgstr "Uw email adres" - -#: forms.py:116 forms.py:118 -msgid "Your message" -msgstr "Uw bericht" - -#: forms.py:132 -msgid "Contact form" -msgstr "Contactformulier" +#: forms.py:121 +msgid "Message" +msgstr "Bericht" #: models.py:22 models.py:39 msgid "page" diff --git a/cms/views.py b/cms/views.py index 30c9082..59aaedf 100644 --- a/cms/views.py +++ b/cms/views.py @@ -1,14 +1,19 @@ import json from django.contrib.auth.mixins import UserPassesTestMixin -from django.http import Http404, HttpResponseBadRequest, HttpResponseRedirect +from django.http import ( + Http404, + HttpResponse, + HttpResponseBadRequest, + HttpResponseRedirect, +) from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.views.decorators.cache import never_cache from django.views.generic import base, detail, edit from . import registry -from .forms import PageForm, SectionForm +from .forms import ContactForm, PageForm, SectionForm class SectionView: @@ -54,6 +59,17 @@ class SectionFormView(SectionView): return form_class(**kwargs) +class ContactSectionFormView(SectionFormView): + """Contact section with bogus contact form""" + + form_class = ContactForm + + def form_valid(self, form): + response = HttpResponse(status=302) + response["Location"] = form.save(self.object.href) + return response + + class PageView(detail.DetailView): """View of a page with heterogeneous sections""" diff --git a/example/views.py b/example/views.py index d8da576..a3150da 100644 --- a/example/views.py +++ b/example/views.py @@ -1,39 +1,31 @@ from cms.decorators import section_view -from cms.forms import ContactForm -from cms.views import SectionFormView, SectionView -from django.http import HttpResponse +from cms.views import ContactSectionFormView, SectionView from django.utils.translation import gettext_lazy as _ @section_view class Text(SectionView): verbose_name = _("Text") - fields = ["content"] template_name = "text.html" + fields = ["content"] @section_view class Images(SectionView): verbose_name = _("Image(s)") - fields = ["images"] template_name = "images.html" + fields = ["images"] @section_view class Video(SectionView): verbose_name = _("Video") - fields = ["video"] template_name = "video.html" + fields = ["video"] @section_view -class Contact(SectionFormView): +class Contact(ContactSectionFormView): verbose_name = _("Contact") - fields = ["content", "href"] - form_class = ContactForm template_name = "contact.html" - - def form_valid(self, form): - response = HttpResponse(status=302) - response["Location"] = form.save(self.object.href) - return response + fields = ["content", "href"] diff --git a/pyproject.toml b/pyproject.toml index 1a17557..5d7bf33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,2 @@ [tool.isort] -line_length = 88 +profile = "black"