Пример #1
0
def info_book_in_template(request, isbn, record_list, template_name, app):
    book = util.get_book_info(isbn)
    borrow_statis = util.get_borrows_each_month(isbn)
    max = 0.5
    for statis in borrow_statis:
        if max < statis['borrow_times']:
            max = statis['borrow_times']
    step = int(round((max / 5 + 0.5)))
    max = step * 5
    for statis in borrow_statis:
        statis['borrow_times'] = statis['borrow_times'] * 100.0 / max
    divide = []
    i = 0
    while i <= max:
        divide.append(i)
        i += step
        
    p = request.GET.get('page', '1')
    if not p.isdigit():
        p = 1
    else:
        p = int(p)
        
    basic_info = { 'divide': divide, 'app': app, 'borrow_statis': borrow_statis, \
                    'book': book, 'isbn': isbn }
    return list_detail.object_list(
        request,
        paginate_by = Per_Page,
        page = p,
        queryset = record_list,
        template_name = template_name,
        template_object_name = 'record',
        extra_context = basic_info,
    )
Пример #2
0
def audit(request):
    app = 'book-admin'
    top_borrows = get_top_borrows_in_month()
    seq = 0
    for top in top_borrows:
        book = Book.objects.get(isbn=top['isbn'])
        top['book'] = book
        seq += 1
        top['seq'] = seq
    total_books = BookInstance.objects.exclude(state='R').count()
    total_borrowing_now = BookInstance.objects.filter(state='B').count()
    total_avaliable_now = total_books - total_borrowing_now
    borrow_statis = get_borrows_each_month()
    max = 0.5
    for statis in borrow_statis:
        if max < statis['borrow_times']:
            max = statis['borrow_times']
    step = int(round((max / 5 + 0.5)))
    max = step * 5
    for statis in borrow_statis:
        statis['borrow_times'] = statis['borrow_times'] * 100.0 / max
    divide = []
    i = 0
    while i <= max:
        divide.append(i)
        i += step
    return render_to_response('book_admin/audit.html', locals(), context_instance=RequestContext(request));