Esempio n. 1
0
def book_info_by_barcode(request, book_id):
    # return:
    # -1: no barcode matches found. (default result)
    # -2: other errors

    # barcode is the unique string assigned to the books in library

    result = None
    template = '404.html'
    context = {}

    #TODO: this one is nasty - either update the models or write a generic raw query in query.py

    try:
        context = query.get_book_info('call_number', book_id)[0]

    #todo: fix the exception part
    except Exception as e:
        template = '404.html'
        result = render(request, '404.html')
        print e

    if context:
        template = 'book_page.html'

    result = render(request, template, context)

    return result
Esempio n. 2
0
def get_book_detail(request, book_id):
    # return:
    # -1: no barcode matches found. (default result)
    # -2: other errors

    # barcode is the unique string assigned to the books in library

    result = None
    result = {}

    #TODO: this one is nasty - either update the models or write a generic raw query in query.py

    try:
        result = query.get_book_info('call_number', book_id)[0]

    #todo: fix the exception part
    except Exception as e:
        result['error'] = 400
        print e

    if 'error' in result:
        status = 400

    else:
        status = 200

    result = json.dumps(result)

    response = HttpResponse(result, content_type="application/json; charset=UTF-8", status=status)

    response['status'] = status

    response['Access-Control-Allow-Origin'] = '*'

    return response
Esempio n. 3
0
def do_search(field, keyword):
    #TODO: need to refactor the function to search fields other than those in the Readerware table
    # e.g. author(contributor), language, etc.

    # POST: json result of book search

    book_list = []
    result = {}

    print field, keyword

    if keyword:
        keyword = keyword.replace(',', ' ').replace(';', ' ').replace('+', ' ').split()

        if field == 'title':
            book_list = query.get_book_info('title', keyword)

        elif field == 'author':
            author_keywords = get_author_id_list(keyword)

            if keyword:
                for author_keyword in author_keywords:
                    for author_field in author_fields:
                        search_result = query.get_book_info(author_field, author_keyword, is_exact=True)
                        if search_result:
                            book_list += search_result

        elif field == 'isbn':
            book_list = query.get_book_info('isbn', keyword)


    if book_list:
        result['books'] = book_list

    else:
        result['error'] = 'No Book Found'


    result = json.dumps(result)

    return result
Esempio n. 4
0
def get_all_book(limit=2000):
    book_list = query.get_book_info(no_keyword=True, search_limit=limit)

    result = {}

    if book_list:
        result['books'] = book_list

    else:
        result['error'] = 'No Book Found'

    result = json.dumps(result)

    return result