Esempio n. 1
0
def ings_search(request):
    """ """
    if not request.is_ajax():
        return HttpResponse(status=400)
    if request.method != 'POST':
        return JsonResponse(data={"error": "Bad Request"}, status=400)
    data = request.POST.get('params', None)
    content = {'data': []}
    if data:
        params = []
        for astr in data.split(','):
            params.append(RE_ONLY_ALPHA_AND_SPACE.sub('', astr.lower()).split(' '))
        params_ids = word_dao.search(params)
        products = product_dao.search(params_ids)
        ingredient_list = []
        for product in products:
            ingredient_list.append(product['product'])
        dummy_ingredients = set(ingredient_list)
        ingredients = ingredient_dao.search(dummy_ingredients)
        for ingredient in ingredients:
            content['data'].append(ingredient)
    return JsonResponse(data=content, status=200)
Esempio n. 2
0
def str_clean_and_lowcase(astr):
    """ Очистка и преобразование строки к нижнему регистру """
    astr = RE_ONLY_ONE_SPACE.sub(' ', 
                RE_ONLY_ALPHA_AND_SPACE.sub('', astr.lower()))
    return astr.strip()