mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-31 20:00:38 -05:00
converted ingredient parser to class and added automation beta hint
This commit is contained in:
@@ -31,7 +31,7 @@ from rest_framework.viewsets import ViewSetMixin
|
||||
from treebeard.exceptions import PathOverflow, InvalidMoveToDescendant, InvalidPosition
|
||||
|
||||
from cookbook.helper.image_processing import handle_image
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.ingredient_parser import IngredientParser
|
||||
from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest,
|
||||
CustomIsOwner, CustomIsShare,
|
||||
CustomIsShared, CustomIsUser,
|
||||
@@ -853,11 +853,11 @@ def recipe_from_source(request):
|
||||
},
|
||||
status=400)
|
||||
else:
|
||||
return JsonResponse({"recipe_json": get_from_scraper(scrape, request.space)})
|
||||
return JsonResponse({"recipe_json": get_from_scraper(scrape, request)})
|
||||
elif (mode == 'source') or (mode == 'url' and auto == 'false'):
|
||||
if not data or data == 'undefined':
|
||||
data = requests.get(url, headers=HEADERS).content
|
||||
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(data, url, request.space)
|
||||
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(data, url, request)
|
||||
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
||||
return JsonResponse(
|
||||
{
|
||||
@@ -893,7 +893,9 @@ def get_backup(request):
|
||||
@group_required('user')
|
||||
def ingredient_from_string(request):
|
||||
text = request.POST['text']
|
||||
amount, unit, food, note = parse(text)
|
||||
|
||||
ingredient_parser = IngredientParser(request, False)
|
||||
amount, unit, food, note = ingredient_parser.parse(text)
|
||||
|
||||
return JsonResponse(
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse, get_unit, get_food
|
||||
from cookbook.helper.ingredient_parser import IngredientParser
|
||||
from cookbook.helper.permission_helper import group_required
|
||||
from cookbook.models import TelegramBot, ShoppingList, ShoppingListEntry
|
||||
|
||||
@@ -49,9 +49,12 @@ def hook(request, token):
|
||||
if not sl:
|
||||
sl = ShoppingList.objects.create(created_by=tb.created_by, space=tb.space)
|
||||
|
||||
amount, unit, ingredient, note = parse(data['message']['text'])
|
||||
f = get_food(ingredient, tb.space)
|
||||
u = get_unit(unit, tb.space)
|
||||
request.space = tb.space # TODO this is likely a bad idea. Verify and test
|
||||
request.user = tb.created_by
|
||||
ingredient_parser = IngredientParser(request, False)
|
||||
amount, unit, ingredient, note = ingredient_parser.parse(data['message']['text'])
|
||||
f = ingredient_parser.get_food(ingredient)
|
||||
u = ingredient_parser.get_unit(unit)
|
||||
sl.entries.add(
|
||||
ShoppingListEntry.objects.create(
|
||||
food=f, unit=u, amount=amount
|
||||
|
||||
@@ -26,10 +26,9 @@ from cookbook.forms import (CommentForm, Recipe, User,
|
||||
UserCreateForm, UserNameForm, UserPreference,
|
||||
UserPreferenceForm, SpaceJoinForm, SpaceCreateForm,
|
||||
SearchPreferenceForm)
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission
|
||||
from cookbook.models import (Comment, CookLog, InviteLink, MealPlan,
|
||||
RecipeBook, RecipeBookEntry, ViewLog, ShoppingList, Space, Keyword, RecipeImport, Unit,
|
||||
ViewLog, ShoppingList, Space, Keyword, RecipeImport, Unit,
|
||||
Food, UserFile, ShareLink)
|
||||
from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall,
|
||||
ViewLogTable, InviteLinkTable)
|
||||
|
||||
Reference in New Issue
Block a user