def api_collection_search(search_str): public_only = False if user_has_auth_role(ROLE_MEDIA_EDIT) else True results = collection_search(search_str, public_only, VALID_COLLECTION_TAG_SETS_IDS) trim_count = MAX_COLLECTIONS if len(results) > 20 else len(results) trimmed = results[:trim_count] add_user_favorite_flag_to_collections(trimmed) return jsonify({'list': trimmed})
def api_collection_search(search_str): public_only = False if user_has_auth_role(ROLE_MEDIA_EDIT) else True results = collection_search(search_str, public_only, VALID_COLLECTION_TAG_SETS_IDS) trim_count = MAX_COLLECTIONS if len(results) > 20 else len(results) trimmed = results[:trim_count] #flat_list = [{'tags_id': t['tags_id'], 'tag_set_label':t['tag_set_label'],'label':t['label'], 'tag':t['tag']} for t in trimmed] add_user_favorite_flag_to_collections(trimmed) return jsonify({'list': trimmed})
def api_media_source_details(media_id): health = _cached_media_source_health(user_mediacloud_key(), media_id) info = _media_source_details(media_id) info['health'] = health user_mc = user_admin_mediacloud_client() if user_has_auth_role(ROLE_MEDIA_EDIT): info['scrape_status'] = user_mc.feedsScrapeStatus(media_id) # need to know if scrape is running else: info['scrape_status'] = None add_user_favorite_flag_to_sources([info]) add_user_favorite_flag_to_collections(info['media_source_tags']) analytics_db.increment_count(analytics_db.TYPE_MEDIA, media_id, analytics_db.ACTION_SOURCE_MGR_VIEW) return jsonify(info)
def api_media_source_details(media_id): health = _cached_media_source_health(user_mediacloud_key(), media_id) info = _media_source_details(media_id) info['health'] = health user_mc = user_admin_mediacloud_client() if user_has_auth_role(ROLE_MEDIA_EDIT): info['scrape_status'] = user_mc.feedsScrapeStatus( media_id) # need to know if scrape is running else: info['scrape_status'] = None add_user_favorite_flag_to_sources([info]) add_user_favorite_flag_to_collections(info['media_source_tags']) return jsonify(info)
def api_collection_details(collection_id): add_in_sources = False if ('getSources' in request.args) and (request.args['getSources'] == 'true'): add_in_sources = True user_mc = user_mediacloud_client() info = user_mc.tag(collection_id) add_user_favorite_flag_to_collections([info]) info['id'] = collection_id info['tag_set'] = _tag_set_info(user_mediacloud_key(), info['tag_sets_id']) if add_in_sources: media_in_collection = media_with_tag(user_mediacloud_key(), collection_id) info['sources'] = media_in_collection analytics_db.increment_count(analytics_db.TYPE_COLLECTION, collection_id, analytics_db.ACTION_SOURCE_MGR_VIEW) return jsonify({'results': info})
def api_collection_details(collection_id): add_in_sources = False if ('getSources' in request.args) and (request.args['getSources'] == 'true'): add_in_sources = True user_mc = user_mediacloud_client() info = user_mc.tag(collection_id) add_user_favorite_flag_to_collections([info]) info['id'] = collection_id info['tag_set'] = _tag_set_info(user_mediacloud_key(), info['tag_sets_id']) if add_in_sources: media_in_collection = media_with_tag(user_mediacloud_key(), collection_id) info['sources'] = media_in_collection analytics_db.increment_count(analytics_db.TYPE_COLLECTION, collection_id, analytics_db.ACTION_SOURCE_MGR_VIEW) return jsonify({'results': info})
def api_collection_details(collection_id): add_in_sources = False if ('getSources' in request.args) and (request.args['getSources'] == 'true'): add_in_sources = True user_mc = user_mediacloud_client() info = user_mc.tag(collection_id) add_user_favorite_flag_to_collections([info]) info['id'] = collection_id info['tag_set'] = _tag_set_info(user_mediacloud_key(), info['tag_sets_id']) if add_in_sources: media_in_collection = media_with_tag(user_mediacloud_key(), collection_id) info['sources'] = media_in_collection return jsonify({'results': info})
def api_collection_set(tag_sets_id): ''' Return a list of all the (public only or public and private, depending on user role) collections in a tag set. Not cached because this can change, and load time isn't terrible. :param tag_sets_id: the tag set to query for public collections :return: dict of info and list of collections in ''' if user_has_auth_role(ROLE_MEDIA_EDIT): info = apicache.tag_set_with_private_collections( user_mediacloud_key(), tag_sets_id) else: info = apicache.tag_set_with_public_collections( user_mediacloud_key(), tag_sets_id) add_user_favorite_flag_to_collections(info['tags']) # rename to make more sense here info['collections'] = sorted(info['tags'], key=itemgetter('label', 'tag')) del info['tags'] return jsonify(info)
def api_collection_set(tag_sets_id): """ Return a list of all the (public only or public and private, depending on user role) collections in a tag set. Not cached because this can change, and load time isn't terrible. :param tag_sets_id: the tag set to query for public collections :return: dict of info and list of collections in """ if user_has_auth_role(ROLE_MEDIA_EDIT): info = apicache.tag_set_with_private_collections(user_mediacloud_key(), tag_sets_id) else: info = apicache.tag_set_with_public_collections(user_mediacloud_key(), tag_sets_id) add_user_favorite_flag_to_collections(info['tags']) # rename to make more sense here for t in info['tags']: t['sort_key'] = t['label'] if t['label'] else t['tag'] info['collections'] = sorted(info['tags'], key=itemgetter('sort_key')) del info['tags'] return jsonify(info)