Ejemplo n.º 1
0
def passage_lookup(request, version, template_name=None, template_loader=loader,
        extra_context=None, context_processors=None, template_object_name='object',
        mimetype=None):
    """
    Given a textual passage via GET[q] displays the reference, or simply displays a
    passage entry form.
    
    @args::
        
        `version`: The translation to be used.
        
        GET[q]: `Romans 1:1-2:3`, or `Romans 1:1 - 1 Corinthians 2:3`, etc.
    
    """
    
    passage_reference = request.GET.get('q', False)
    if passage_reference:
        if '-' in passage_reference:
            ref = passage_reference.split('-') # Split the passage_reference into start and end verses.
            if len(ref) > 2:
                # Whoa, too many `-` characters...
                raise RangeError("We can't make sense of your chapter:verse passage reference.")
            start_verse = Verse(ref[0].strip())
            # Now the end verse. This could be in the same book, or a different book entirely.
            # eg: `Romans 1:1-2:3`, or `Romans 1:1 - 1 Corinthians 2:3`
            end_ref = ref[1].strip()
            
            # If we can't find the book reference, assume it is part of the same book.
            try:
                b = book_re.search(ref[1].strip()).group(0)
            except:
                # Assume the same book:
                end_ref = '%s ' % (bible_data()[start_verse.book]['name'], end_ref)
            
            end_verse = Verse(end_ref)
            
            
        else:
            start_verse = start_verse
            end_verse = None
    
        Scripture(start_verse=start_verse.format(), end_verse=end_verse)
    return HttpResponse
Ejemplo n.º 2
0
def find_book(book, bible=KJV):
    " Find the book reference and return the :model:`bibletext.Book` "
    try:
        # Does the text look like a book reference?
        b = book_re.search(book).group(0)
    except error:
        raise BookError("Could not find that book of the Bible: %s." % book)
        
    # Try to find the book listed as a book name or abbreviation
    bible_data = data.bible_data(bible.translation)
    b = b.rstrip('.').lower().strip()
    for i, book_data in enumerate(bible_data):
        if book_data['name'].lower() == b:
            found = i + 1
            break
        else:
            for abbr in book_data['abbrs']:
                if abbr == b:
                    found = i + 1
                    break
    try:
        return bible.bible[found]
    except:
        raise BookError("Could not find that book of the Bible: %d." % book)