forked from hugomaiavieira/Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
54 lines (42 loc) · 1.34 KB
/
views.py
File metadata and controls
54 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from django.shortcuts import render_to_response
from django.template import RequestContext
from django import forms
from django.core.mail import send_mail
from tags.models import Tag
from blog.models import Artigo
class FormContato(forms.Form):
nome = forms.CharField(max_length=50, required=True)
email = forms.EmailField(required=True)
assunto = forms.CharField(max_length=100,required=False)
mensagem = forms.Field(widget=forms.Textarea, required=True)
def enviar(self):
titulo = "[Blog do Hugo] %(assunto)s" % self.cleaned_data
origem = "contato@hugomaiavieira.com"
destino = "hugouenf@gmail.com"
texto = """
Nome: %(nome)s
E-mail: %(email)s
Mensagem:
%(mensagem)s
""" % self.cleaned_data
send_mail(
subject=titulo,
message=texto,
from_email=origem,
recipient_list=[destino],
)
def contato(request):
tags = Tag.objects.all().order_by("nome")
artigos = Artigo.objects.all()
if request.method == 'POST':
form = FormContato(request.POST)
if form.is_valid():
form.enviar()
aviso = 'Mensagem enviada com sucesso!'
else:
form = FormContato()
return render_to_response(
'contato.html',
locals(),
context_instance=RequestContext(request),
)