mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2025-02-17 01:50:32 +03:00
fixed after pr
This commit is contained in:
parent
784d6699de
commit
8aef80af48
|
@ -39,7 +39,6 @@ LOCALE_PATHS = [str(APPS_DIR / "locale")]
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||||
DATABASES = {"default": env.db("DATABASE_URL")}
|
DATABASES = {"default": env.db("DATABASE_URL")}
|
||||||
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
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
|
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
@ -217,5 +216,3 @@ REST_FRAMEWORK = {
|
||||||
|
|
||||||
# django-cors-headers
|
# django-cors-headers
|
||||||
CORS_ALLOW_ALL_ORIGINS = True
|
CORS_ALLOW_ALL_ORIGINS = True
|
||||||
|
|
||||||
YANDEX_DICT_API_KEY = "dict.1.1.20221022T010312Z.55cce597a6cfa505.f416aba85e7642eedc1b76b8e21c06506fb17f83"
|
|
||||||
|
|
|
@ -13,8 +13,7 @@ from search.models import (
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from search.services.hints import get_hints
|
from search.services.hints import get_hints
|
||||||
from search.services.spell_check import spell_check
|
from search.services.spell_check import spell_check_ru as spell_check
|
||||||
from search.services.translate import translate_en_ru, translate_ru_en
|
|
||||||
|
|
||||||
|
|
||||||
def process_unit_operation(unit: ProductUnitCharacteristic.objects, operation: str):
|
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)
|
qs = qs.filter(characteristics__in=char)
|
||||||
elif typ == "Unknown":
|
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
|
continue
|
||||||
else:
|
else:
|
||||||
if typ.startswith("*"):
|
if typ.startswith("*"):
|
||||||
|
|
|
@ -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"]])]
|
|
Loading…
Reference in New Issue
Block a user