fixed after pr

This commit is contained in:
Alexander Karpov 2022-10-22 18:33:33 +03:00
parent 784d6699de
commit 8aef80af48
3 changed files with 1 additions and 38 deletions

View File

@ -39,7 +39,6 @@ LOCALE_PATHS = [str(APPS_DIR / "locale")]
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {"default": env.db("DATABASE_URL")}
DATABASES["default"]["ATOMIC_REQUESTS"] = True
YANDEX_DICT_API_KEY = env.str('YANDEX_DICT')
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
@ -217,5 +216,3 @@ REST_FRAMEWORK = {
# django-cors-headers
CORS_ALLOW_ALL_ORIGINS = True
YANDEX_DICT_API_KEY = "dict.1.1.20221022T010312Z.55cce597a6cfa505.f416aba85e7642eedc1b76b8e21c06506fb17f83"

View File

@ -13,8 +13,7 @@ from search.models import (
from typing import List
from search.services.hints import get_hints
from search.services.spell_check import spell_check
from search.services.translate import translate_en_ru, translate_ru_en
from search.services.spell_check import spell_check_ru as spell_check
def process_unit_operation(unit: ProductUnitCharacteristic.objects, operation: str):
@ -179,21 +178,6 @@ def process_search(data: List[dict], limit=5, offset=0) -> List[dict]:
)
qs = qs.filter(characteristics__in=char)
elif typ == "Unknown":
if val[0] in string.printable:
val = "".join(translate_en_ru(val))
else:
val = "".join(translate_ru_en(val))
type = get_hints(val)
if type == "Name":
qs = apply_qs_search(qs, val)
elif type == "Category":
qs = qs.filter(category__name__unaccent__trigram_similar=val)
elif type == "Unknown":
continue
else:
qs = qs.filter(
characteristics__characteristic__name__unaccent__trigram_similar=val
)
continue
else:
if typ.startswith("*"):

View File

@ -1,18 +0,0 @@
import requests as r
from conf.settings.base import YANDEX_DICT_API_KEY
from itertools import chain
from typing import List
def translate_ru_en(word: str) -> List[str]:
res = r.get(
f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=ru-en&text={word}"
)
return [i["text"] for i in chain(*[j["tr"] for j in res.json()["def"]])]
def translate_en_ru(word: str) -> List[str]:
res = r.get(
f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=en-ru&text={word}"
)
return [i["text"] for i in chain(*[j["tr"] for j in res.json()["def"]])]