Beispiel #1
0
def make_test_pdf(filename=_default_filename):
    dummy_order = Order(
        '1A1000', parse_date('2012-1-1'),
        Distributor('Warehouse Co.',
                    account_number='42',
                    fax='555-5543',
                    phone='416-555-9876',
                    sales_rep='Billy Jo',
                    address1='123 Fake Street',
                    city="Townville",
                    province="Mare Crisium",
                    postal_code="ABC123",
                    country="The Moon"), ShippingMethod("Rocket"),
        'Extra nonsense is free of charge!')
    paperback = Binding('Paper')
    penguin = Publisher('Penguin')
    location = ShelfLocation('Dreamspace')
    for x in xrange(10, 35):
        OrderEntry(
            dummy_order,
            Book('97811122233' + str(x), 'BOOK' + str(x), penguin, paperback,
                 location, [('Seneca', ), ('Brown', 'Dan')]), x)
    OrderEntry(
        dummy_order,
        Book('9781112223399', 'AWESOME', penguin, paperback, location,
             [('Seneca', ), ('Brown', 'Dan')]), 9)
    generate_order_pdf(dummy_order, filename)
Beispiel #2
0
def addbook(request):
    error = []
    a = []
    errorflag = True
    if "a0" in request.GET:
        a.append(request.GET["a0"])
    if "a1" in request.GET:
        a.append(request.GET["a1"])
    if "a2" in request.GET:
        a.append(request.GET["a2"])
    if "a3" in request.GET:
        a.append(request.GET["a3"])
    if "a4" in request.GET:
        a.append(request.GET["a4"])
    if "a5" in request.GET:
        a.append(request.GET["a5"])
    for i in range(0, len(a)):
        if not a[i]:
            errorflag = False
    judge = Author.objects.filter(AuthorID__icontains=a[2])
    if judge and errorflag:
        newbook = Book(ISBN=a[0], Title=a[1], AuthorID=judge[0], Publisher=a[3], PublishDate=a[4], Price=a[5])
        newbook.save()
        return render_to_response("success.html")
    elif not judge:
        return render_to_response("addauthorconfirm.html", {"AuthorID": a[2]})
    else:
        error.append("信息不完善哦")
    return render_to_response("add.html", {"error": error})
Beispiel #3
0
def insert(request):
    if request.method == 'POST':
        book = BookForm(request.POST)
        if book.is_valid():
            cd = book.cleaned_data
            if len(Author.objects.filter(AuthorID=cd['AuthorID']))<=0:
                new_author=Author(AuthorID =cd['AuthorID'], Name =cd['Name'],\
                Age =cd['Age'],Country =cd['Country'])
                new_author.save()
                new_book=Book(ISBN=cd['ISBN'],Title=cd['Title'],AuthorID=new_author,\
                Publisher=cd['Publisher'],PublishDate=cd['PublishDate'],Price=cd['Price'])
                new_book.save()
            else:
                
                new_book=Book(ISBN=cd['ISBN'],Title=cd['Title'],AuthorID=Author.objects.get(AuthorID=cd['AuthorID']),\
                Publisher=cd['Publisher'],PublishDate=cd['PublishDate'],Price=cd['Price'])
                new_book.save()
            return render_to_response('add.html', {'form': BookForm()})
    else:
        book= BookForm()
    return render_to_response('add.html', {'form': book})