2016-04-07 05:26:50 +00:00
|
|
|
from django import forms
|
2016-04-10 21:12:43 +00:00
|
|
|
from .models import ContactMessage
|
2016-04-07 05:26:50 +00:00
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.core.mail import EmailMultiAlternatives
|
2016-04-09 18:00:16 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-04-23 07:22:44 +00:00
|
|
|
from utils.fields import CountryField
|
|
|
|
|
|
|
|
|
|
|
|
class BillingAddressForm(forms.Form):
|
|
|
|
street_address = forms.CharField()
|
|
|
|
city = forms.CharField()
|
|
|
|
postal_code = forms.CharField()
|
|
|
|
country = CountryField()
|
|
|
|
token = forms.CharField(widget=forms.HiddenInput())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
labels = {
|
|
|
|
'street_address': _('Street Address'),
|
|
|
|
'city': _('City'),
|
|
|
|
'postal_code': _('Postal Code'),
|
|
|
|
'Country': _('Country'),
|
|
|
|
}
|
2016-04-07 05:26:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContactUsForm(forms.ModelForm):
|
|
|
|
error_css_class = 'autofocus'
|
|
|
|
|
|
|
|
class Meta:
|
2016-04-10 21:12:43 +00:00
|
|
|
model = ContactMessage
|
2016-04-07 05:26:50 +00:00
|
|
|
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'}),
|
|
|
|
}
|
2016-04-09 18:00:16 +00:00
|
|
|
labels = {
|
|
|
|
'name': _('Name'),
|
|
|
|
'email': _('Email'),
|
|
|
|
'phone_number': _('Phone number'),
|
|
|
|
'message': _('Message'),
|
|
|
|
}
|
2016-04-07 05:26:50 +00:00
|
|
|
|
|
|
|
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")
|
2016-04-09 01:11:22 +00:00
|
|
|
email.to = ['info@digitalglarus.ch']
|
2016-04-07 05:26:50 +00:00
|
|
|
email.send()
|