コード例 #1
0
ファイル: views.py プロジェクト: cs1303104/experiment4
def update(request):
    book1 = book.objects.filter(ISBN__icontains=request.GET["ISBN_detail"])
    if request.POST:
        if (
            ("authorID" in request.POST)
            and ("publisher" in request.POST)
            and ("publishDate" in request.POST)
            and ("price" in request.POST)
            and request.POST["authorID"]
            and request.POST["publisher"]
            and request.POST["publishDate"]
            and request.POST["price"]
        ):
            author1 = author.objects.filter(name__icontains=request.POST["authorID"])
            books = book.objects.filter(authorID__name__icontains=author1[0].name)
            if len(author1):
                book1.update(authorID=author1[0])
                book1.update(publisher=request.POST["publisher"])
                book1.update(publishDate=request.POST["publishDate"])
                book1.update(price=request.POST["price"])
                return render_to_response(
                    "search_author_form.html",
                    {"submit": True, "author_exist": True, "author": author1[0], "books": books},
                )
            else:
                return render_to_response("update.html", {"no_author": 1, "authorname": request.POST["authorID"]})

        if request.POST["authorID"] and request.POST["name"] and request.POST["age"] and request.POST["country"]:
            author2 = author(
                authorID=request.POST["authorID"],
                name=request.POST["name"],
                age=request.POST["age"],
                country=request.POST["country"],
            )
            author2.save()
            return render_to_response(
                "update.html", {"no_author": 0, "authorname": request.POST["name"], "book": book1[0], "add_author": 1}
            )
    return render_to_response("update.html", {"book": book1[0]})
コード例 #2
0
ファイル: views.py プロジェクト: cs1303104/experiment4
def search_author_form(request):
    if request.POST:
        if "author_name" in request.POST and len(request.POST["author_name"]):
            author1 = author.objects.filter(name__icontains=request.POST["author_name"])
            book1 = book.objects.filter(authorID__name__icontains=request.POST["author_name"])
            if len(author1):
                return render_to_response(
                    "search_author_form.html",
                    {
                        "submit": True,
                        "author_exist": True,
                        "author": author1[0],
                        "books": book1,
                        "booknumber": len(book1),
                    },
                )
            else:
                return render_to_response(
                    "search_author_form.html",
                    {"submit": True, "author_exist": False, "authorname": request.POST["author_name"]},
                )

        if (
            ("authorID" in request.POST)
            and ("name" in request.POST)
            and ("age" in request.POST)
            and ("country" in request.POST)
            and request.POST["authorID"]
            and request.POST["name"]
            and request.POST["age"]
            and request.POST["country"]
        ):
            author2 = author(
                authorID=request.POST["authorID"],
                name=request.POST["name"],
                age=request.POST["age"],
                country=request.POST["country"],
            )
            author2.save()
            return render_to_response(
                "search_author_form.html", {"submit": True, "author_exist": True, "author": author2}
            )

        if (
            request.POST["ISBN"]
            and request.POST["title"]
            and request.POST["authorID"]
            and request.POST["publisher"]
            and request.POST["publishDate"]
            and request.POST["price"]
        ):
            author3 = author.objects.filter(authorID__icontains=request.POST["authorID"])
            if len(author3):
                book1 = book(
                    ISBN=request.POST["ISBN"],
                    title=request.POST["title"],
                    authorID=author3[0],
                    publisher=request.POST["publisher"],
                    publishDate=request.POST["publishDate"],
                    price=request.POST["price"],
                )
                book1.save()
                book1 = book.objects.filter(authorID__name__icontains=author3[0].name)
                return render_to_response(
                    "search_author_form.html",
                    {
                        "submit": True,
                        "author_exist": True,
                        "author": author3[0],
                        "books": book1,
                        "booknumber": len(book1),
                    },
                )

    return render_to_response("search_author_form.html", {"submit": False})