def get_gushim(): """ get gush_id metadata """ detailed = request.args.get('detailed', '') == 'true' gushim = helpers._get_gushim(fields={'gush_id': True, 'last_checked_at': True, '_id': False}) if detailed: # Flatten list of gushim into a dict g_flat = dict((g['gush_id'], {"gush_id": g['gush_id'], "last_checked_at": g['last_checked_at'], "plan_stats": {}}) for g in gushim) # Get plan statistics from DB stats = helpers._get_plan_statistics() # Merge stats into gushim dict for g in stats['result']: try: gush_id = g['_id']['gush_id'] status = g['_id']['status'] g_flat[gush_id]['plan_stats'][status] = g['count'] except KeyError, e: # Gush has plans but is missing from list of gushim? app.logger.warn("Gush #%d has plans but is not listed in the Gushim list", gush_id) app.log_exception(e) # De-flatten our dict gushim = g_flat.values()
def get_gushim(): """ get gush_id metadata """ detailed = request.args.get('detailed', '') == 'true' gushim = helpers._get_gushim(fields={ 'gush_id': True, 'last_checked_at': True, '_id': False }) if detailed: # Flatten list of gushim into a dict g_flat = dict((g['gush_id'], { "gush_id": g['gush_id'], "last_checked_at": g['last_checked_at'], "plan_stats": {} }) for g in gushim) # Get plan statistics from DB stats = helpers._get_plan_statistics() # Merge stats into gushim dict for g in stats['result']: try: gush_id = g['_id']['gush_id'] status = g['_id']['status'] g_flat[gush_id]['plan_stats'][status] = g['count'] except KeyError, e: # Gush has plans but is missing from list of gushim? app.logger.warn( "Gush #%d has plans but is not listed in the Gushim list", gush_id) app.log_exception(e) # De-flatten our dict gushim = g_flat.values()
def get_gush(gush_id): """ get gush_id metadata """ gush = helpers._get_gushim(query={"gush_id": gush_id}) if gush is None or len(gush) == 0: abort(404) return helpers._create_response_json(gush[0])