コード例 #1
0
def get_item_from_tiid(tiid,
                       format=None,
                       include_history=False,
                       callback_name=None):
    try:
        item = item_module.get_item(tiid, myrefsets, myredis)
    except (LookupError, AttributeError):
        abort_custom(404, "item does not exist")

    if not item:
        abort_custom(404, "item does not exist")

    if item_module.is_currently_updating(tiid, myredis):
        response_code = 210  # not complete yet
        item["currently_updating"] = True
    else:
        response_code = 200
        item["currently_updating"] = False

    api_key = request.args.get("key", None)
    clean_item = item_module.clean_for_export(item, api_key,
                                              os.getenv("API_ADMIN_KEY"))
    clean_item[
        "HTTP_status_code"] = response_code  # hack for clients who can't read real response codes

    resp_string = json.dumps(clean_item, sort_keys=True, indent=4)
    if callback_name is not None:
        resp_string = callback_name + '(' + resp_string + ')'

    resp = make_response(resp_string, response_code)

    return resp
コード例 #2
0
def get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history=False):
    collection_obj = Collection.query.get(cid)
    collection_doc = get_collection_doc_from_object(collection_obj)
    if not collection_doc:
        return (None, None)

    collection_doc["items"] = []
    tiids = collection_obj.tiids

    if tiids:
        item_objects = get_readonly_item_objects_with_metrics(tiids)

        for item_obj in item_objects:
            #logger.info(u"got item {tiid} for {cid}".format(
            #    tiid=item_obj.tiid, cid=cid))
            try:
                item_doc = item_obj.as_old_doc()
                item_for_client = item_module.build_item_for_client(item_doc, myrefsets, myredis)
            except (KeyError, TypeError, AttributeError):
                logger.info(u"Couldn't build item {tiid}, excluding it from the returned collection {cid}".format(
                    tiid=item_obj.tiid, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection_doc["items"] += [item_for_client]
    
    something_currently_updating = False
    for item in collection_doc["items"]:
        item["currently_updating"] = item_module.is_currently_updating(item["_id"], myredis)
        something_currently_updating = something_currently_updating or item["currently_updating"]

    logger.debug(u"Got items for collection_doc %s" %cid)

    return (collection_doc, something_currently_updating)
コード例 #3
0
ファイル: views.py プロジェクト: dbeucke/total-impact-core
def get_item_from_tiid(tiid, format=None, include_history=False, callback_name=None):
    try:
        item = item_module.get_item(tiid, myrefsets, myredis)
    except (LookupError, AttributeError):
        abort_custom(404, "item does not exist")

    if not item:
        abort_custom(404, "item does not exist")

    if item_module.is_currently_updating(tiid, myredis):
        response_code = 210 # not complete yet
        item["currently_updating"] = True
    else:
        response_code = 200
        item["currently_updating"] = False

    api_key = request.args.get("key", None)
    clean_item = item_module.clean_for_export(item, api_key, os.getenv("API_ADMIN_KEY"))
    clean_item["HTTP_status_code"] = response_code  # hack for clients who can't read real response codes

    resp_string = json.dumps(clean_item, sort_keys=True, indent=4)
    if callback_name is not None:
        resp_string = callback_name + '(' + resp_string + ')'

    resp = make_response(resp_string, response_code)

    return resp
コード例 #4
0
def get_collection_with_items_for_client(cid,
                                         myrefsets,
                                         myredis,
                                         mydao,
                                         include_history=False):
    collection_obj = Collection.query.get(cid)
    collection_doc = get_collection_doc_from_object(collection_obj)
    if not collection_doc:
        return (None, None)

    collection_doc["items"] = []
    tiids = collection_obj.tiids

    if tiids:
        item_objects = get_readonly_item_objects_with_metrics(tiids)

        for item_obj in item_objects:
            #logger.info(u"got item {tiid} for {cid}".format(
            #    tiid=item_obj.tiid, cid=cid))
            try:
                item_doc = item_obj.as_old_doc()
                item_for_client = item_module.build_item_for_client(
                    item_doc, myrefsets, myredis)
            except (KeyError, TypeError, AttributeError):
                logger.info(
                    u"Couldn't build item {tiid}, excluding it from the returned collection {cid}"
                    .format(tiid=item_obj.tiid, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection_doc["items"] += [item_for_client]

    something_currently_updating = False
    for item in collection_doc["items"]:
        item["currently_updating"] = item_module.is_currently_updating(
            item["_id"], myredis)
        something_currently_updating = something_currently_updating or item[
            "currently_updating"]

    logger.debug(u"Got items for collection_doc %s" % cid)

    return (collection_doc, something_currently_updating)
コード例 #5
0
def get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history=False):
    startkey = [cid, 0]
    endkey = [cid, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"]
    view_response = mydao.db.view("collections_with_items/collections_with_items", 
                        include_docs=True, 
                        startkey=startkey, 
                        endkey=endkey)
    # the first row is the collection document
    first_row = view_response.rows[0]
    collection = first_row.doc
    try:
        del collection["ip_address"]
    except KeyError:
        pass
    del collection["alias_tiids"]

    # start with the 2nd row, since 1st row is the collection document
    collection["items"] = []
    if len(view_response.rows) > 1:
        for row in view_response.rows[1:]:
            item_doc = row.doc 
            try:
                item_for_client = item_module.build_item_for_client(item_doc, myrefsets, mydao, include_history)
            except (KeyError, TypeError):
                logging.info("Couldn't build item {item_doc}, excluding it from the returned collection {cid}".format(
                    item_doc=item_doc, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection["items"] += [item_for_client]
    
    something_currently_updating = False
    for item in collection["items"]:
        item["currently_updating"] = item_module.is_currently_updating(item["_id"], myredis)
        something_currently_updating = something_currently_updating or item["currently_updating"]

    logging.info("Got items for collection %s" %cid)
    # print json.dumps(collection, sort_keys=True, indent=4)
    return (collection, something_currently_updating)
コード例 #6
0
ファイル: views.py プロジェクト: karthik/total-impact-core
def get_item_from_tiid(tiid, format=None, include_history=False):

    try:
        item = item_module.get_item(tiid, myrefsets, mydao, include_history)
    except (LookupError, AttributeError):
        abort(404)

    if not item:
        abort(404)

    if item_module.is_currently_updating(tiid, myredis):
        response_code = 210 # not complete yet
        item["currently_updating"] = True
    else:
        response_code = 200
        item["currently_updating"] = False

    api_key = request.args.get("key", None)
    clean_item = item_module.clean_for_export(item, api_key, os.getenv("API_KEY"))
    resp = make_response(json.dumps(clean_item, sort_keys=True, indent=4),
                         response_code)
    resp.mimetype = "application/json"

    return resp
コード例 #7
0
 def test_is_currently_updating_no(self):
     self.r.set_num_providers_left("tiidthatisnotdone", 0)        
     response = item_module.is_currently_updating("tiidthatisdone", self.r)
     assert_equals(response, False)
コード例 #8
0
 def test_is_currently_updating_unknown(self):
     response = item_module.is_currently_updating("tiidnotinredis", self.r)
     assert_equals(response, False)
コード例 #9
0
def is_something_currently_updating(items_dict, myredis):
    something_currently_updating = False
    for tiid in items_dict:
        this_item_updating = item_module.is_currently_updating(tiid, myredis)
        something_currently_updating = something_currently_updating or this_item_updating
    return something_currently_updating
コード例 #10
0
def is_something_currently_updating(items_dict, myredis):
    something_currently_updating = False
    for tiid in items_dict:
        this_item_updating = item_module.is_currently_updating(tiid, myredis)
        something_currently_updating = something_currently_updating or this_item_updating
    return something_currently_updating