mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 05:39:00 -05:00
renamed recipeingredient to ingredient
This commit is contained in:
@@ -18,10 +18,10 @@ from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin, ListMode
|
||||
|
||||
from cookbook.helper.permission_helper import group_required, CustomIsOwner, CustomIsAdmin, CustomIsUser
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, RecipeIngredient, Food
|
||||
from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, Ingredient, Food
|
||||
from cookbook.provider.dropbox import Dropbox
|
||||
from cookbook.provider.nextcloud import Nextcloud
|
||||
from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, RecipeIngredientSerializer, IngredientSerializer
|
||||
from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, IngredientSerializer, FoodSerializer
|
||||
|
||||
|
||||
class UserNameViewSet(viewsets.ModelViewSet):
|
||||
@@ -134,15 +134,15 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
||||
return queryset
|
||||
|
||||
|
||||
class RecipeIngredientViewSet(viewsets.ModelViewSet):
|
||||
queryset = RecipeIngredient.objects.all()
|
||||
serializer_class = RecipeIngredientSerializer
|
||||
class IngredientViewSet(viewsets.ModelViewSet):
|
||||
queryset = Ingredient.objects.all()
|
||||
serializer_class = IngredientSerializer
|
||||
permission_classes = [CustomIsUser]
|
||||
|
||||
|
||||
class IngredientViewSet(viewsets.ModelViewSet):
|
||||
class FoodViewSet(viewsets.ModelViewSet):
|
||||
queryset = Food.objects.all()
|
||||
serializer_class = IngredientSerializer
|
||||
serializer_class = FoodSerializer
|
||||
permission_classes = [CustomIsUser]
|
||||
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ def import_url(request):
|
||||
# TODO return proper error
|
||||
pass
|
||||
|
||||
RecipeIngredient.objects.create(recipe=recipe, ingredient=i, unit=u, amount=ing['amount'])
|
||||
Ingredient.objects.create(recipe=recipe, ingredient=i, unit=u, amount=ing['amount'])
|
||||
|
||||
if data['image'] != '':
|
||||
response = requests.get(data['image'])
|
||||
|
||||
@@ -19,7 +19,7 @@ from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncFor
|
||||
from cookbook.helper.permission_helper import group_required, GroupRequiredMixin
|
||||
|
||||
from cookbook.helper.permission_helper import OwnerRequiredMixin
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeIngredient, RecipeBook, \
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, Ingredient, RecipeBook, \
|
||||
MealPlan, Unit, Food
|
||||
from cookbook.provider.dropbox import Dropbox
|
||||
from cookbook.provider.nextcloud import Nextcloud
|
||||
@@ -83,10 +83,10 @@ def internal_recipe_update(request, pk):
|
||||
except simplejson.errors.JSONDecodeError:
|
||||
form_ingredients = []
|
||||
|
||||
RecipeIngredient.objects.filter(recipe=recipe_instance).delete()
|
||||
Ingredient.objects.filter(recipe=recipe_instance).delete()
|
||||
|
||||
for i in form_ingredients:
|
||||
recipe_ingredient = RecipeIngredient()
|
||||
recipe_ingredient = Ingredient()
|
||||
recipe_ingredient.recipe = recipe_instance
|
||||
|
||||
if 'note' in i:
|
||||
@@ -95,10 +95,10 @@ def internal_recipe_update(request, pk):
|
||||
if Food.objects.filter(name=i['ingredient__name']).exists():
|
||||
recipe_ingredient.ingredient = Food.objects.get(name=i['ingredient__name'])
|
||||
else:
|
||||
ingredient = Food()
|
||||
ingredient.name = i['ingredient__name']
|
||||
ingredient.save()
|
||||
recipe_ingredient.ingredient = ingredient
|
||||
food = Food()
|
||||
food.name = i['food__name']
|
||||
food.save()
|
||||
recipe_ingredient.ingredient = food
|
||||
|
||||
if isinstance(i['amount'], str):
|
||||
try:
|
||||
@@ -127,7 +127,7 @@ def internal_recipe_update(request, pk):
|
||||
else:
|
||||
form = InternalRecipeForm(instance=recipe_instance)
|
||||
|
||||
ingredients = RecipeIngredient.objects.select_related('unit__name', 'ingredient__name').filter(recipe=recipe_instance).values('ingredient__name', 'unit__name', 'amount', 'note').order_by('id')
|
||||
ingredients = Ingredient.objects.select_related('unit__name', 'food__name').filter(recipe=recipe_instance).values('food__name', 'unit__name', 'amount', 'note').order_by('id')
|
||||
|
||||
return render(request, 'forms/edit_internal_recipe.html',
|
||||
{'form': form, 'ingredients': json.dumps(list(ingredients)),
|
||||
@@ -181,7 +181,7 @@ class FoodUpdate(GroupRequiredMixin, UpdateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(FoodUpdate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Ingredient")
|
||||
context['title'] = _("Food")
|
||||
return context
|
||||
|
||||
|
||||
@@ -325,7 +325,7 @@ def edit_ingredients(request):
|
||||
if units_form.is_valid():
|
||||
new_unit = units_form.cleaned_data['new_unit']
|
||||
old_unit = units_form.cleaned_data['old_unit']
|
||||
recipe_ingredients = RecipeIngredient.objects.filter(unit=old_unit).all()
|
||||
recipe_ingredients = Ingredient.objects.filter(unit=old_unit).all()
|
||||
for i in recipe_ingredients:
|
||||
i.unit = new_unit
|
||||
i.save()
|
||||
@@ -338,7 +338,7 @@ def edit_ingredients(request):
|
||||
if ingredients_form.is_valid():
|
||||
new_ingredient = ingredients_form.cleaned_data['new_food']
|
||||
old_ingredient = ingredients_form.cleaned_data['old_food']
|
||||
recipe_ingredients = RecipeIngredient.objects.filter(ingredient=old_ingredient).all()
|
||||
recipe_ingredients = Ingredient.objects.filter(food=old_ingredient).all()
|
||||
for i in recipe_ingredients:
|
||||
i.ingredient = new_ingredient
|
||||
i.save()
|
||||
|
||||
@@ -12,7 +12,7 @@ from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from cookbook.forms import ExportForm, ImportForm
|
||||
from cookbook.helper.permission_helper import group_required
|
||||
from cookbook.models import RecipeIngredient, Recipe, Unit, Food, Keyword, Food
|
||||
from cookbook.models import Ingredient, Recipe, Unit, Food, Keyword, Food
|
||||
|
||||
|
||||
@group_required('user')
|
||||
@@ -47,8 +47,8 @@ def import_recipe(request):
|
||||
pass
|
||||
|
||||
for ri in data['recipe_ingredients']:
|
||||
RecipeIngredient.objects.create(recipe=recipe, ingredient=Food.objects.get(name=ri['ingredient']),
|
||||
unit=Unit.objects.get(name=ri['unit']), amount=ri['amount'], note=ri['note'])
|
||||
Ingredient.objects.create(recipe=recipe, ingredient=Food.objects.get(name=ri['food']),
|
||||
unit=Unit.objects.get(name=ri['unit']), amount=ri['amount'], note=ri['note'])
|
||||
|
||||
if data['image']:
|
||||
fmt, img = data['image'].split(';base64,')
|
||||
@@ -84,13 +84,13 @@ def export_recipe(request):
|
||||
for k in recipe.keywords.all():
|
||||
export['keywords'].append({'name': k.name, 'icon': k.icon, 'description': k.description})
|
||||
|
||||
for ri in RecipeIngredient.objects.filter(recipe=recipe).all():
|
||||
for ri in Ingredient.objects.filter(recipe=recipe).all():
|
||||
if ri.unit not in export['units']:
|
||||
export['units'].append({'name': ri.unit.name, 'description': ri.unit.description})
|
||||
if ri.ingredient not in export['ingredients']:
|
||||
export['ingredients'].append({'name': ri.ingredient.name})
|
||||
|
||||
export['recipe_ingredients'].append({'ingredient': ri.ingredient.name, 'unit': ri.unit.name, 'amount': float(ri.amount), 'note': ri.note})
|
||||
export['recipe_ingredients'].append({'food': ri.ingredient.name, 'unit': ri.unit.name, 'amount': float(ri.amount), 'note': ri.note})
|
||||
|
||||
if recipe.image and form.cleaned_data['image']:
|
||||
with open(recipe.image.path, 'rb') as img_f:
|
||||
|
||||
@@ -79,7 +79,7 @@ def recipe_view(request, pk, share=None):
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
ingredients = RecipeIngredient.objects.filter(recipe=recipe).all()
|
||||
ingredients = Ingredient.objects.filter(recipe=recipe).all()
|
||||
comments = Comment.objects.filter(recipe=recipe)
|
||||
|
||||
if request.method == "POST":
|
||||
|
||||
Reference in New Issue
Block a user