website / views.py

#coding:utf-8
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth.models import User
from django import forms
from google.appengine.api.mail import send_mail

class FormContato(forms.forms.Form):
    name = forms.fields.CharField(max_length=100, widget = forms.TextInput(attrs = {'class' : 'campo_contato'}))
    email = forms.fields.EmailField(required=True, widget = forms.TextInput(attrs = {'class' : 'campo_contato'}))
    assunto = forms.fields.CharField(max_length=100, widget = forms.TextInput(attrs = {'class' : 'campo_contato'}))
    mensagem = forms.fields.Field(widget = forms.Textarea(attrs = {'class' : 'campo_contato'}))
    
    def enviar(self):
        titulo = '[franciscosouza.net] %s' %(self.cleaned_data['assunto'])
        destinatario = 'francisco@franciscosouza.net'
        texto = '''
            Nome: %(name)s
            E-mail: %(email)s
            Mensagem:
            %(mensagem)s
        ''' % self.cleaned_data
        
        send_mail(
            sender=destinatario,
            to=destinatario,
            subject=titulo,
            body=texto,
        )

def bemvindo(request):
    return render_to_response('bemvindo.html', locals(), RequestContext(request, {}))

def redireciona(request):
    return HttpResponseRedirect("http://blog.franciscosouza.net")

def novo(request):
    return render_to_response('blog_model.html', locals(), RequestContext(request, {}))

def contato(request):
    if request.method == 'POST':
        form = FormContato(request.POST)
        
        if form.is_valid():
            form.enviar()
            msg = 'Obrigado pelo contato, em breve devo responder!'
            form = FormContato()
            return render_to_response('contato.html', locals(), RequestContext(request, {}))
    else:
        form = FormContato()
    return render_to_response('contato.html', locals(), RequestContext(request, {}))

def criar_admin(request):
    user = User.get_by_key_name('admin')
    if not user or user.username != 'admin' or not (user.is_active and
            user.is_staff and user.is_superuser and
            user.check_password('admin')):
        user = User(key_name='admin', username='admin',
            email='francisco@franciscosouza.net', first_name='Francisco', last_name='Souza',
            is_active=True, is_staff=True, is_superuser=True)
        user.set_password('admin')
        user.put()
        msg = 'Criei!'
    else:
        msg = user
    return render_to_response('bemvindo.html', locals(), RequestContext(request))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.