it/itf/frontpage/views.py

70 lines
2.3 KiB
Python
Raw Normal View History

2011-10-13 11:05:32 +00:00
# Create your views here.
from django.shortcuts import render_to_response
from models import *
from settings import TWITTER_ID
import twitter
from django.template import RequestContext
from django import forms
from django.forms.widgets import Textarea
2011-10-24 15:37:01 +00:00
from django.utils.html import urlize
2011-11-01 03:51:14 +00:00
from django.core.mail import send_mail
2011-10-13 11:05:32 +00:00
class ContactForm(forms.Form):
name = forms.CharField(max_length=255)
2011-10-25 21:27:35 +00:00
email = forms.EmailField()
2011-10-13 11:05:32 +00:00
message = forms.CharField(widget=Textarea(attrs={'cols': 10, 'rows': 6}))
2011-11-01 03:51:14 +00:00
def save(self, fail_silently=False):
if not self.is_valid():
raise ValueError("Sorry, invalid contact form.")
# from_email = self.cleaned_data['from_email']
email = self.cleaned_data['email']
name = self.cleaned_data['name']
message = self.cleaned_data['message']
message_body = '%s wrote: \n\n %s' % (name, message,)
recipients = ['sanjaybhangar@gmail.com', 'indiatheatreforum@gmail.com']
2011-11-01 03:51:14 +00:00
send_mail(fail_silently=fail_silently, from_email=email, message=message_body, recipient_list=recipients, subject="Contact on theatreforum.in")
2011-10-13 11:05:32 +00:00
'''
class Meta:
widgets = {
'message': Textarea(attrs={'cols': 80, 'rows': 20})
}
'''
def index(request):
try:
tApi = twitter.Api()
2011-10-24 15:37:01 +00:00
statuses = tApi.GetUserTimeline(TWITTER_ID)[0:3]
2011-10-13 11:05:32 +00:00
except:
statuses = []
boxes = SliderBox.objects.all()
2011-11-01 02:19:06 +00:00
front_images = FrontImage.objects.filter(is_active=True)[0:3]
2011-10-13 11:05:32 +00:00
return render_to_response("noel/index.html", RequestContext(request, {
2011-10-24 15:37:01 +00:00
'tweets': [urlize(s.text) for s in statuses],
2011-11-01 02:19:06 +00:00
'boxes': boxes,
'front_images': front_images
2011-10-13 11:05:32 +00:00
}))
def contact(request):
2011-11-01 03:51:14 +00:00
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid:
form.save()
errors = 0
success = True
else:
errors = form.errors
success = False
else:
form = ContactForm()
success = False
errors = []
2011-10-13 11:05:32 +00:00
# form = ContactForm()
return render_to_response("registration/contact.html", RequestContext(request, {
2011-11-01 03:51:14 +00:00
'form': ContactForm(),
'errors': errors,
'success': success
2011-10-13 11:05:32 +00:00
}))