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


Python Book.title方法代码示例

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


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

示例1: read_gutenberg_headers

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import title [as 别名]
def read_gutenberg_headers(fp):
    book = Book()
    for line in fp:
        if line.startswith('Title:'):
            book.title = line[6:].strip(string.punctuation + string.whitespace)

        if line.startswith('Author:'):
            book.author = line[7:].strip(string.punctuation + string.whitespace)

        if line.startswith('Release Date:'):
            book.published = line[13:].strip(string.punctuation + string.whitespace)

        if line.startswith('*** START OF THIS PROJECT GUTENBERG EBOOK'):
            return book
开发者ID:ebachle,项目名称:stats,代码行数:16,代码来源:utils.py

示例2: setup_environ

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import title [as 别名]
import settings_copy as settings
setup_environ(settings)

from books.models import Book

t = int(raw_input('number of books you want to add:'))

import random

TITLE_PREFIX = (u'数学', u'方程', u'化学', u'生物', u'疾病', u'神经', u'电子', u'模拟', u'物理', u'逻辑', u'算法', u'程序', u'数据库', u'网络', u'计算机', u'概率', u'随机')
TITLE_SUFFIX = (u'引论', u'概论', u'方法', u'教程', u'导读', u'分析', u'入门')
AUTHOR_PREFIX = u'赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
AUTHOR_SUFFIX = u'伟芳秀敏杰丹灵华兆婷超梁晗辉军越征凯腾江帆一中君盛丽群来未晨和刚明娜'

def get_rand(s):
    return s[random.randint(0, len(s) - 1)]

for i in range(t):
    b = Book()
    b.isbn = str(int(random.random() * (10 ** 13)))
    t = random.randint(1, 2)
    s = ''.join([get_rand(TITLE_PREFIX) for tt in range(0, t)])
    s += get_rand(TITLE_SUFFIX)
    b.title = s
    b.author = get_rand(AUTHOR_PREFIX) + get_rand(AUTHOR_SUFFIX);
    if random.randint(0, 2) == 1:
        b.author += get_rand(AUTHOR_SUFFIX)
    b.press = get_rand((u"复旦大学出版社", u"机械工业出版社", u"中华书局"))
    b.sale_price = round(random.random() * 100) + 1
    print b
    b.save()
开发者ID:ComboZhc,项目名称:Library,代码行数:33,代码来源:add_books.py

示例3: bibtex

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import title [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.title方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。