예제 #1
0
 def related_books_available(cls, license_pool):
     """:return: bool asserting whether related books are available for a
     particular work
     """
     contributions = license_pool.presentation_edition.contributions
     series = license_pool.presentation_edition.series
     return contributions or series or NoveListAPI.is_configured()
예제 #2
0
 def __init__(self, _db, license_pool, full_name, display_name=None,
              novelist_api=None, parent=None):
     self.api = novelist_api or NoveListAPI.from_config(_db)
     super(RecommendationLane, self).__init__(
         _db, license_pool, full_name, display_name=display_name,
         parent=parent
     )
     self.recommendations = self.fetch_recommendations()
예제 #3
0
    def related_books_available(cls, work, library):
        """:return: bool asserting whether related books might exist for
        a particular Work
        """
        contributions = work.sort_author and work.sort_author != Edition.UNKNOWN_AUTHOR

        return (contributions or work.series
                or NoveListAPI.is_configured(library))
예제 #4
0
 def __init__(self, library, work, display_name=None,
              novelist_api=None, parent=None):
     super(RecommendationLane, self).__init__(
         library, work, display_name=display_name,
     )
     _db = Session.object_session(library)
     self.api = novelist_api or NoveListAPI.from_config(library)
     self.recommendations = self.fetch_recommendations(_db)
     if parent:
         parent.children.append(self)
예제 #5
0
    def related_books_available(cls, work, library):
        """:return: bool asserting whether related books might exist for
        a particular Work
        """
        if isinstance(work, Work):
            edition = work.presentation_edition
        else:
            # This is a MaterializedWork*, so we're gonna grab the
            # edition where we can.
            edition = work.license_pool.presentation_edition

        contributions = edition.contributions
        series = edition.series
        return contributions or series or NoveListAPI.is_configured(library)
예제 #6
0
파일: lanes.py 프로젝트: lhuabu/circulation
    def __init__(self, library, work, display_name=None,
                 novelist_api=None, parent=None):
        """Constructor.

        :raises: CannotLoadConfiguration if `novelist_api` is not provided
        and no Novelist integration is configured for this library.
        """
        super(RecommendationLane, self).__init__(
            library, work, display_name=display_name,
        )
        self.novelist_api = novelist_api or NoveListAPI.from_config(library)
        if parent:
            parent.append_child(self)
        _db = Session.object_session(library)
        self.recommendations = self.fetch_recommendations(_db)
예제 #7
0
 def __init__(self,
              library,
              work,
              display_name=None,
              novelist_api=None,
              parent=None):
     super(RecommendationLane, self).__init__(
         library,
         work,
         display_name=display_name,
     )
     _db = Session.object_session(library)
     self.api = novelist_api or NoveListAPI.from_config(library)
     self.recommendations = self.fetch_recommendations(_db)
     if parent:
         parent.children.append(self)
예제 #8
0
 def __init__(self,
              _db,
              library,
              work,
              full_name,
              display_name=None,
              novelist_api=None,
              parent=None):
     super(RecommendationLane, self).__init__(
         _db,
         library,
         work,
         full_name,
         display_name=display_name,
         parent=parent,
         searchable=False,
     )
     self.api = novelist_api or NoveListAPI.from_config(library)
     self.recommendations = self.fetch_recommendations()
예제 #9
0
파일: opds.py 프로젝트: dguo/circulation
 def related_books_available(cls, license_pool):
     """:return: bool asserting whether related books are available for a
     particular work
     """
     series = license_pool.presentation_edition.series
     return NoveListAPI.is_configured() or series
예제 #10
0
    def annotate_work_entry(self, work, active_license_pool, edition, identifier, feed, entry):
        Annotator.annotate_work_entry(
            work, active_license_pool, edition, identifier, feed, entry
        )
        active_loan = self.active_loans_by_work.get(work)
        active_hold = self.active_holds_by_work.get(work)
        active_fulfillment = self.active_fulfillments_by_work.get(work)

        # First, add a permalink.
        feed.add_link_to_entry(
            entry, 
            rel='alternate',
            type=OPDSFeed.ENTRY_TYPE,
            href=self.permalink_for(
                work, active_license_pool, identifier
            )
        )

        # Add a link for reporting problems.
        feed.add_link_to_entry(
            entry, 
            rel='issues',
            href=self.url_for(
                'report',
                identifier_type=identifier.type,
                identifier=identifier.identifier,
                library_short_name=self.library.short_name,
                _external=True
            )
        )

        # Now we need to generate a <link> tag for every delivery mechanism
        # that has well-defined media types.
        link_tags = self.acquisition_links(
            active_license_pool, active_loan, active_hold, active_fulfillment,
            feed, identifier
        )
        for tag in link_tags:
            entry.append(tag)

        # Add a link for each author.
        self.add_author_links(work, feed, entry)

        # And a series, if there is one.
        if work.series:
            self.add_series_link(work, feed, entry)

        if NoveListAPI.is_configured(self.library):
            # If NoveList Select is configured, there might be
            # recommendations, too.
            feed.add_link_to_entry(
                entry,
                rel='recommendations',
                type=OPDSFeed.ACQUISITION_FEED_TYPE,
                title='Recommended Works',
                href=self.url_for(
                    'recommendations',
                    identifier_type=identifier.type,
                    identifier=identifier.identifier,
                    library_short_name=self.library.short_name,
                    _external=True
                )
            )

        # Add a link for related books if available.
        if self.related_books_available(work, self.library):
            feed.add_link_to_entry(
                entry,
                rel='related',
                type=OPDSFeed.ACQUISITION_FEED_TYPE,
                title='Recommended Works',
                href=self.url_for(
                    'related_books',
                    identifier_type=identifier.type,
                    identifier=identifier.identifier,
                    library_short_name=self.library.short_name,
                    _external=True
                )
            )

        # Add a link to get a patron's annotations for this book.
        feed.add_link_to_entry(
            entry,
            rel="http://www.w3.org/ns/oa#annotationService",
            type=AnnotationWriter.CONTENT_TYPE,
            href=self.url_for(
                'annotations_for_work',
                identifier_type=identifier.type,
                identifier=identifier.identifier,
                library_short_name=self.library.short_name,
                _external=True
            )
        )