Esempio n. 1
0
def get_chapters(book=None):
    which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')
    if book:
        book_data = get_book_details(book, False)
        if book_data['count']:
            book_data['results']['chapters'] = {}
            bible_schema = set_schema(only_columns=('chapter_id', 'chapter_id', 'verse_id'), many=True)
            if which_rule == "get_chapters/<book>/verses":
                data = Bible.query.with_entities(func.count(Bible.verse_id).label('verse_id'), Bible.chapter_id).filter(Bible.book_id==book_data['results']['book_id']).group_by(Bible.chapter_id).all()
                results = bible_schema.dump(data)
                book_data['results']['chapters']['count'] = len(results.data)
                book_data['results']['verses'] = {}
                book_data['results']['verses']['by_chapter'] = results.data

                total_verse_count = 0
                for line in results.data:
                    total_verse_count += int(line['verse_id'])

                book_data['results']['verses']['count'] = total_verse_count
                book_data['message'] += ', with chapter count and details'
            else:
                data = Bible.query.with_entities(Bible.chapter_id).filter(Bible.book_id==book_data['results']['book_id']).group_by(Bible.chapter_id).count()
                book_data['results']['chapters']['count'] = data
                book_data['message'] += ', with chapter count'

        return tools.jsonize(book_data)
    else:
        return tools.makeResponse(results=None, errors=True, message='Incomplete command: ' + which_rule)
Esempio n. 2
0
def get_books_and_sections(section=None):
    bible_schema = set_schema(only_columns=('book_id', 'book_abbr',
                                            'book_name', 'section'),
                              many=True)
    data = None
    message = 'Books'
    if section:
        if section == 'OT' or section == 'NT':
            data = Bible.query.with_entities(
                Bible.book_id, Bible.book_abbr, Bible.book_name,
                Bible.section).filter_by(section=section).group_by(
                    Bible.book_id).order_by(Bible.book_id).all()
            message += ': ' + section

    if not data:
        data = Bible.query.with_entities(
            Bible.book_id, Bible.book_abbr, Bible.book_name,
            Bible.section).group_by(Bible.book_id).order_by(
                Bible.book_id).all()
        which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')

        if which_rule == 'get_section/':
            message += ': No section selected, listing all'
        else:
            message += ': All'

    results = bible_schema.dump(data)

    return tools.makeResponse(results=results.data,
                              errors=results.errors,
                              message=message)
Esempio n. 3
0
def get_books_and_sections(section=None):
    bible_schema = set_schema(only_columns=('book_id', 'book_abbr', 'book_name', 'section'), many=True)
    data = None
    message = 'Books'
    if section:
        if section == 'OT' or section == 'NT':
            data = Bible.query.with_entities(Bible.book_id, Bible.book_abbr, Bible.book_name, Bible.section).filter_by(section=section).group_by(Bible.book_id).order_by(Bible.book_id).all()
            message += ': ' + section

    if not data:
        data = Bible.query.with_entities(Bible.book_id, Bible.book_abbr, Bible.book_name, Bible.section).group_by(Bible.book_id).order_by(Bible.book_id).all()
        which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')

        if which_rule == 'get_section/':
            message += ': No section selected, listing all'
        else:
            message += ': All'

    results = bible_schema.dump(data)

    return tools.makeResponse(results=results.data, errors=results.errors, message=message)