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
3c0b414b10
commit
7dd4f7e70a
37 changed files with 425 additions and 31 deletions
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
3
utils/admin.py
Normal file
3
utils/admin.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
utils/apps.py
Normal file
5
utils/apps.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UtilsConfig(AppConfig):
|
||||
name = 'utils'
|
||||
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()
|
||||
27
utils/migrations/0001_initial.py
Normal file
27
utils/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-04-10 17:04
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ContactMessage',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('email', models.EmailField(max_length=254)),
|
||||
('phone_number', models.CharField(max_length=200)),
|
||||
('message', models.TextField()),
|
||||
('received_date', models.DateTimeField(auto_now_add=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
utils/migrations/__init__.py
Normal file
0
utils/migrations/__init__.py
Normal file
14
utils/models.py
Normal file
14
utils/models.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class ContactMessage(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
email = models.EmailField()
|
||||
phone_number = models.CharField(max_length=200)
|
||||
message = models.TextField()
|
||||
received_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s - %s" % (self.name, self.email, self.received_date)
|
||||
25
utils/test_forms.py
Normal file
25
utils/test_forms.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from django.test import TestCase
|
||||
from .forms import ContactUsForm
|
||||
|
||||
|
||||
class ContactUsFormTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.completed_data = {
|
||||
'name': 'test',
|
||||
'email': 'test@gmail.com',
|
||||
'phone_number': '32123123123123',
|
||||
'message': 'This is a message',
|
||||
}
|
||||
|
||||
self.incompleted_data = {
|
||||
'name': 'test',
|
||||
}
|
||||
|
||||
def test_valid_form(self):
|
||||
form = ContactUsForm(data=self.completed_data)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
def test_invalid_form(self):
|
||||
form = ContactUsForm(data=self.incompleted_data)
|
||||
self.assertFalse(form.is_valid())
|
||||
3
utils/tests.py
Normal file
3
utils/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
utils/views.py
Normal file
3
utils/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Loading…
Add table
Add a link
Reference in a new issue