it/itf/erang_organised/views.py

108 lines
2.7 KiB
Python
Raw Normal View History

2010-08-01 21:50:16 +00:00
# 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
2010-11-06 21:32:55 +00:00
from django.db.models import Q
2010-12-06 22:33:00 +00:00
from ox.django.shortcuts import render_to_json_response
2010-11-10 21:40:04 +00:00
from django.core.paginator import Paginator, InvalidPage, EmptyPage
2010-11-20 14:13:49 +00:00
from django.template import RequestContext
2011-04-28 11:22:28 +00:00
from django.views.decorators.csrf import csrf_exempt
2010-08-01 21:50:16 +00:00
RESULTS_PER_PAGE = 6
2010-11-09 19:52:52 +00:00
2010-08-01 21:50:16 +00:00
def home(request):
2010-10-21 16:51:01 +00:00
all_issues = Issue.objects.all().order_by('-date')
2010-08-01 21:50:16 +00:00
if request.GET.has_key('issue_id'):
issue_id = request.GET.get('issue_id')
else:
2010-10-23 15:30:51 +00:00
# l = 0
issue_id = all_issues[0].id
2010-08-01 21:50:16 +00:00
current_issue = Issue.objects.get(pk=issue_id)
other_issues = all_issues.exclude(pk=issue_id)
2010-11-20 14:13:49 +00:00
hasCommented = request.GET.has_key('c')
2010-08-01 21:50:16 +00:00
return render_to_response("erang/home.html", {
'current_issue': current_issue,
2010-11-20 14:13:49 +00:00
'hasCommented': hasCommented
2010-11-09 19:52:52 +00:00
# 'past_issues': other_issues
2010-11-20 14:13:49 +00:00
}, context_instance=RequestContext(request))
2010-11-09 19:52:52 +00:00
def issue_list(request):
p = RESULTS_PER_PAGE
2010-11-10 21:40:04 +00:00
try:
page_no = int(request.GET.get("page", '1'))
except ValueError:
page_no = 1
2010-11-09 19:52:52 +00:00
# print start_no
search_terms = request.GET.get("search", "")
# print search_terms
if search_terms != '':
qset = search(search_terms)
else:
qset = Issue.objects.all()
2010-11-12 21:18:42 +00:00
qset = qset.order_by('-date')
2010-11-10 21:40:04 +00:00
paginator = Paginator(qset, p)
try:
results = paginator.page(page_no)
except (EmptyPage, InvalidPage):
results = paginator.page(paginator.num_pages)
2010-11-09 19:52:52 +00:00
issues = []
2010-11-10 21:40:04 +00:00
for r in results.object_list:
d = r.get_dict()
2010-11-09 19:52:52 +00:00
issues.append(d)
return render_to_json_response({
2010-11-10 21:40:04 +00:00
'hasPrev': results.has_previous(),
'hasNext': results.has_next(),
2010-11-09 19:52:52 +00:00
'issues': issues,
2010-11-10 21:40:04 +00:00
'page_no': page_no,
'search_terms': search_terms
2010-08-01 21:50:16 +00:00
})
2010-11-09 19:52:52 +00:00
2010-08-01 21:50:16 +00:00
2011-04-28 11:22:28 +00:00
@csrf_exempt
2010-08-01 21:50:16 +00:00
def subscribe(request):
email = request.POST.get("email")
url = ERANG_SUBSCRIBE_URL + email
re = urllib2.urlopen(url).read()
return HttpResponse(re)
2010-11-09 19:52:52 +00:00
def search(terms):
# terms = request.GET['search']
2010-11-06 21:32:55 +00:00
words = terms.split(" ")
qset = Issue.objects.all()
issues = []
for w in words:
qset = qset.filter(Q(title__icontains=w) | Q(summary__icontains=w))
2010-11-09 19:52:52 +00:00
return qset
'''
2010-11-06 21:32:55 +00:00
for issue in qset:
2010-11-09 19:52:52 +00:00
d = issue.get_dict()
issues.append(d)
return issues
'''
2010-08-01 21:50:16 +00:00
2010-12-19 21:53:18 +00:00
'''
2010-08-01 21:50:16 +00:00
def postfeedback(request):
p = request.POST
issue = p.get("issue")
name = p.get("name")
email = p.get("email")
2010-08-01 22:05:46 +00:00
comment = p.get("comment")
2010-08-01 21:50:16 +00:00
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'])
2010-08-01 21:50:16 +00:00
return HttpResponse("1")
2010-12-19 21:53:18 +00:00
'''