Esempio n. 1
0
    def all(cls, _db, **constructor_kwargs):
        """Yield a sequence of CollectionMonitor objects: one for every
        Collection associated with cls.PROTOCOL.

        Monitors that have no Timestamp will be yielded first. After that,
        Monitors with older Timestamps will be yielded before Monitors with
        newer timestamps.

        :param constructor_kwargs: These keyword arguments will be passed
        into the CollectionMonitor constructor.
        """
        service_match = or_(Timestamp.service==cls.SERVICE_NAME,
                            Timestamp.service==None)
        collections = Collection.by_protocol(_db, cls.PROTOCOL).outerjoin(
            Timestamp,
            and_(
                Timestamp.collection_id==Collection.id,
                service_match,
            )
        )
        collections = collections.order_by(
            Timestamp.timestamp.asc().nullsfirst()
        )
        for collection in collections:
            yield cls(_db=_db, collection=collection, **constructor_kwargs)
Esempio n. 2
0
    def all(cls, _db, **constructor_kwargs):
        """Yield a sequence of CollectionMonitor objects: one for every
        Collection associated with cls.PROTOCOL.

        Monitors that have no Timestamp will be yielded first. After
        that, Monitors with older values for Timestamp.start will be
        yielded before Monitors with newer values.

        :param constructor_kwargs: These keyword arguments will be passed
        into the CollectionMonitor constructor.

        """
        service_match = or_(Timestamp.service==cls.SERVICE_NAME,
                            Timestamp.service==None)
        collections = Collection.by_protocol(_db, cls.PROTOCOL).outerjoin(
            Timestamp,
            and_(
                Timestamp.collection_id==Collection.id,
                service_match,
            )
        )
        collections = collections.order_by(
            Timestamp.start.asc().nullsfirst()
        )
        for collection in collections:
            yield cls(_db=_db, collection=collection, **constructor_kwargs)
Esempio n. 3
0
    def to_collection(self, _db):
        """Find or create a Collection object for this Overdrive Advantage
        account.

        :return: a 2-tuple of Collections (primary Overdrive
        collection, Overdrive Advantage collection)
        """
        # First find the parent Collection.
        try:
            parent = Collection.by_protocol(_db, ExternalIntegration.OVERDRIVE).filter(
                Collection.external_account_id==self.parent_library_id
            ).one()
        except NoResultFound, e:
            # Without the parent's credentials we can't access the child.
            raise ValueError(
                "Cannot create a Collection whose parent does not already exist."
            )
Esempio n. 4
0
    def all(cls, _db, **kwargs):
        """Yield a sequence of CollectionCoverageProvider instances, one for
        every Collection that gets its licenses from cls.PROTOCOL.

        CollectionCoverageProviders will be yielded in a random order.

        :param kwargs: Keyword arguments passed into the constructor for
        CollectionCoverageProvider (or, more likely, one of its subclasses).

        """
        if cls.PROTOCOL:
            collections = Collection.by_protocol(_db, cls.PROTOCOL)
        else:
            collections = _db.query(Collection)

        collections = collections.order_by(func.random())
        for collection in collections:
            yield cls(collection, **kwargs)