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
def inner(request, *args, **kwargs): s = " " d = " " try: storage_label, docstore_index_exists = set_docstore_index(request) except TransportError: storage_label = "e" docstore_index_exists = "e" if storage_label and (storage_label == "e"): s = "e" elif storage_label: s = "s" if docstore_index_exists and (docstore_index_exists == "e"): d = "e" elif docstore_index_exists: d = "d" key = "".join([s, d]) error_messages = { "sd": (None), # nothing to see here, move along "s ": ("No search index for %s. Search is disabled. Please reindex." % (storage_label)), " d": ("No storage devices mounted. Search is disabled."), " ": ("No storage devices mounted and no search index. Search is disabled."), "ee": ("Cannot connect to Elasticsearch. Search is disabled."), } msg = error_messages[key] if msg: messages.warning(request, msg, extra_tags="bottom") return func(request, *args, **kwargs)
def inner(request, *args, **kwargs): storage_label,docstore_index_exists = set_docstore_index(request) s = ' '; d = ' ' if storage_label: s = 's' if docstore_index_exists: d = 'd' key = ''.join([s,d]) error_messages = { 'sd': None, # nothing to see here, move along 's ': 'No search index for %s. Search is disabled. Please reindex.' % (storage_label), ' d': 'No storage devices mounted. Search is disabled.', ' ': 'No storage devices mounted and no search index. Search is disabled.', } msg = error_messages[key] if msg: messages.warning(request, msg) return func(request, *args, **kwargs)