当前位置: 首页>>代码示例>>Python>>正文


Python Book.publisher方法代码示例

本文整理汇总了Python中books.models.Book.publisher方法的典型用法代码示例。如果您正苦于以下问题:Python Book.publisher方法的具体用法?Python Book.publisher怎么用?Python Book.publisher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在books.models.Book的用法示例。


在下文中一共展示了Book.publisher方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bibtex

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import publisher [as 别名]
def bibtex(request):
    if request.method == "POST":
        if "_parse" in request.POST:
            form = ParseBibTexForm(request.POST)
            if form.is_valid():
                entries = parsers.bibtex(form.cleaned_data["bibtex"])
                if len(entries) >= 1:
                    messages.add_message(request, messages.SUCCESS, "Successfully parsed entry from BibTex.")
                    e = entries[0]
                    form = ParsedBibTexForm(
                        initial={
                            "title": e["title"],
                            "authors": "\n".join(str(author) for author in e["authors"]),
                            "series": e["journal"],
                            "volume": e["volume"],
                            "publisher": e["publisher"],
                            "published_on": e["published_on"],
                            "url": e["url"],
                            "bibtex": e["bibtex"],
                        }
                    )
                    return render(request, "books/admin/parsed_bibtex.html", locals())
                else:
                    messages.add_message(request, messages.ERROR, "No entries found.")
                    return render(request, "books/admin/parse_bibtex.html", locals())
            else:
                return render(request, "books/admin/parse_bibtex.html", locals())
        elif "_create_book" in request.POST:
            form = ParsedBibTexForm(request.POST)
            if form.is_valid():
                series, created = (
                    Series.objects.get_or_create(name=form.cleaned_data["series"])
                    if form.cleaned_data["series"]
                    else (None, False)
                )
                publisher, created = (
                    Publisher.objects.get_or_create(name=form.cleaned_data["publisher"])
                    if form.cleaned_data["publisher"]
                    else (None, False)
                )
                book = Book()
                book.title = form.cleaned_data["title"]
                book.published_on = form.cleaned_data["published_on"]
                book.series = series
                book.volume = form.cleaned_data["volume"]
                book.publisher = publisher
                book.bibtex = form.cleaned_data["bibtex"]
                book.save()

                authors = form.cleaned_data["authors"].split("\n")
                for author in authors:
                    author = eval(author)
                    person, created = Person.objects.get_or_create(
                        firstname=author["firstname"], lastname=author["lastname"]
                    )
                    book.authors.add(person)
                book.save()

                if form.cleaned_data["url"]:
                    Url.objects.create(url=form.cleaned_data["url"], book=book)

                messages.add_message(request, messages.SUCCESS, "Successfully created Book from BibTex.")
                return redirect("admin:books_book_change", book.id)
            else:
                messages.add_message(request, messages.ERROR, "Can not create book.")
                return render(request, "books/admin/parsed_bibtex.html", locals())
    else:
        form = ParseBibTexForm()
        return render(request, "books/admin/parse_bibtex.html", locals())
开发者ID:jnphilipp,项目名称:buecher,代码行数:71,代码来源:bibtex.py


注:本文中的books.models.Book.publisher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。