本文整理汇总了Python中catalogue.models.Book类的典型用法代码示例。如果您正苦于以下问题:Python Book类的具体用法?Python Book怎么用?Python Book使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
WLTestCase.setUp(self)
index = Index()
index.index.delete_all()
index.index.commit()
self.do_doktora = Book.from_xml_file(
get_fixture('do-doktora.xml'))
self.do_anusie = Book.from_xml_file(
get_fixture('fraszka-do-anusie.xml', catalogue))
示例2: setUp
def setUp(self):
WLTestCase.setUp(self)
index = Index()
index.index.delete_all()
index.index.commit()
with self.settings(NO_SEARCH_INDEX=False):
self.do_doktora = Book.from_xml_file(
get_fixture('do-doktora.xml'))
self.do_anusie = Book.from_xml_file(
get_fixture('fraszka-do-anusie.xml', catalogue))
示例3: setUp
def setUp(self):
WLTestCase.setUp(self)
index = Index()
self.search = Search()
index.delete_query(self.search.index.query(uid="*"))
index.index.commit()
self.do_doktora = Book.from_xml_file(
get_fixture('do-doktora.xml', opds))
self.do_anusie = Book.from_xml_file(
get_fixture('fraszka-do-anusie.xml', catalogue))
示例4: test_simple_import
def test_simple_import(self, parent_cover_changed):
child = Book.from_text_and_meta(ContentFile(self.TEXT), self.child)
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent)
parent_cover_changed.assert_called_with(child)
# Now reimport parent.
parent_cover_changed.reset_mock()
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent, overwrite=True)
self.assertEqual(parent_cover_changed.call_count, 0)
# Now change cover in parent.
parent_cover_changed.reset_mock()
self.parent.cover_url = "http://example.com/other-cover.jpg"
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent, overwrite=True)
parent_cover_changed.assert_called_with(child)
示例5: test_book_with_footnote
def test_book_with_footnote(self):
book_text = """<utwor>
<opowiadanie>
<akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
<akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
<akap><pe><slowo_obce>rose</slowo_obce> (techn.) --- #FF007F.</pe></akap>
</opowiadanie></utwor>
"""
book = Book.from_text_and_meta(ContentFile(book_text), self.book_info)
self.assertEqual(
len(self.client.get('/przypisy/').context['object_list']),
2,
'There should be two notes on the note list.')
self.assertEqual(
len(self.client.get('/przypisy/?ltr=a').context['object_list']),
0,
'There should not be a note for the letter A.')
self.assertEqual(
len(self.client.get('/przypisy/?ltr=r').context['object_list']),
2,
'Both notes start with the letter R.')
self.assertEqual(
len(self.client.get('/przypisy/?qual=techn.').context['object_list']),
1,
'There should be a note qualified with \'techn.\' qualifier.')
示例6: test_new_child
def test_new_child(self, parent_cover_changed):
# Add parent without child first.
parts, self.parent.parts = self.parent.parts, []
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent)
# Now import child and reimport parent.
child = Book.from_text_and_meta(ContentFile(self.TEXT), self.child)
self.parent.parts = parts
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent, overwrite=True)
parent_cover_changed.assert_called_with(child)
# Now remove the child.
parent_cover_changed.reset_mock()
self.parent.parts = []
parent = Book.from_text_and_meta(ContentFile(self.TEXT), self.parent, overwrite=True)
parent_cover_changed.assert_called_with(child)
示例7: catalogue_csv
def catalogue_csv(path):
books_by_author, orphans, books_by_parent = Book.book_list()
render_to_csv(path, 'reporting/catalogue.csv', {
'books_by_author': books_by_author,
'orphans': orphans,
'books_by_parent': books_by_parent,
})
示例8: test_none_indexed
def test_none_indexed(self):
self.book2 = Book.create(self.user, 'book 2', slug='book2')
self.make_gallery(self.book1, {
'0001_1l' : 'aa',
'0001_2r' : 'bb',
'0002_1l' : 'cc',
'0002_2r' : 'dd',
})
self.make_gallery(self.book2, {
'0001_1l' : 'ee',
'0001_2r' : 'ff',
'0002_1l' : 'gg',
'0002_2r' : 'hh',
})
self.book1.append(self.book2)
files = listdir(join(self.scandir, self.book1.gallery))
files.sort()
print files
self.assertEqual(files, [
'0-0001_1l',
'0-0001_2r',
'0-0002_1l',
'0-0002_2r',
'1-0001_1l',
'1-0001_2r',
'1-0002_1l',
'1-0002_2r',
])
示例9: create_missing
def create_missing(request, slug=None):
if slug is None:
slug = ''
slug = slug.replace(' ', '-')
if request.method == "POST":
form = forms.DocumentCreateForm(request.POST, request.FILES)
if form.is_valid():
if request.user.is_authenticated():
creator = request.user
else:
creator = None
book = Book.create(
text=form.cleaned_data['text'],
creator=creator,
slug=form.cleaned_data['slug'],
title=form.cleaned_data['title'],
gallery=form.cleaned_data['gallery'],
)
return http.HttpResponseRedirect(reverse("catalogue_book", args=[book.slug]))
else:
form = forms.DocumentCreateForm(initial={
"slug": slug,
"title": slug.replace('-', ' ').title(),
"gallery": slug,
})
return render(request, "catalogue/document_create_missing.html", {
"slug": slug,
"form": form,
"logout_to": '/',
})
示例10: tag_dict
def tag_dict(tag, fields=None):
all_fields = ("name", "category", "sort_key", "description", "gazeta_link", "wiki_link", "url", "books")
if fields:
fields = (f for f in fields if f in all_fields)
else:
fields = all_fields
obj = {}
for field in fields:
if field == "url":
obj[field] = tag.get_absolute_url()
elif field == "books":
obj[field] = [b.id for b in Book.tagged_top_level([tag]).iterator()]
elif field == "sort_key":
obj[field] = tag.sort_key
else:
f = getattr(tag, field)
if f:
obj[field] = f
obj["id"] = tag.id
return obj
示例11: read
def read(self, request, tags, top_level=False, audiobooks=False, daisy=False):
""" Lists all books with given tags.
:param tags: filtering tags; should be a path of categories
and slugs, i.e.: authors/an-author/epoch/an-epoch/
:param top_level: if True and a book is included in the results,
it's children are aren't. By default all books matching the tags
are returned.
"""
try:
tags = read_tags(tags, allowed=book_tag_categories)
except ValueError:
return rc.NOT_FOUND
if tags:
if top_level:
books = Book.tagged_top_level(tags)
return books if books else rc.NOT_FOUND
else:
books = Book.tagged.with_all(tags)
else:
books = Book.objects.all()
if top_level:
books = books.filter(parent=None)
if audiobooks:
books = books.filter(media__type="mp3").distinct()
if daisy:
books = books.filter(media__type="daisy").distinct()
if books.exists():
return books
else:
return rc.NOT_FOUND
示例12: tag_dict
def tag_dict(tag, fields=None):
all_fields = ('name', 'category', 'sort_key', 'description',
'gazeta_link', 'wiki_link',
'url', 'books',
)
if fields:
fields = (f for f in fields if f in all_fields)
else:
fields = all_fields
obj = {}
for field in fields:
if field == 'url':
obj[field] = tag.get_absolute_url()
elif field == 'books':
obj[field] = [b.id for b in Book.tagged_top_level([tag]).iterator()]
elif field == 'sort_key':
obj[field] = tag.sort_key
else:
f = getattr(tag, field)
if f:
obj[field] = f
obj['id'] = tag.id
return obj
示例13: save
def save(self, **kwargs):
return Book.from_xml_file(
self.cleaned_data["book_xml_file"],
overwrite=True,
remote_gallery_url=self.cleaned_data["gallery_url"],
**kwargs
)
示例14: catalogue_pdf
def catalogue_pdf(path):
books_by_author, orphans, books_by_parent = Book.book_list()
render_to_pdf(
path,
"reporting/catalogue.texml",
locals(),
{"wl-logo.png": os.path.join(settings.STATIC_ROOT, "img/logo-big.png")},
)
示例15: add_tag
def add_tag(db, tag):
id = tag.id
category = categories[tag.category]
name = tag.name
sort_key = tag.sort_key
books = Book.tagged_top_level([tag])
book_ids = ','.join(str(b.id) for b in books)
db.execute(tag_sql, locals())