renamed ingredient to food

This commit is contained in:
vabene1111
2020-06-25 21:24:03 +02:00
parent 2c5e44d73c
commit f685253645
22 changed files with 83 additions and 54 deletions

View File

@@ -18,7 +18,7 @@ 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, Ingredient
from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, RecipeIngredient, 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
@@ -141,7 +141,7 @@ class RecipeIngredientViewSet(viewsets.ModelViewSet):
class IngredientViewSet(viewsets.ModelViewSet):
queryset = Ingredient.objects.all()
queryset = Food.objects.all()
serializer_class = IngredientSerializer
permission_classes = [CustomIsUser]

View File

@@ -115,7 +115,7 @@ def import_url(request):
recipe.keywords.add(k)
for ing in data['recipeIngredient']:
i, i_created = Ingredient.objects.get_or_create(name=ing['ingredient']['text'])
i, i_created = Food.objects.get_or_create(name=ing['ingredient']['text'])
if ing['unit']:
u, u_created = Unit.objects.get_or_create(name=ing['unit']['text'])
else:
@@ -161,7 +161,7 @@ def statistics(request):
counts.keywords = Keyword.objects.count()
counts.recipe_import = RecipeImport.objects.count()
counts.units = Unit.objects.count()
counts.ingredients = Ingredient.objects.count()
counts.ingredients = Food.objects.count()
counts.comments = Comment.objects.count()
counts.recipes_internal = Recipe.objects.filter(internal=True).count()

View File

@@ -9,7 +9,7 @@ from django.views.generic import DeleteView
from cookbook.helper.permission_helper import group_required, GroupRequiredMixin, OwnerRequiredMixin
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeBook, \
RecipeBookEntry, MealPlan, Ingredient
RecipeBookEntry, MealPlan, Food
from cookbook.provider.dropbox import Dropbox
from cookbook.provider.nextcloud import Nextcloud

View File

@@ -15,12 +15,12 @@ from django.utils.translation import gettext as _
from django.views.generic import UpdateView
from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm, InternalRecipeForm, CommentForm, \
MealPlanForm, UnitMergeForm, IngredientMergeForm, IngredientForm, RecipeBookForm
MealPlanForm, UnitMergeForm, IngredientMergeForm, RecipeBookForm, FoodForm
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, \
MealPlan, Unit, Ingredient
MealPlan, Unit, Food
from cookbook.provider.dropbox import Dropbox
from cookbook.provider.nextcloud import Nextcloud
@@ -92,10 +92,10 @@ def internal_recipe_update(request, pk):
if 'note' in i:
recipe_ingredient.note = i['note']
if Ingredient.objects.filter(name=i['ingredient__name']).exists():
recipe_ingredient.ingredient = Ingredient.objects.get(name=i['ingredient__name'])
if Food.objects.filter(name=i['ingredient__name']).exists():
recipe_ingredient.ingredient = Food.objects.get(name=i['ingredient__name'])
else:
ingredient = Ingredient()
ingredient = Food()
ingredient.name = i['ingredient__name']
ingredient.save()
recipe_ingredient.ingredient = ingredient
@@ -168,19 +168,19 @@ class KeywordUpdate(GroupRequiredMixin, UpdateView):
return context
class IngredientUpdate(GroupRequiredMixin, UpdateView):
class FoodUpdate(GroupRequiredMixin, UpdateView):
groups_required = ['user']
template_name = "generic/edit_template.html"
model = Ingredient
form_class = IngredientForm
model = Food
form_class = FoodForm
# TODO add msg box
def get_success_url(self):
return reverse('edit_ingredient', kwargs={'pk': self.object.pk})
return reverse('edit_food', kwargs={'pk': self.object.pk})
def get_context_data(self, **kwargs):
context = super(IngredientUpdate, self).get_context_data(**kwargs)
context = super(FoodUpdate, self).get_context_data(**kwargs)
context['title'] = _("Ingredient")
return context
@@ -336,8 +336,8 @@ def edit_ingredients(request):
ingredients_form = IngredientMergeForm(request.POST, prefix=IngredientMergeForm.prefix)
if ingredients_form.is_valid():
new_ingredient = ingredients_form.cleaned_data['new_ingredient']
old_ingredient = ingredients_form.cleaned_data['old_ingredient']
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()
for i in recipe_ingredients:
i.ingredient = new_ingredient

View File

@@ -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, Ingredient, Keyword
from cookbook.models import RecipeIngredient, Recipe, Unit, Food, Keyword, Food
@group_required('user')
@@ -42,12 +42,12 @@ def import_recipe(request):
for i in data['ingredients']:
try:
Ingredient.objects.create(name=i['name']).save()
Food.objects.create(name=i['name']).save()
except IntegrityError:
pass
for ri in data['recipe_ingredients']:
RecipeIngredient.objects.create(recipe=recipe, ingredient=Ingredient.objects.get(name=ri['ingredient']),
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'])
if data['image']:

View File

@@ -6,7 +6,7 @@ from django_tables2 import RequestConfig
from cookbook.filters import IngredientFilter
from cookbook.helper.permission_helper import group_required
from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Ingredient
from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Food
from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable, IngredientTable
@@ -36,8 +36,8 @@ def recipe_import(request):
@group_required('user')
def ingredient(request):
f = IngredientFilter(request.GET, queryset=Ingredient.objects.all().order_by('pk'))
def food(request):
f = IngredientFilter(request.GET, queryset=Food.objects.all().order_by('pk'))
table = IngredientTable(f.qs)
RequestConfig(request, paginate={'per_page': 25}).configure(table)