it/itf/erang_organised/views.py
2010-11-07 03:02:55 +05:30

61 lines
1.7 KiB
Python

# Create your views here.
from django.shortcuts import render_to_response
from models import Issue
from settings import ERANG_SUBSCRIBE_URL
import urllib2
from django.http import HttpResponse
from django.core.mail import send_mail
from django.db.models import Q
from oxdjango.shortcuts import render_to_json_response
def home(request):
all_issues = Issue.objects.all().order_by('-date')
if request.GET.has_key('issue_id'):
issue_id = request.GET.get('issue_id')
else:
# l = 0
issue_id = all_issues[0].id
current_issue = Issue.objects.get(pk=issue_id)
other_issues = all_issues.exclude(pk=issue_id)
return render_to_response("erang/home.html", {
'current_issue': current_issue,
'past_issues': other_issues
})
def subscribe(request):
email = request.POST.get("email")
url = ERANG_SUBSCRIBE_URL + email
re = urllib2.urlopen(url).read()
return HttpResponse(re)
def search(request):
terms = request.GET['search']
words = terms.split(" ")
qset = Issue.objects.all()
issues = []
for w in words:
qset = qset.filter(Q(title__icontains=w) | Q(summary__icontains=w))
for issue in qset:
issues.append({
'id': issue.id,
'title': issue.title,
'summary': issue.summary,
})
return render_to_json_response(issues)
def postfeedback(request):
p = request.POST
issue = p.get("issue")
name = p.get("name")
email = p.get("email")
comment = p.get("comment")
txt = """
Feedback on Issue: %s
Name: %s
Email: %s
Feedback %s
""" % (issue, name, email, comment,)
send_mail("eRang Feedback", txt, "do-not-reply@theatreforum.in", ['sanjaybhangar@gmail.com', 'erang@theatreforum.in'])
return HttpResponse("1")