mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-31 20:00:38 -05:00
Merge branch 'develop' into draggable_pill_update
This commit is contained in:
@@ -189,9 +189,14 @@ class MergeMixin(ViewSetMixin): # TODO update Units to use merge API
|
||||
# a new scenario exists and needs to be handled
|
||||
raise NotImplementedError
|
||||
if isTree:
|
||||
if self.model.node_order_by:
|
||||
node_location = 'sorted-child'
|
||||
else:
|
||||
node_location = 'last-child'
|
||||
|
||||
children = source.get_children().exclude(id=target.id)
|
||||
for c in children:
|
||||
c.move(target, 'last-child')
|
||||
c.move(target, node_location)
|
||||
content = {'msg': _(f'{source.name} was merged successfully with {target.name}')}
|
||||
source.delete()
|
||||
return Response(content, status=status.HTTP_200_OK)
|
||||
@@ -232,6 +237,10 @@ class TreeMixin(MergeMixin, FuzzyFilterMixin):
|
||||
@decorators.renderer_classes((TemplateHTMLRenderer, JSONRenderer))
|
||||
def move(self, request, pk, parent):
|
||||
self.description = f"Move {self.basename} to be a child of {self.basename} with ID of [int]. Use ID: 0 to move {self.basename} to the root."
|
||||
if self.model.node_order_by:
|
||||
node_location = 'sorted'
|
||||
else:
|
||||
node_location = 'last'
|
||||
|
||||
try:
|
||||
child = self.model.objects.get(pk=pk, space=self.request.space)
|
||||
@@ -244,7 +253,7 @@ class TreeMixin(MergeMixin, FuzzyFilterMixin):
|
||||
if parent == 0:
|
||||
try:
|
||||
with scopes_disabled():
|
||||
child.move(self.model.get_first_root_node(), 'last-sibling')
|
||||
child.move(self.model.get_first_root_node(), f'{node_location}-sibling')
|
||||
content = {'msg': _(f'{child.name} was moved successfully to the root.')}
|
||||
return Response(content, status=status.HTTP_200_OK)
|
||||
except (PathOverflow, InvalidMoveToDescendant, InvalidPosition):
|
||||
@@ -262,7 +271,7 @@ class TreeMixin(MergeMixin, FuzzyFilterMixin):
|
||||
|
||||
try:
|
||||
with scopes_disabled():
|
||||
child.move(parent, 'last-child')
|
||||
child.move(parent, f'{node_location}-child')
|
||||
content = {'msg': _(f'{child.name} was moved successfully to parent {parent.name}')}
|
||||
return Response(content, status=status.HTTP_200_OK)
|
||||
except (PathOverflow, InvalidMoveToDescendant, InvalidPosition):
|
||||
|
||||
@@ -18,10 +18,11 @@ from requests.exceptions import MissingSchema
|
||||
|
||||
from cookbook.forms import BatchEditForm, SyncForm
|
||||
from cookbook.helper.image_processing import handle_image
|
||||
from cookbook.helper.ingredient_parser import IngredientParser
|
||||
from cookbook.helper.permission_helper import group_required, has_group_permission
|
||||
from cookbook.helper.recipe_url_import import parse_cooktime
|
||||
from cookbook.models import (Comment, Food, Ingredient, Keyword, Recipe,
|
||||
RecipeImport, Step, Sync, Unit, UserPreference, Automation)
|
||||
RecipeImport, Step, Sync, Unit, UserPreference)
|
||||
from cookbook.tables import SyncTable
|
||||
|
||||
|
||||
@@ -152,21 +153,16 @@ def import_url(request):
|
||||
k, created = Keyword.objects.get_or_create(name=kw['text'], space=request.space)
|
||||
recipe.keywords.add(k)
|
||||
|
||||
ingredient_parser = IngredientParser(request, True)
|
||||
for ing in data['recipeIngredient']:
|
||||
ingredient = Ingredient(space=request.space, )
|
||||
|
||||
if food_text := ing['ingredient']['text'].strip():
|
||||
if automation := Automation.objects.filter(space=request.space, type=Automation.FOOD_ALIAS, param_1=food_text).first():
|
||||
ingredient.food.id = automation.param_2
|
||||
else:
|
||||
ingredient.food, f_created = Food.objects.get_or_create(name=food_text, space=request.space)
|
||||
ingredient.food = ingredient_parser.get_food(food_text)
|
||||
|
||||
if ing['unit']:
|
||||
if unit_text := ing['unit']['text']:
|
||||
if automation := Automation.objects.filter(space=request.space, type=Automation.UNIT_ALIAS, param_1=unit_text).first():
|
||||
ingredient.unit.id = automation.param_2
|
||||
else:
|
||||
ingredient.unit, u_created = Unit.objects.get_or_create(name=unit_text, space=request.space)
|
||||
if unit_text := ing['unit']['text'].strip():
|
||||
ingredient.unit = ingredient_parser.get_unit(unit_text)
|
||||
|
||||
# TODO properly handle no_amount recipes
|
||||
if isinstance(ing['amount'], str):
|
||||
|
||||
@@ -29,7 +29,7 @@ from cookbook.forms import (CommentForm, Recipe, User,
|
||||
from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission
|
||||
from cookbook.models import (Comment, CookLog, InviteLink, MealPlan,
|
||||
ViewLog, ShoppingList, Space, Keyword, RecipeImport, Unit,
|
||||
Food, UserFile, ShareLink)
|
||||
Food, UserFile, ShareLink, SearchPreference, SearchFields)
|
||||
from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall,
|
||||
ViewLogTable, InviteLinkTable)
|
||||
from cookbook.views.data import Object
|
||||
@@ -219,10 +219,12 @@ def books(request):
|
||||
def meal_plan(request):
|
||||
return render(request, 'meal_plan.html', {})
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def meal_plan_new(request):
|
||||
return render(request, 'meal_plan_new.html', {})
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def supermarket(request):
|
||||
return render(request, 'supermarket.html', {})
|
||||
@@ -344,11 +346,11 @@ def user_settings(request):
|
||||
if not sp:
|
||||
sp = SearchPreferenceForm(user=request.user)
|
||||
fields_searched = (
|
||||
len(search_form.cleaned_data['icontains'])
|
||||
+ len(search_form.cleaned_data['istartswith'])
|
||||
+ len(search_form.cleaned_data['trigram'])
|
||||
+ len(search_form.cleaned_data['fulltext']))
|
||||
# TODO add 'recommended' option
|
||||
len(search_form.cleaned_data['icontains'])
|
||||
+ len(search_form.cleaned_data['istartswith'])
|
||||
+ len(search_form.cleaned_data['trigram'])
|
||||
+ len(search_form.cleaned_data['fulltext'])
|
||||
)
|
||||
if fields_searched == 0:
|
||||
search_form.add_error(None, _('You must select at least one field to search!'))
|
||||
search_error = True
|
||||
@@ -366,6 +368,27 @@ def user_settings(request):
|
||||
sp.istartswith.set(search_form.cleaned_data['istartswith'])
|
||||
sp.trigram.set(search_form.cleaned_data['trigram'])
|
||||
sp.fulltext.set(search_form.cleaned_data['fulltext'])
|
||||
sp.trigram_threshold = search_form.cleaned_data['trigram_threshold']
|
||||
|
||||
if search_form.cleaned_data['preset'] == 'fuzzy':
|
||||
sp.search = SearchPreference.SIMPLE
|
||||
sp.lookup = True
|
||||
sp.unaccent.set([SearchFields.objects.get(name='Name')])
|
||||
sp.icontains.set([SearchFields.objects.get(name='Name')])
|
||||
sp.istartswith.clear()
|
||||
sp.trigram.set([SearchFields.objects.get(name='Name')])
|
||||
sp.fulltext.clear()
|
||||
sp.trigram_threshold = 0.1
|
||||
|
||||
if search_form.cleaned_data['preset'] == 'precise':
|
||||
sp.search = SearchPreference.WEB
|
||||
sp.lookup = True
|
||||
sp.unaccent.set(SearchFields.objects.all())
|
||||
sp.icontains.clear()
|
||||
sp.istartswith.set([SearchFields.objects.get(name='Name')])
|
||||
sp.trigram.clear()
|
||||
sp.fulltext.set(SearchFields.objects.all())
|
||||
sp.trigram_threshold = 0.1
|
||||
|
||||
sp.save()
|
||||
if up:
|
||||
@@ -416,8 +439,8 @@ def history(request):
|
||||
@group_required('admin')
|
||||
def system(request):
|
||||
postgres = False if (
|
||||
settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2' # noqa: E501
|
||||
or settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql' # noqa: E501
|
||||
settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2' # noqa: E501
|
||||
or settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql' # noqa: E501
|
||||
) else True
|
||||
|
||||
secret_key = False if os.getenv('SECRET_KEY') else True
|
||||
|
||||
Reference in New Issue
Block a user