rendered paste body# Imports
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from biblewiz.bible.models import Scripture
from biblewiz.bible.models import Book
from biblewiz.bible.models import Translation
from django.shortcuts import render_to_response
import re, string
##################
# Home Page View #
##################
def index(request):
translation = Translation.objects.all()
return render_to_response('forms.html', {'translation_list': translation})
##########################
# Scripture Lookup Views #
##########################
def display_verse(request, translation, book, chapter, verse):
book = string.replace(book, '-', ' ')
try:
scripture = Scripture.objects.select_related().get(translation__acronym=translation, book__english=book, chapter=chapter, verse=verse)
except Scripture.DoesNotExist:
return HttpResponse('invalid scripture lookup')
else:
return render_to_response('verse_single.html', {'scripture': scripture})
def display_verse_range(request, translation, book, chapter, start_verse, end_verse):
book = string.replace(book, '-', ' ')
scripture = Scripture.objects.select_related().filter(translation__acronym=translation,chapter=chapter, book__english=book,verse__range=(start_verse, end_verse))
if scripture:
return render_to_response('verse_range.html', {'scripture_list': scripture})
else:
return HttpResponse('invalid scripture lookup')
def display_chapter(request, translation, book, chapter):
book = string.replace(book, '-', ' ')
scripture = Scripture.objects.select_related().filter(translation__acronym=translation, book__english=book, chapter=chapter)
if scripture:
return render_to_response('chapter.html', {'scripture_list': scripture})
else:
return HttpResponse('invalid scripture lookup')
def display_chapters(request, translation, book):
book = string.replace(book, '_', ' ')
chapters = Scripture.objects.distinct(translation__acronym=translation, book__english=book)
return render_to_response('chapter_list.html', {'chapter_list': chapters})
def display_books(request, translation):
book = Book.objects.all()
return render_to_response('books.html', {'book_list': book})
##############################################
# URL Redirector for Scripture Search String #
##############################################
def lookup(request):
result = Translation.objects.get(id=request.POST['translation'])
search_string = request.POST['scripture_text']
if re.search('^[0-9]+\s+[A-Za-z]+\s+[0-9]+:[0-9]+-[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '-' + array[1] + '/' + array[2] + '/' + array[3] + '-' + array[4]
return HttpResponseRedirect(url)
elif re.search('^[0-9]+\s[A-Za-z]+\s+[0-9]+:[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '-' + array[1] + '/' + array[2] + '/' + array[3]
return HttpResponseRedirect(url)
elif re.search('^[0-9]+\s[A-Za-z]+\s+[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '-' + array[1] + '/' + array[2] + '/'
return HttpResponseRedirect(url)
elif re.search('^[A-Za-z]+\s+[0-9]+:[0-9]+-[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '/' + array[1] + '/' + array[2] + '-' + array[3]
return HttpResponseRedirect(url)
elif re.search('^[A-Za-z]+\s+[0-9]+:[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '/' + array[1] + '/' + array[2]
return HttpResponseRedirect(url)
elif re.search('^[A-Za-z]+\s+[0-9]+$', search_string):
p = re.compile('\w+')
array = p.findall(search_string)
url = '/bible/'+ result.acronym + '/' + array[0] + '/' + array[1] + '/'
return HttpResponseRedirect(url)
else:
return HttpResponse('Incorrect Search Syntax');
########################
# Parallel Bible Views #
########################
def compare_verse(request, trans1, trans2, trans3, trans4, book, chapter, verse):
book = string.replace(book, '-', ' ')
try:
scripture1 = Scripture.objects.select_related().get(translation__acronym=trans1, book__english=book, chapter=chapter, verse=verse)
scripture2 = Scripture.objects.select_related().get(translation__acronym=trans2, book__english=book, chapter=chapter, verse=verse)
scripture3 = Scripture.objects.select_related().get(translation__acronym=trans3, book__english=book, chapter=chapter, verse=verse)
scripture4 = Scripture.objects.select_related().get(translation__acronym=trans4, book__english=book, chapter=chapter, verse=verse)
except Scripture.DoesNotExist:
return HttpResponse('invalid scripture lookup')
else:
return render_to_response('compare_verse.html', {'scripture1': scripture1, 'scripture2': scripture2, 'scripture3': scripture3, 'scripture4': scripture4 })
def compare_verse_range(request, trans1, trans2, trans3, trans4, book, chapter, start_verse, end_verse):
book = string.replace(book, '-', ' ')
scripture1 = Scripture.objects.select_related().filter(translation__acronym=trans1,chapter=chapter, book__english=book,verse__range=(start_verse, end_verse))
scripture2 = Scripture.objects.select_related().filter(translation__acronym=trans2,chapter=chapter, book__english=book,verse__range=(start_verse, end_verse))
scripture3 = Scripture.objects.select_related().filter(translation__acronym=trans3,chapter=chapter, book__english=book,verse__range=(start_verse, end_verse))
scripture4 = Scripture.objects.select_related().filter(translation__acronym=trans4,chapter=chapter, book__english=book,verse__range=(start_verse, end_verse))
table = ''
if scripture1:
for i in range(0, 2):
table += '<tr>'
table += '<td><sup>' + scripture1[i].verse #+ '</sup> ' + scripture1[i].scripture + '</tr>'
table += '<td><sup>' + scripture2[i].verse #+ '</sup> ' + scripture2[i].scripture + '</tr>'
table += '<td><sup>' + scripture3[i].verse #+ '</sup> ' + scripture3[i].scripture + '</tr>'
table += '<td><sup>' + scripture4[i].verse #+ '</sup> ' + scripture4[i].scripture + '</tr>'
table += '</tr>'
return render_to_response('compare_range.html', {'table': table })
#return render_to_response('compare_range.html', {'scripture1': scripture1, 'scripture2': scripture2, 'scripture3': scripture3, 'scripture4': scripture4 })
else:
return HttpResponse('invalid scripture lookup')
def compare_chapter(request, translation, book, chapter):
book = string.replace(book, '-', ' ')
scripture = Scripture.objects.select_related().filter(translation__acronym=translation, book__english=book, chapter=chapter)
if scripture:
return render_to_response('chapter.html', {'scripture_list': scripture})
else:
return HttpResponse('invalid scripture lookup')