def collection_get(cid='', format="json", include_history=False): logger.info(u"in collection_get".format(cid=cid)) # if not include items, then just return the collection straight from couch if (request.args.get("include_items") in ["0", "false", "False"]): coll = collection.get_collection_doc(cid) if not coll: abort_custom(404, "collection not found") # except if format is csv. can't do that. if format == "csv": abort_custom(405, "csv method not supported for not include_items") else: response_code = 200 resp = make_response(json.dumps(coll, sort_keys=True, indent=4), response_code) else: include_history = (request.args.get("include_history", 0) in ["1", "true", "True"]) (coll_with_items, something_currently_updating ) = collection.get_collection_with_items_for_client( cid, myrefsets, myredis, mydao, include_history) # return success if all reporting is complete for all items if something_currently_updating: response_code = 210 # update is not complete yet else: response_code = 200 if format == "csv": # remove scopus before exporting to csv, so don't add magic keep-scopus keys to clean method clean_items = [ item_module.clean_for_export(item) for item in coll_with_items["items"] ] csv = collection.make_csv_stream(clean_items) resp = make_response(csv, response_code) resp.mimetype = "text/csv;charset=UTF-8" resp.headers.add( "Content-Disposition", "attachment; filename=impactstory-{cid}.csv".format(cid=cid)) resp.headers.add("Content-Encoding", "UTF-8") else: secret_key = os.getenv("API_ADMIN_KEY") if request.args.get("api_admin_key"): supplied_key = request.args.get("api_admin_key", "") else: supplied_key = request.args.get("key", "") clean_if_necessary_items = [ item_module.clean_for_export(item, supplied_key, secret_key) for item in coll_with_items["items"] ] coll_with_items["items"] = clean_if_necessary_items resp = make_response( json.dumps(coll_with_items, sort_keys=True, indent=4), response_code) return resp
def collection_get(cid='', format="json", include_history=False): logger.info(u"in collection_get".format(cid=cid)) # if not include items, then just return the collection straight from couch if (request.args.get("include_items") in ["0", "false", "False"]): coll = collection.get_collection_doc(cid) if not coll: abort_custom(404, "collection not found") # except if format is csv. can't do that. if format == "csv": abort_custom(405, "csv method not supported for not include_items") else: response_code = 200 resp = make_response(json.dumps(coll, sort_keys=True, indent=4), response_code) else: include_history = (request.args.get("include_history", 0) in ["1", "true", "True"]) (coll_with_items, something_currently_updating) = collection.get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history) # return success if all reporting is complete for all items if something_currently_updating: response_code = 210 # update is not complete yet else: response_code = 200 if format == "csv": # remove scopus before exporting to csv, so don't add magic keep-scopus keys to clean method clean_items = [item_module.clean_for_export(item) for item in coll_with_items["items"]] csv = collection.make_csv_stream(clean_items) resp = make_response(csv, response_code) resp.mimetype = "text/csv;charset=UTF-8" resp.headers.add("Content-Disposition", "attachment; filename=impactstory-{cid}.csv".format( cid=cid)) resp.headers.add("Content-Encoding", "UTF-8") else: secret_key = os.getenv("API_ADMIN_KEY") if request.args.get("api_admin_key"): supplied_key = request.args.get("api_admin_key", "") else: supplied_key = request.args.get("key", "") clean_if_necessary_items = [item_module.clean_for_export(item, supplied_key, secret_key) for item in coll_with_items["items"]] coll_with_items["items"] = clean_if_necessary_items resp = make_response(json.dumps(coll_with_items, sort_keys=True, indent=4), response_code) return resp
def collection_metrics_refresh(cid=""): # first, get the tiids in this collection: try: coll_doc = collection.get_collection_doc(cid) tiids = coll_doc["alias_tiids"].values() except (TypeError, AttributeError): logger.exception( u"couldn't get tiids in POST collection '{cid}'".format(cid=cid)) abort_custom(500, "Error doing collection_update") refresh_from_tiids(tiids, {}, "low", myredis) resp = make_response("true", 200) return resp
def collection_metrics_refresh(cid=""): # first, get the tiids in this collection: try: coll_doc = collection.get_collection_doc(cid) tiids = coll_doc["alias_tiids"].values() except (TypeError, AttributeError): logger.exception(u"couldn't get tiids in POST collection '{cid}'".format( cid=cid )) abort_custom(500, "Error doing collection_update") refresh_from_tiids(tiids, {}, "low", myredis) resp = make_response("true", 200) return resp
def collection_metrics_refresh(cid=""): # first, get the tiids in this collection: try: coll_doc = collection.get_collection_doc(cid) tiids = coll_doc["alias_tiids"].values() except (TypeError, AttributeError): logger.exception( u"couldn't get tiids in POST collection '{cid}'".format(cid=cid)) abort_custom(500, "Error doing collection_update") for tiid in tiids: try: item_obj = item_module.Item.from_tiid(tiid) item = item_obj.as_old_doc() item_module.start_item_update(tiid, item["aliases"], myredis) except AttributeError: logger.debug( u"couldn't find tiid {tiid} in {cid} so not refreshing its metrics" .format(cid=cid, tiid=tiid)) resp = make_response("true", 200) return resp
def collection_metrics_refresh(cid=""): # first, get the tiids in this collection: try: coll_doc = collection.get_collection_doc(cid) tiids = coll_doc["alias_tiids"].values() except (TypeError, AttributeError): logger.exception(u"couldn't get tiids in POST collection '{cid}'".format( cid=cid )) abort_custom(500, "Error doing collection_update") for tiid in tiids: try: item_obj = item_module.Item.from_tiid(tiid) item = item_obj.as_old_doc() item_module.start_item_update(tiid, item["aliases"], myredis) except AttributeError: logger.debug(u"couldn't find tiid {tiid} in {cid} so not refreshing its metrics".format( cid=cid, tiid=tiid)) resp = make_response("true", 200) return resp