| 
									
										
										
										
											2016-04-07 00:26:50 -05:00
										 |  |  | from django import forms | 
					
						
							| 
									
										
										
										
											2016-04-10 16:12:43 -05:00
										 |  |  | from .models import ContactMessage | 
					
						
							| 
									
										
										
										
											2016-04-07 00:26:50 -05:00
										 |  |  | from django.template.loader import render_to_string | 
					
						
							|  |  |  | from django.core.mail import EmailMultiAlternatives | 
					
						
							| 
									
										
										
										
											2016-04-09 13:00:16 -05:00
										 |  |  | from django.utils.translation import ugettext_lazy as _ | 
					
						
							| 
									
										
										
										
											2016-04-07 00:26:50 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ContactUsForm(forms.ModelForm): | 
					
						
							|  |  |  |     error_css_class = 'autofocus' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class Meta: | 
					
						
							| 
									
										
										
										
											2016-04-10 16:12:43 -05:00
										 |  |  |         model = ContactMessage | 
					
						
							| 
									
										
										
										
											2016-04-07 00:26:50 -05: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 13:00:16 -05:00
										 |  |  |         labels = { | 
					
						
							|  |  |  |             'name': _('Name'), | 
					
						
							|  |  |  |             'email': _('Email'), | 
					
						
							|  |  |  |             'phone_number': _('Phone number'), | 
					
						
							|  |  |  |             'message': _('Message'), | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-04-07 00:26:50 -05: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-08 20:11:22 -05:00
										 |  |  |         email.to = ['info@digitalglarus.ch'] | 
					
						
							| 
									
										
										
										
											2016-04-07 00:26:50 -05:00
										 |  |  |         email.send() |