當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Book類代碼示例

本文整理匯總了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))
開發者ID:jumasheff,項目名稱:wolnelektury,代碼行數:10,代碼來源:__init__.py

示例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))
開發者ID:BibliotekaOtwartejNauki,項目名稱:wolnelektury,代碼行數:11,代碼來源:__init__.py

示例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))
開發者ID:,項目名稱:,代碼行數:12,代碼來源:

示例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)
開發者ID:fnp,項目名稱:wolnelektury,代碼行數:15,代碼來源:test_cover.py

示例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.')
開發者ID:fnp,項目名稱:wolnelektury,代碼行數:30,代碼來源:tests.py

示例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)
開發者ID:fnp,項目名稱:wolnelektury,代碼行數:16,代碼來源:test_cover.py

示例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,
    })
開發者ID:fnp,項目名稱:wolnelektury,代碼行數:7,代碼來源:views.py

示例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',
            ])        
開發者ID:,項目名稱:,代碼行數:31,代碼來源:

示例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": '/',
    })
開發者ID:,項目名稱:,代碼行數:35,代碼來源:

示例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
開發者ID:barszczmm,項目名稱:wolnelektury,代碼行數:27,代碼來源:handlers.py

示例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
開發者ID:barszczmm,項目名稱:wolnelektury,代碼行數:34,代碼來源:handlers.py

示例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
開發者ID:prmtl,項目名稱:wolnelektury,代碼行數:30,代碼來源:handlers.py

示例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
     )
開發者ID:fnp,項目名稱:wolnelektury,代碼行數:7,代碼來源:forms.py

示例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")},
    )
開發者ID:prmtl,項目名稱:wolnelektury,代碼行數:8,代碼來源:views.py

示例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())
開發者ID:jumasheff,項目名稱:wolnelektury,代碼行數:9,代碼來源:mobileinit.py


注:本文中的catalogue.models.Book類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。