black format
This commit is contained in:
@@ -22,7 +22,7 @@ def authentication(username, password):
|
||||
|
||||
# perform the Bind operation
|
||||
if not c.bind():
|
||||
print('error in bind', c.result)
|
||||
print("error in bind", c.result)
|
||||
|
||||
if c.extend.standard.who_am_i():
|
||||
return username
|
||||
|
||||
@@ -174,7 +174,9 @@ class Etherpad(models.Model):
|
||||
self.etherpad_key = create_pad(pad_name)
|
||||
|
||||
if self.etherpad_key is None:
|
||||
raise ValidationError(f"Etherpad '{pad_name}' konnte nicht erstellt werden. This should never happen!")
|
||||
raise ValidationError(
|
||||
f"Etherpad '{pad_name}' konnte nicht erstellt werden. This should never happen!"
|
||||
)
|
||||
|
||||
@property
|
||||
def etherpad_html(self):
|
||||
|
||||
@@ -17,7 +17,11 @@ class ActiveMemberForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
member_qs = self.fields["member"].queryset.filter(role="A").order_by("firstname", "surname")
|
||||
member_qs = (
|
||||
self.fields["member"]
|
||||
.queryset.filter(role="A")
|
||||
.order_by("firstname", "surname")
|
||||
)
|
||||
self.fields["member"].queryset = member_qs
|
||||
|
||||
|
||||
|
||||
@@ -3,51 +3,54 @@ from elasticsearch import Elasticsearch, helpers
|
||||
import contextlib
|
||||
import logging
|
||||
import elasticsearch
|
||||
ELASTIC_HOST = os.environ.get("ELASTIC_HOST","http://elastic:9200")
|
||||
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD","*l9qNGoojiCC4n9KcZhj")
|
||||
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY","Anwesend")
|
||||
ELASTIC_INDEX = os.environ.get("ELASTIC_INDEX","legacy")
|
||||
|
||||
ELASTIC_HOST = os.environ.get("ELASTIC_HOST", "http://elastic:9200")
|
||||
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD", "*l9qNGoojiCC4n9KcZhj")
|
||||
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY", "Anwesend")
|
||||
ELASTIC_INDEX = os.environ.get("ELASTIC_INDEX", "legacy")
|
||||
|
||||
elasticsearch.logger.setLevel(elasticsearch.logging.WARN)
|
||||
|
||||
# Verbinde mit Client
|
||||
@contextlib.contextmanager
|
||||
def es_client():
|
||||
logging.debug(f"ELASIC HOST:%s" % ELASTIC_HOST)
|
||||
client = Elasticsearch(ELASTIC_HOST, verify_certs=False, basic_auth=('elastic', ELASTIC_PASSWORD))
|
||||
yield client
|
||||
client.close()
|
||||
logging.debug(f"ELASIC HOST:%s" % ELASTIC_HOST)
|
||||
client = Elasticsearch(
|
||||
ELASTIC_HOST, verify_certs=False, basic_auth=("elastic", ELASTIC_PASSWORD)
|
||||
)
|
||||
yield client
|
||||
client.close()
|
||||
|
||||
|
||||
def es_query(query:str):
|
||||
query ={
|
||||
"multi_match":{
|
||||
"query": query,
|
||||
#"fields": ["title^20","text^3"],
|
||||
"fields": ["title^20","title.ngrams^5","text^3","text.ngrams"],
|
||||
"type": "most_fields"
|
||||
}
|
||||
def es_query(query: str):
|
||||
query = {
|
||||
"multi_match": {
|
||||
"query": query,
|
||||
# "fields": ["title^20","text^3"],
|
||||
"fields": ["title^20", "title.ngrams^5", "text^3", "text.ngrams"],
|
||||
"type": "most_fields",
|
||||
}
|
||||
return query
|
||||
}
|
||||
return query
|
||||
|
||||
|
||||
def es_highlight():
|
||||
highlight = {
|
||||
"fields": {
|
||||
"title": {},
|
||||
"text": {}
|
||||
}
|
||||
}
|
||||
return highlight
|
||||
highlight = {"fields": {"title": {}, "text": {}}}
|
||||
return highlight
|
||||
|
||||
|
||||
class SearchObject:
|
||||
def get_model_name(self):
|
||||
return "SearchObject"
|
||||
def __init__(self, res):
|
||||
self.title= res.get("_source",{}).get("title","")
|
||||
self.url= res.get("_source",{}).get("url","")
|
||||
self.text= res.get("_source",{}).get("text","")
|
||||
self.raw= res.get("_source",{}).get("raw","")
|
||||
self.highlight=res.get("highlight",{}).get("title",[""]) + res.get("highlight",{}).get("text",[""])
|
||||
|
||||
def __init__(self, res):
|
||||
self.title = res.get("_source", {}).get("title", "")
|
||||
self.url = res.get("_source", {}).get("url", "")
|
||||
self.text = res.get("_source", {}).get("text", "")
|
||||
self.raw = res.get("_source", {}).get("raw", "")
|
||||
self.highlight = res.get("highlight", {}).get("title", [""]) + res.get(
|
||||
"highlight", {}
|
||||
).get("text", [""])
|
||||
|
||||
|
||||
def es_sorting():
|
||||
@@ -62,7 +65,8 @@ def es_sorting():
|
||||
}
|
||||
}
|
||||
|
||||
def es_search(query:str):
|
||||
|
||||
def es_search(query: str):
|
||||
logging.debug(f"Run Search for legacy :%s" % query)
|
||||
with es_client() as client:
|
||||
result = client.search(
|
||||
@@ -75,5 +79,6 @@ def es_search(query:str):
|
||||
logging.debug(result.keys())
|
||||
return [SearchObject(r) for r in result["hits"]["hits"]]
|
||||
|
||||
#for hit in resp["hits"]["hits"]:
|
||||
|
||||
# for hit in resp["hits"]["hits"]:
|
||||
# print(hit)
|
||||
Reference in New Issue
Block a user