diff --git a/fet2020/authentications/authentications.py b/fet2020/authentications/authentications.py index 96084b5b..91a1e12a 100644 --- a/fet2020/authentications/authentications.py +++ b/fet2020/authentications/authentications.py @@ -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 diff --git a/fet2020/documents/api.py b/fet2020/documents/api.py index 4212dea3..2431d43d 100644 --- a/fet2020/documents/api.py +++ b/fet2020/documents/api.py @@ -82,11 +82,11 @@ def create_pad(padID, text="helloworld"): epc.createGroupPad(groupID=group["groupID"], padName=padID, text=text) logger.info(f"neues Pad erzeugt: {padID}") - + return padID - if __pad_exists(padID=padID): + if __pad_exists(padID=padID): return padID - else: + else: raise Exception("Tried to create pad but failed!") diff --git a/fet2020/intern/models.py b/fet2020/intern/models.py index 48b95ac1..9ce32402 100644 --- a/fet2020/intern/models.py +++ b/fet2020/intern/models.py @@ -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): diff --git a/fet2020/members/forms.py b/fet2020/members/forms.py index 32e3db00..22ecfbec 100644 --- a/fet2020/members/forms.py +++ b/fet2020/members/forms.py @@ -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 diff --git a/fet2020/search/legacy.py b/fet2020/search/legacy.py index aa1b2df0..cd508ebe 100644 --- a/fet2020/search/legacy.py +++ b/fet2020/search/legacy.py @@ -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"]: -# print(hit) \ No newline at end of file + +# for hit in resp["hits"]["hits"]: +# print(hit)