Moved contact form model in order to be reusable by ungleich app, Created unit test for digitalglarus contact page, Created ungleich contact page, Created unit test for ungleich contact page, Created unit test for forms .
This commit is contained in:
parent
cf0fec706c
commit
942464f6f6
37 changed files with 425 additions and 31 deletions
33
utils/forms.py
Normal file
33
utils/forms.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from django import forms
|
||||
from .models import ContactMessage
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class ContactUsForm(forms.ModelForm):
|
||||
error_css_class = 'autofocus'
|
||||
|
||||
class Meta:
|
||||
model = ContactMessage
|
||||
fields = ['name', 'email', 'phone_number', 'message']
|
||||
widgets = {
|
||||
'name': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'email': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'phone_number': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'message': forms.Textarea(attrs={'class': u'form-control'}),
|
||||
}
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'email': _('Email'),
|
||||
'phone_number': _('Phone number'),
|
||||
'message': _('Message'),
|
||||
}
|
||||
|
||||
def send_email(self):
|
||||
text_content = render_to_string('emails/contact.txt', {'data': self.cleaned_data})
|
||||
html_content = render_to_string('emails/contact.html', {'data': self.cleaned_data})
|
||||
email = EmailMultiAlternatives('Subject', text_content)
|
||||
email.attach_alternative(html_content, "text/html")
|
||||
email.to = ['info@digitalglarus.ch']
|
||||
email.send()
|
||||
Loading…
Add table
Add a link
Reference in a new issue