Beispiel #1
0
 def update_url(time=last_update_time, page=None):
     kw = dict(_external=True)
     if time:
         kw.update({'last_update_time' : last_update_time})
     if page:
         kw.update(page.items())
     return cdn_url_for("updates", **kw)
Beispiel #2
0
 def update_url(time=last_update_time, page=None):
     kw = dict(_external=True,
               collection_metadata_identifier=collection_details)
     if time:
         kw.update({'last_update_time': last_update_time})
     if page:
         kw.update(page.items())
     return cdn_url_for("updates", **kw)
 def collection_feed_url(cls, endpoint, collection, page=None,
     **param_kwargs
 ):
     kw = dict(
         _external=True,
         collection_metadata_identifier=collection.name
     )
     kw.update(param_kwargs)
     if page:
         kw.update(page.items())
     return cdn_url_for(endpoint, **kw)
Beispiel #4
0
 def collection_feed_url(cls,
                         endpoint,
                         collection,
                         page=None,
                         **param_kwargs):
     kw = dict(_external=True,
               collection_metadata_identifier=collection.name)
     kw.update(param_kwargs)
     if page:
         kw.update(page.items())
     return cdn_url_for(endpoint, **kw)
Beispiel #5
0
 def feed_url(self, lane, facets, pagination):
     kwargs = dict(facets.items())
     kwargs.update(dict(pagination.items()))
     if lane.license_source:
         view = "feed_from_license_source"
         kwargs['license_source_name'] = lane.license_source.name
     else:
         view = "feed"
         kwargs['lane'] = lane.name
         kwargs['languages'] = lane.languages
     return cdn_url_for(view, _external=True, **kwargs)
Beispiel #6
0
    def add_items(self, collection_details):
        """Adds identifiers to a Collection's catalog"""
        client = authenticated_client_from_request(self._db)
        if isinstance(client, ProblemDetail):
            return client

        collection, ignore = Collection.from_metadata_identifier(
            self._db, collection_details)

        urns = request.args.getlist('urn')
        messages = []
        for urn in urns:
            message = None
            identifier = None
            try:
                identifier, ignore = Identifier.parse_urn(self._db, urn)
            except Exception as e:
                identifier = None

            if not identifier:
                message = OPDSMessage(urn, INVALID_URN.status_code,
                                      INVALID_URN.detail)
            else:
                status = HTTP_OK
                description = "Already in catalog"

                if identifier not in collection.catalog:
                    collection.catalog_identifier(self._db, identifier)
                    status = HTTP_CREATED
                    description = "Successfully added"

                message = OPDSMessage(urn, status, description)

            messages.append(message)

        title = "%s Catalog Item Additions for %s" % (collection.protocol,
                                                      client.url)
        url = cdn_url_for("add",
                          collection_metadata_identifier=collection.name,
                          urn=urns)
        addition_feed = AcquisitionFeed(self._db,
                                        title,
                                        url, [],
                                        VerboseAnnotator,
                                        precomposed_entries=messages)

        return feed_response(addition_feed)
Beispiel #7
0
    def remove_items(self, collection_details):
        """Removes identifiers from a Collection's catalog"""
        client = authenticated_client_from_request(self._db)
        if isinstance(client, ProblemDetail):
            return client

        collection, ignore = Collection.from_metadata_identifier(
            self._db, collection_details)

        urns = request.args.getlist('urn')
        messages = []
        for urn in urns:
            message = None
            identifier = None
            try:
                identifier, ignore = Identifier.parse_urn(self._db, urn)
            except Exception as e:
                identifier = None

            if not identifier:
                message = OPDSMessage(urn, INVALID_URN.status_code,
                                      INVALID_URN.detail)
            else:
                if identifier in collection.catalog:
                    collection.catalog.remove(identifier)
                    message = OPDSMessage(urn, HTTP_OK, "Successfully removed")
                else:
                    message = OPDSMessage(urn, HTTP_NOT_FOUND,
                                          "Not in catalog")

            messages.append(message)

        title = "%s Catalog Item Removal for %s" % (collection.protocol,
                                                    client.url)
        url = cdn_url_for("remove",
                          collection_metadata_identifier=collection.name,
                          urn=urns)
        removal_feed = AcquisitionFeed(self._db,
                                       title,
                                       url, [],
                                       VerboseAnnotator,
                                       precomposed_entries=messages)

        return feed_response(removal_feed)
Beispiel #8
0
    def remove_items(self):
        collection = self.authenticated_collection_from_request()
        if isinstance(collection, ProblemDetail):
            return collection

        urns = request.args.getlist('urn')
        messages = []
        for urn in urns:
            message = None
            identifier = None
            try:
                identifier, ignore = Identifier.parse_urn(self._db, urn)
            except Exception as e:
                identifier = None
            if not identifier:
                message = OPDSMessage(
                    urn, INVALID_URN.status_code, INVALID_URN.detail
                )
            else:
                if identifier in collection.catalog:
                    collection.catalog.remove(identifier)
                    message = OPDSMessage(
                        urn, HTTP_OK, "Successfully removed"
                    )
                else:
                    message = OPDSMessage(
                        urn, HTTP_NOT_FOUND, "Not in collection catalog"
                    )
            if message:
                messages.append(message)

        title = "%s Catalog Item Removal" % collection.name
        url = cdn_url_for("remove", urn=urns)
        removal_feed = AcquisitionFeed(
            self._db, title, url, [], VerboseAnnotator,
            precomposed_entries=messages
        )

        return feed_response(removal_feed)
Beispiel #9
0
 def cdn_url_for(self, *args, **kwargs):
     if self.test_mode:
         return self.test_url_for(True, *args, **kwargs)
     else:
         return cdn_url_for(*args, **kwargs)
Beispiel #10
0
 def cdn_url_for(self, *args, **kwargs):
     if self.test_mode:
         return self.test_url_for(True, *args, **kwargs)
     else:
         return cdn_url_for(*args, **kwargs)
Beispiel #11
0
 def default_lane_url(cls):
     return cdn_url_for("feed", _external=True)