Exemplo n.º 1
0
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})
Exemplo n.º 2
0
def api_mediapicker_collection_search():
    t0 = time.time()
    use_pool = None
    add_source_counts = False
    public_only = False if user_has_auth_role(ROLE_MEDIA_EDIT) else True
    search_str = request.args['media_keyword']
    tag_sets_id_list = request.args['which_set'].split(',')
    t1 = time.time()
    results = collection_search(search_str, public_only, tag_sets_id_list)
    t2 = time.time()
    trimmed_collections = results[:MAX_COLLECTIONS]
    # flat_list_of_collections = [item for sublist in trimmed_collections for item in sublist]
    set_of_queried_collections = []
    if add_source_counts:
        if len(trimmed_collections) > 0:
            if use_pool:
                pool = Pool(processes=STORY_COUNT_POOL_SIZE)
                set_of_queried_collections = pool.map(collection_details_worker, trimmed_collections)
                pool.close()
            else:
                set_of_queried_collections = [collection_details_worker(c) for c in trimmed_collections]
    else:
        # skip adding in the source count details all together
        set_of_queried_collections = trimmed_collections
    t3 = time.time()
    if use_pool is not None:
        set_of_queried_collections = sorted(set_of_queried_collections, key=itemgetter('media_count'), reverse=True)
    t4 = time.time()
    logger.debug("total: {}".format(t4 - t0))
    logger.debug("  load: {}".format(t1-t0))
    logger.debug("  search: {}".format(t2 - t1))
    logger.debug("  media_count: {}".format(t3 - t2))
    logger.debug("  sort: {}".format(t4 - t3))
    return jsonify({'list': set_of_queried_collections})
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
def api_collections_name_exists():
    """
    Check if source with name/url exists already
    :return: boolean indicating if source with this name exists or not (case insensive check)
    """
    search_str = request.args['searchStr']
    tags_id = int(request.args['id']) if 'id' in request.args else None
    matching_collections = collection_search(search_str, False, VALID_COLLECTION_TAG_SETS_IDS)[:MAX_SOURCES]
    if tags_id:
        matching_collections_names = [s['label'].lower().strip() for s in matching_collections
                                      if s['tags_id'] != tags_id]
    else:
        matching_collections_names = [s['label'].lower().strip() for s in matching_collections]

    name_in_use = search_str.lower() in matching_collections_names
    return jsonify({'nameInUse': name_in_use})
Exemplo n.º 5
0
def api_mediapicker_collection_search():
    t0 = time.time()
    use_pool = None
    add_source_counts = False
    public_only = False if user_has_auth_role(ROLE_MEDIA_EDIT) else True
    search_str = request.args['media_keyword']
    tag_sets_id_list = request.args['which_set'].split(',')
    t1 = time.time()
    results = collection_search(search_str, public_only, tag_sets_id_list)
    t2 = time.time()
    trimmed_collections = results[:MAX_COLLECTIONS]
    # flat_list_of_collections = [item for sublist in trimmed_collections for item in sublist]
    set_of_queried_collections = []
    if add_source_counts:
        if len(trimmed_collections) > 0:
            if use_pool:
                pool = Pool(processes=STORY_COUNT_POOL_SIZE)
                set_of_queried_collections = pool.map(
                    collection_details_worker, trimmed_collections)
                pool.close()
            else:
                set_of_queried_collections = [
                    collection_details_worker(c) for c in trimmed_collections
                ]
    else:
        # skip adding in the source count details all together
        set_of_queried_collections = trimmed_collections
    t3 = time.time()
    if use_pool is not None:
        set_of_queried_collections = sorted(set_of_queried_collections,
                                            key=itemgetter('media_count'),
                                            reverse=True)
    t4 = time.time()
    logger.debug("total: {}".format(t4 - t0))
    logger.debug("  load: {}".format(t1 - t0))
    logger.debug("  search: {}".format(t2 - t1))
    logger.debug("  media_count: {}".format(t3 - t2))
    logger.debug("  sort: {}".format(t4 - t3))
    return jsonify({'list': set_of_queried_collections})