Пример #1
0
def _index_choices( request, show_missing=False, default=None ):
    """
    @param request: 
    @param show_missing: 
    @param default: choice tuple or None
    """
    # current indices in Elasticsearch
    indices = []
    for index in index_names(settings.DOCSTORE_HOSTS):
        indices.append(index)
    if show_missing:
        # session index
        session_index = None
        if request:
            set_docstore_index(request)
            session_index = request.session.get('docstore_index', None)
            if session_index and (session_index not in indices):
                indices.append(session_index)
        # if current storage has no index
        storage_label = request.session.get('storage_label', None)
        if request and storage_label:
            if storage_label:
                store_index = make_index_name(storage_label)
                if store_index and (store_index not in indices):
                    indices.append(store_index)
    # make list of tuples for choices menu
    choices = [(index,index) for index in indices]
    if default:
        choices.insert(0, default)
    return choices
Пример #2
0
def set_docstore_index( request ):
    """Ensure active Elasticsearch index matches active storage; complain if not.
    
    Look at mounted storage. Make an index name based on that.
    If mounted and corresponding index exists in Elasticsearch, make sure it's
    in session.  If index is in session but storage not mounted or Elasticearch
    index doesn't exist, remove from session.
    
    storage_label: label of storage currently in session
    docstore_index_exists: Elasticsearch index exists for storage_label (or not)
    
    @param request:
    @returns: storage_label,docstore_index_exists
    """
    # gather info
    docstore_index = None
    docstore_index_exists = None
    storage_label = request.session.get('storage_label', None)
    if not storage_label:
        storage_label = target_index(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX)
    if storage_label:
        docstore_index = make_index_name(storage_label)
        if docstore_index:
            docstore_index_exists = index_exists(settings.DOCSTORE_HOSTS, docstore_index)
    # rm index from session
    if not (storage_label or docstore_index_exists):
        request.session['docstore_index'] = None
    # add index to session
    if storage_label and docstore_index_exists and not request.session.get('docstore_index',None):
        request.session['docstore_index'] = docstore_index
    return storage_label,docstore_index_exists
Пример #3
0
def test_make_index_name():
    assert docstore.make_index_name('abc-def_ghi.jkl/mno\\pqr stu') == 'abc-def_ghi.jkl-mno-pqrstu'
    assert docstore.make_index_name('qnfs/kinkura/gold') == 'qnfs-kinkura-gold'
Пример #4
0
def test_make_index_name():
    assert docstore.make_index_name(
        'abc-def_ghi.jkl/mno\\pqr stu') == 'abc-def_ghi.jkl-mno-pqrstu'
    assert docstore.make_index_name('qnfs/kinkura/gold') == 'qnfs-kinkura-gold'