mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
Citadel: Use new search backend active check
And more important, do not access the DB during app initialization
This commit is contained in:
parent
aa0389567b
commit
ed3eb176d4
@ -5,7 +5,6 @@
|
||||
# them and/or modify them under the terms of the MIT License;
|
||||
# see the LICENSE file for more details.
|
||||
|
||||
from flask import current_app
|
||||
from wtforms.fields.core import BooleanField
|
||||
from wtforms.fields.html5 import IntegerField, URLField
|
||||
from wtforms.validators import URL, DataRequired, NumberRange
|
||||
@ -85,13 +84,9 @@ class CitadelPlugin(LiveSyncPluginBase):
|
||||
self.connect(signals.get_search_providers, self.get_search_providers)
|
||||
self.connect(signals.plugin.cli, self._extend_indico_cli)
|
||||
|
||||
def _is_configured(self):
|
||||
return bool(self.settings.get('search_backend_url')) and bool(self.settings.get('search_backend_token'))
|
||||
|
||||
def get_search_providers(self, sender, **kwargs):
|
||||
from indico_citadel.search import CitadelProvider
|
||||
if current_app.config['TESTING'] or (not self.settings.get('disable_search') and self._is_configured()):
|
||||
return CitadelProvider
|
||||
return CitadelProvider
|
||||
|
||||
def _extend_indico_cli(self, sender, **kwargs):
|
||||
return cli
|
||||
|
||||
@ -9,10 +9,12 @@ import base64
|
||||
import zlib
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
from requests.exceptions import RequestException
|
||||
from werkzeug.urls import url_join
|
||||
|
||||
from indico.modules.search.base import IndicoSearchProvider, SearchOption
|
||||
from indico.util.decorators import classproperty
|
||||
|
||||
from indico_citadel import _
|
||||
from indico_citadel.result_schemas import CitadelResultSchema
|
||||
@ -28,6 +30,17 @@ class CitadelProvider(IndicoSearchProvider):
|
||||
self.backend_url = CitadelPlugin.settings.get('search_backend_url')
|
||||
self.records_url = url_join(self.backend_url, 'api/records/')
|
||||
|
||||
@classproperty
|
||||
@classmethod
|
||||
def active(cls):
|
||||
from indico_citadel.plugin import CitadelPlugin
|
||||
if current_app.config['TESTING']:
|
||||
return True
|
||||
elif CitadelPlugin.settings.get('disable_search'):
|
||||
return False
|
||||
return bool(CitadelPlugin.settings.get('search_backend_url') and
|
||||
CitadelPlugin.settings.get('search_backend_token'))
|
||||
|
||||
def search(self, query, user=None, page=1, object_types=(), **params):
|
||||
# https://cern-search.docs.cern.ch/usage/operations/#query-documents
|
||||
# this token is used by the backend to authenticate and also to filter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user