def favorite_sources():
    user_mc = user_mediacloud_client()
    user_favorited = db.get_users_lists(user_name(), 'favoriteSources')
    favorited_s = [user_mc.media(media_id) for media_id in user_favorited]
    for s in favorited_s:
        s['isFavorite'] = True
    return jsonify({'list': favorited_s})
示例#2
0
def topic_filter_cascade_list():
    public_topics = sorted_public_topic_list()

    # for t in sorted_public_topics:
    #    t['detailInfo'] = get_topic_info_per_snapshot_timespan(t['topics_id'])

    # check if user had favorites or personal
    user_topics = []
    favorited_topics = []
    results = {'link_ids': []}
    if is_user_logged_in():
        user_mc = user_admin_mediacloud_client()
        link_id = request.args.get('linkId')
        results = user_mc.topicList(link_id=link_id)
        user_topics = results['topics']
        favorite_topic_ids = db.get_users_lists(user_name(), 'favorite'
                                                'Topics')
        # mark all the public topics as favorite or not
        for t in public_topics:
            t['isFavorite'] = t['topics_id'] in favorite_topic_ids
        # mark all the user's topics as favorite or not
        for t in user_topics:
            t['isFavorite'] = t['topics_id'] in favorite_topic_ids
        # fill in the list of favorite topics (need to hit server because they might no be in the other results)
        favorited_topics = [user_mc.topic(tid) for tid in favorite_topic_ids]
        for t in favorited_topics:
            t['isFavorite'] = True
    return jsonify({
        'topics': {
            'favorite': favorited_topics,
            'personal': user_topics,
            'public': public_topics
        },
        'link_ids': results['link_ids']
    })
def favorite_collections():
    user_mc = user_mediacloud_client()
    user_favorited = db.get_users_lists(user_name(), 'favoriteCollections')
    favorited_collections = [user_mc.tag(tag_id) for tag_id in user_favorited]
    for s in favorited_collections:
        s['isFavorite'] = True
    return jsonify({'list': favorited_collections})
示例#4
0
def favorite_topics():
    user_mc = user_admin_mediacloud_client()
    user_favorited = db.get_users_lists(user_name(), 'favoriteTopics')
    favorited_topics = [user_mc.topic(topic_id) for topic_id in user_favorited]
    for t in favorited_topics:
        t['isFavorite'] = True
        t['detailInfo'] = get_topic_info_per_snapshot_timespan(t['topics_id'])
    return jsonify({'topics': favorited_topics})
示例#5
0
def download_favorite_sources():
    user_mc = user_admin_mediacloud_client()
    user_favorited = db.get_users_lists(user_name(), 'favoriteSources')
    favorited_s = [user_mc.media(media_id) for media_id in user_favorited]
    for s in favorited_s:
        s['isFavorite'] = True

    filename = "FavoriteSources.csv"
    return download_sources_csv(favorited_s, filename)
def add_user_favorite_flag_to_sources(sources):
    user_favorited = db.get_users_lists(user_name(), 'favoriteSources')
    for s in sources:
        s['isFavorite'] = int(s['media_id']) in user_favorited
    return sources
def add_user_favorite_flag_to_collections(collections):
    user_favorited = db.get_users_lists(user_name(), 'favoriteCollections')
    for c in collections:
        c['isFavorite'] = int(c['tags_id']) in user_favorited
    return collections
示例#8
0
def load_user_searches():
    username = user_name()
    search_list = db.get_users_lists(username, 'searches')
    return jsonify({'list': search_list})
示例#9
0
def _add_user_favorite_flag_to_topics(topics):
    user_favorited = db.get_users_lists(user_name(), 'favoriteTopics')
    for t in topics:
        t['isFavorite'] = t['topics_id'] in user_favorited
    return topics