コード例 #1
0
ファイル: views.py プロジェクト: bhitov/sprout-library
def search_googlex(request):
    """
    Searches google books for a book with the given barcode (isbn)
    """
    if request.method == 'POST':
        form = BookSearch(request.POST)
        barcode = form.data['barcode']
        response = google_books.search(barcode)
        print "I passed the loop"
        if request.is_ajax():
            print "I think I am ajax"
            json = simplejson.dumps(response)
            return HttpResponse(json, mimetype='application/json')
        return render(request,
                      'search.html',
                      {'book_list': response['book_list'], 'form': form, 
                       'title' :'Search Google'})
    else:
        book = Book(author='a', title='t')
        book.id = 'dummy'
        form = BookSearch()
        return render(request,
                      'search.html',
                      {'form': form, 'title' : 'Search Google',
                       'book_list' : [book]},)
コード例 #2
0
def search_googlex(request):
    """
    Searches google books for a book with the given barcode (isbn)
    """
    if request.method == 'POST':
        form = BookSearch(request.POST)
        barcode = form.data['barcode']
        response = google_books.search(barcode)
        print "I passed the loop"
        if request.is_ajax():
            print "I think I am ajax"
            json = simplejson.dumps(response)
            return HttpResponse(json, mimetype='application/json')
        return render(
            request, 'search.html', {
                'book_list': response['book_list'],
                'form': form,
                'title': 'Search Google'
            })
    else:
        book = Book(author='a', title='t')
        book.id = 'dummy'
        form = BookSearch()
        return render(
            request,
            'search.html',
            {
                'form': form,
                'title': 'Search Google',
                'book_list': [book]
            },
        )