kopia lustrzana https://github.com/rtts/django-simplecms
Porównaj commity
4 Commity
80133f8aa1
...
9588d7ac72
Autor | SHA1 | Data |
---|---|---|
Jaap Joris Vens | 9588d7ac72 | |
Jaap Joris Vens | 1fda2f40c1 | |
Jaap Joris Vens | 347ee7ac3b | |
Jaap Joris Vens | ac49478bbb |
|
@ -1,28 +1,28 @@
|
|||
repos:
|
||||
|
||||
- repo: https://github.com/rtts/djhtml
|
||||
rev: v1.4.11
|
||||
rev: v1.5.2
|
||||
hooks:
|
||||
- id: djhtml
|
||||
|
||||
- repo: https://github.com/myint/autoflake
|
||||
rev: v1.4
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: autoflake
|
||||
args: ['--in-place', '--remove-all-unused-imports']
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.10.1
|
||||
rev: 5.11.4
|
||||
hooks:
|
||||
- id: isort
|
||||
args: ['--resolve-all-configs', '--line-length', '88']
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 21.12b0
|
||||
rev: 22.12.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: 4.0.1
|
||||
rev: 6.0.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = "1.0.7"
|
||||
__version__ = "1.1.0"
|
||||
default_app_config = "cms.apps.CmsConfig"
|
||||
|
|
34
cms/forms.py
34
cms/forms.py
|
@ -1,6 +1,7 @@
|
|||
from urllib.parse import quote
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.mail import EmailMessage
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from . import registry
|
||||
|
@ -112,24 +113,19 @@ class SectionForm(forms.ModelForm):
|
|||
|
||||
|
||||
class ContactForm(forms.Form):
|
||||
sender = forms.EmailField(label=_("Your email address"))
|
||||
spam_protection = forms.CharField(label=_("Your message"), widget=forms.Textarea())
|
||||
message = forms.CharField(
|
||||
label=_("Your message"), widget=forms.Textarea(), initial="Hi there!"
|
||||
"""
|
||||
Spam-resistant contact form.
|
||||
"""
|
||||
|
||||
body = forms.CharField(
|
||||
label=_("Your message"), widget=forms.Textarea(), required=False
|
||||
)
|
||||
|
||||
def save(self):
|
||||
body = self.cleaned_data.get("spam_protection")
|
||||
if len(body.split()) < 7:
|
||||
return
|
||||
spamcheck = self.cleaned_data.get("message")
|
||||
if spamcheck != "Hi there!":
|
||||
return
|
||||
def save(self, address):
|
||||
"""
|
||||
Return a mailto: link.
|
||||
"""
|
||||
|
||||
email = EmailMessage(
|
||||
to=settings.DEFAULT_TO_EMAIL,
|
||||
body=body,
|
||||
subject=_("Contact form"),
|
||||
headers={"Reply-To": self.cleaned_data.get("sender")},
|
||||
)
|
||||
email.send()
|
||||
subject = quote(settings.CONTACT_FORM_EMAIL_SUBJECT, safe="")
|
||||
body = quote(self.cleaned_data.get("body"), safe="")
|
||||
return f"mailto:{address}?subject={subject}&body={body}"
|
||||
|
|
|
@ -107,6 +107,7 @@ class PageView(detail.DetailView):
|
|||
view = registry.get_view(section, request)
|
||||
form = view.get_form(method="post")
|
||||
if form.is_valid():
|
||||
view.object = section
|
||||
return view.form_valid(form)
|
||||
section.invalid_form = form
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ PROJECT_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
|||
|
||||
DEBUG = "runserver" in sys.argv
|
||||
KEYFILE = f"/tmp/{PROJECT_NAME}.secret"
|
||||
ADMINS = [("JJ Vens", "jj@rtts.eu")]
|
||||
ADMINS = [("Jaap Joris Vens", "jj@rtts.eu")]
|
||||
DEFAULT_FROM_EMAIL = "noreply@rtts.eu"
|
||||
DEFAULT_TO_EMAIL = ["jj@rtts.eu"]
|
||||
CONTACT_FORM_EMAIL_SUBJECT = "Contact form"
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
ROOT_URLCONF = PROJECT_NAME + ".urls"
|
||||
WSGI_APPLICATION = PROJECT_NAME + ".wsgi.application"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load i18n cms %}
|
||||
<section class="contact">
|
||||
|
||||
<section class="contact" id="{{section.title|slugify}}">
|
||||
<div class="wrapper">
|
||||
<div class="title">
|
||||
<h1>{{section.title}}</h1>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load thumbnail i18n cms %}
|
||||
|
||||
<section class="images">
|
||||
<section class="images" id="{{section.title|slugify}}">
|
||||
<div class="images">
|
||||
{% for image in section.images.all %}
|
||||
<div class="image">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load i18n cms %}
|
||||
|
||||
<section class="text">
|
||||
<section class="text" id="{{section.title|slugify}}">
|
||||
<div class="wrapper">
|
||||
<div class="title">
|
||||
<h1>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load embed_video_tags i18n cms %}
|
||||
|
||||
<section class="video">
|
||||
<section class="video" id="{{section.title|slugify}}">
|
||||
{% if section.video %}
|
||||
<div class="video">
|
||||
<div class="iframe">
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from cms.decorators import section_view
|
||||
from cms.forms import ContactForm
|
||||
from cms.views import SectionFormView, SectionView
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
|
@ -28,7 +29,11 @@ class Video(SectionView):
|
|||
@section_view
|
||||
class Contact(SectionFormView):
|
||||
verbose_name = _("Contact")
|
||||
fields = []
|
||||
fields = ["content", "href"]
|
||||
form_class = ContactForm
|
||||
success_url = "/thanks/"
|
||||
template_name = "contact.html"
|
||||
|
||||
def form_valid(self, form):
|
||||
response = HttpResponse(status=302)
|
||||
response["Location"] = form.save(self.object.href)
|
||||
return response
|
||||
|
|
Ładowanie…
Reference in New Issue