kopia lustrzana https://github.com/rtts/django-simplecms
Move ContactForm back to cms package. Where should it live?
rodzic
2824d290f8
commit
fc64b876da
25
cms/forms.py
25
cms/forms.py
|
@ -1,10 +1,35 @@
|
|||
import swapper
|
||||
from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.mail import EmailMessage
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
Page = swapper.load_model('cms', 'Page')
|
||||
Section = swapper.load_model('cms', 'Section')
|
||||
|
||||
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!')
|
||||
|
||||
def save(self, request):
|
||||
hostname = request.get_host()
|
||||
body = self.cleaned_data.get('spam_protection')
|
||||
if len(body.split()) < 7:
|
||||
return
|
||||
spamcheck = self.cleaned_data.get('message')
|
||||
if spamcheck != 'Hi there!':
|
||||
return
|
||||
|
||||
email = EmailMessage(
|
||||
to = ['info@' + hostname],
|
||||
from_email = 'noreply@' + hostname,
|
||||
body = body,
|
||||
subject = _('Contact form at %(hostname)s.') % {'hostname': hostname},
|
||||
headers = {'Reply-To': self.cleaned_data.get('sender')},
|
||||
)
|
||||
email.send()
|
||||
|
||||
class PageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Page
|
||||
|
|
|
@ -61,8 +61,8 @@ class Numbered:
|
|||
class BasePage(Numbered, models.Model):
|
||||
'''Abstract base model for pages'''
|
||||
number = models.PositiveIntegerField(_('number'), blank=True)
|
||||
slug = models.SlugField(_('slug'), blank=True, unique=True)
|
||||
title = VarCharField(_('title'))
|
||||
slug = models.SlugField(_('slug'), blank=True, unique=True)
|
||||
menu = models.BooleanField(_('visible in menu'), default=True)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
from django import forms
|
||||
from django.core.mail import EmailMessage
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
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!')
|
||||
|
||||
def save(self, request):
|
||||
hostname = request.get_host()
|
||||
body = self.cleaned_data.get('spam_protection') # MUHAHA
|
||||
if len(body.split()) < 7:
|
||||
return
|
||||
email = EmailMessage(
|
||||
to = ['info@' + hostname],
|
||||
from_email = 'noreply@' + hostname,
|
||||
body = body,
|
||||
subject = _('Contact form at %(hostname)s.') % {'hostname': hostname},
|
||||
headers = {'Reply-To': self.cleaned_data.get('sender')},
|
||||
)
|
||||
email.send()
|
|
@ -1,8 +1,8 @@
|
|||
from cms.forms import ContactForm
|
||||
from cms.views import SectionView, SectionFormView
|
||||
from cms.decorators import register_view
|
||||
|
||||
from .models import *
|
||||
from .forms import ContactForm
|
||||
|
||||
@register_view(TextSection)
|
||||
class TextView(SectionView):
|
||||
|
|
Ładowanie…
Reference in New Issue