black format
This commit is contained in:
@@ -22,7 +22,7 @@ def authentication(username, password):
|
|||||||
|
|
||||||
# perform the Bind operation
|
# perform the Bind operation
|
||||||
if not c.bind():
|
if not c.bind():
|
||||||
print('error in bind', c.result)
|
print("error in bind", c.result)
|
||||||
|
|
||||||
if c.extend.standard.who_am_i():
|
if c.extend.standard.who_am_i():
|
||||||
return username
|
return username
|
||||||
|
|||||||
@@ -174,7 +174,9 @@ class Etherpad(models.Model):
|
|||||||
self.etherpad_key = create_pad(pad_name)
|
self.etherpad_key = create_pad(pad_name)
|
||||||
|
|
||||||
if self.etherpad_key is None:
|
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
|
@property
|
||||||
def etherpad_html(self):
|
def etherpad_html(self):
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ class ActiveMemberForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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
|
self.fields["member"].queryset = member_qs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ from elasticsearch import Elasticsearch, helpers
|
|||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
ELASTIC_HOST = os.environ.get("ELASTIC_HOST","http://elastic:9200")
|
|
||||||
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD","*l9qNGoojiCC4n9KcZhj")
|
ELASTIC_HOST = os.environ.get("ELASTIC_HOST", "http://elastic:9200")
|
||||||
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY","Anwesend")
|
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD", "*l9qNGoojiCC4n9KcZhj")
|
||||||
ELASTIC_INDEX = os.environ.get("ELASTIC_INDEX","legacy")
|
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY", "Anwesend")
|
||||||
|
ELASTIC_INDEX = os.environ.get("ELASTIC_INDEX", "legacy")
|
||||||
|
|
||||||
elasticsearch.logger.setLevel(elasticsearch.logging.WARN)
|
elasticsearch.logger.setLevel(elasticsearch.logging.WARN)
|
||||||
|
|
||||||
@@ -14,40 +15,42 @@ elasticsearch.logger.setLevel(elasticsearch.logging.WARN)
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def es_client():
|
def es_client():
|
||||||
logging.debug(f"ELASIC HOST:%s" % ELASTIC_HOST)
|
logging.debug(f"ELASIC HOST:%s" % ELASTIC_HOST)
|
||||||
client = Elasticsearch(ELASTIC_HOST, verify_certs=False, basic_auth=('elastic', ELASTIC_PASSWORD))
|
client = Elasticsearch(
|
||||||
|
ELASTIC_HOST, verify_certs=False, basic_auth=("elastic", ELASTIC_PASSWORD)
|
||||||
|
)
|
||||||
yield client
|
yield client
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
|
||||||
def es_query(query:str):
|
def es_query(query: str):
|
||||||
query ={
|
query = {
|
||||||
"multi_match":{
|
"multi_match": {
|
||||||
"query": query,
|
"query": query,
|
||||||
#"fields": ["title^20","text^3"],
|
# "fields": ["title^20","text^3"],
|
||||||
"fields": ["title^20","title.ngrams^5","text^3","text.ngrams"],
|
"fields": ["title^20", "title.ngrams^5", "text^3", "text.ngrams"],
|
||||||
"type": "most_fields"
|
"type": "most_fields",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
def es_highlight():
|
def es_highlight():
|
||||||
highlight = {
|
highlight = {"fields": {"title": {}, "text": {}}}
|
||||||
"fields": {
|
|
||||||
"title": {},
|
|
||||||
"text": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return highlight
|
return highlight
|
||||||
|
|
||||||
|
|
||||||
class SearchObject:
|
class SearchObject:
|
||||||
def get_model_name(self):
|
def get_model_name(self):
|
||||||
return "SearchObject"
|
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():
|
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)
|
logging.debug(f"Run Search for legacy :%s" % query)
|
||||||
with es_client() as client:
|
with es_client() as client:
|
||||||
result = client.search(
|
result = client.search(
|
||||||
@@ -75,5 +79,6 @@ def es_search(query:str):
|
|||||||
logging.debug(result.keys())
|
logging.debug(result.keys())
|
||||||
return [SearchObject(r) for r in result["hits"]["hits"]]
|
return [SearchObject(r) for r in result["hits"]["hits"]]
|
||||||
|
|
||||||
#for hit in resp["hits"]["hits"]:
|
|
||||||
|
# for hit in resp["hits"]["hits"]:
|
||||||
# print(hit)
|
# print(hit)
|
||||||
Reference in New Issue
Block a user