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

@ -14,6 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (recipes)" jdkType="Python SDK" />
@ -28,7 +29,6 @@
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/cookbook/templates" />
<option value="$MODULE_DIR$/recipes/templates" />
</list>
</option>
</component>

View File

@ -47,7 +47,7 @@ class RecipeAdmin(admin.ModelAdmin):
admin.site.register(Recipe, RecipeAdmin)
admin.site.register(Unit)
admin.site.register(Ingredient)
admin.site.register(Food)
class RecipeIngredientAdmin(admin.ModelAdmin):

View File

@ -2,7 +2,7 @@ import django_filters
from django.contrib.postgres.search import TrigramSimilarity
from django.db.models import Q
from cookbook.forms import MultiSelectWidget
from cookbook.models import Recipe, Keyword, Ingredient
from cookbook.models import Recipe, Keyword, Food
from django.conf import settings
from django.utils.translation import gettext as _
@ -11,7 +11,7 @@ class RecipeFilter(django_filters.FilterSet):
name = django_filters.CharFilter(method='filter_name')
keywords = django_filters.ModelMultipleChoiceFilter(queryset=Keyword.objects.all(), widget=MultiSelectWidget,
method='filter_keywords')
ingredients = django_filters.ModelMultipleChoiceFilter(queryset=Ingredient.objects.all(), widget=MultiSelectWidget,
ingredients = django_filters.ModelMultipleChoiceFilter(queryset=Food.objects.all(), widget=MultiSelectWidget,
method='filter_ingredients', label=_('Ingredients'))
@staticmethod
@ -50,5 +50,5 @@ class IngredientFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
model = Ingredient
model = Food
fields = ['name']

View File

@ -151,13 +151,13 @@ class IngredientMergeForm(forms.Form):
prefix = 'ingredient'
new_ingredient = forms.ModelChoiceField(
queryset=Ingredient.objects.all(),
queryset=Food.objects.all(),
widget=SelectWidget,
label=_('New Ingredient'),
help_text=_('New ingredient that other gets replaced by.'),
)
old_ingredient = forms.ModelChoiceField(
queryset=Ingredient.objects.all(),
queryset=Food.objects.all(),
widget=SelectWidget,
label=_('Old Ingredient'),
help_text=_('Ingredient that should be replaced.'),
@ -186,9 +186,9 @@ class KeywordForm(forms.ModelForm):
widgets = {'icon': EmojiPickerTextInput}
class IngredientForm(forms.ModelForm):
class FoodForm(forms.ModelForm):
class Meta:
model = Ingredient
model = Food
fields = ('name', 'recipe')
widgets = {'recipe': SelectWidget}

View File

@ -1,6 +1,6 @@
from dal import autocomplete
from cookbook.models import Keyword, RecipeIngredient, Recipe, Unit, Ingredient
from cookbook.models import Keyword, Recipe, Unit, Food
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
@ -19,9 +19,9 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView):
class IngredientsAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_authenticated:
return Ingredient.objects.none()
return Food.objects.none()
qs = Ingredient.objects.all()
qs = Food.objects.all()
if self.q:
qs = qs.filter(name__icontains=self.q)

View File

@ -0,0 +1,28 @@
# Generated by Django 3.0.7 on 2020-06-25 19:18
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0055_auto_20200616_1236'),
]
operations = [
migrations.RenameModel(
old_name='Ingredient',
new_name='Food',
),
migrations.AddField(
model_name='recipe',
name='ingredients',
field=models.ManyToManyField(blank=True, related_name='tmp_ingredients', to='cookbook.RecipeIngredient'),
),
migrations.AlterField(
model_name='sharelink',
name='uuid',
field=models.UUIDField(default=uuid.UUID('a5f12617-9e4b-41e3-87ee-49db96090974')),
),
]

View File

@ -136,6 +136,7 @@ class Recipe(models.Model):
link = models.CharField(max_length=512, null=True, blank=True)
cors_link = models.CharField(max_length=1024, null=True, blank=True)
keywords = models.ManyToManyField(Keyword, blank=True)
ingredients = models.ManyToManyField('RecipeIngredient', blank=True, related_name='tmp_ingredients')
working_time = models.IntegerField(default=0)
waiting_time = models.IntegerField(default=0)
internal = models.BooleanField(default=False)
@ -155,7 +156,7 @@ class Unit(models.Model):
return self.name
class Ingredient(models.Model):
class Food(models.Model):
name = models.CharField(unique=True, max_length=128)
recipe = models.ForeignKey(Recipe, null=True, blank=True, on_delete=models.SET_NULL)
@ -165,7 +166,7 @@ class Ingredient(models.Model):
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT)
ingredient = models.ForeignKey(Food, on_delete=models.PROTECT)
unit = models.ForeignKey(Unit, on_delete=models.PROTECT)
amount = models.DecimalField(default=0, decimal_places=16, max_digits=32)
note = models.CharField(max_length=64, null=True, blank=True)

View File

@ -1,7 +1,7 @@
from django.contrib.auth.models import User
from rest_framework import serializers
from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Ingredient, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog
from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food
from cookbook.templatetags.custom_tags import markdown
@ -56,7 +56,7 @@ class UnitSerializer(serializers.ModelSerializer):
class IngredientSerializer(serializers.ModelSerializer):
class Meta:
model = Ingredient
model = Food
fields = '__all__'

View File

@ -48,7 +48,7 @@ class KeywordTable(tables.Table):
class IngredientTable(tables.Table):
id = tables.LinkColumn('edit_ingredient', args=[A('id')])
id = tables.LinkColumn('edit_food', args=[A('id')])
class Meta:
model = Keyword

View File

@ -60,7 +60,7 @@
class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_books,view_plan,view_shopping,list_ingredient,view_plan_entry' %}active{% endif %}">
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_books,view_plan,view_shopping,list_food,view_plan_entry' %}active{% endif %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fas fa-mortar-pestle"></i> {% trans 'Utensils' %}
@ -75,7 +75,7 @@
<a class="dropdown-item" href="{% url 'view_shopping' %}"><i
class="fas fa-shopping-cart fa-fw"></i> {% trans 'Shopping' %}
</a>
<a class="dropdown-item" href="{% url 'list_ingredient' %}"><i
<a class="dropdown-item" href="{% url 'list_food' %}"><i
class="fas fa-leaf fa-fw"></i> {% trans 'Ingredients' %}
</a>
</div>
@ -92,7 +92,7 @@
class="fas fa-edit fa-fw"></i> {% trans 'Batch Edit' %}</a>
</div>
</li>
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_storage,data_sync,list_recipe_import,list_sync_log,data_stats,edit_ingredient' %}active{% endif %}">
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_storage,data_sync,list_recipe_import,list_sync_log,data_stats,edit_food' %}active{% endif %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false"><i class="fas fa-database"></i> {% trans 'Storage Data' %}
</a>
@ -107,7 +107,7 @@
class="fas fa-history fa-fw"></i> {% trans 'Discovery Log' %}</a>
<a class="dropdown-item" href="{% url 'data_stats' %}"><i
class="fas fa-chart-line fa-fw"></i> {% trans 'Statistics' %}</a>
<a class="dropdown-item" href="{% url 'edit_ingredient' %}"><i
<a class="dropdown-item" href="{% url 'edit_food' %}"><i
class="fas fa-balance-scale fa-fw"></i> {% trans 'Units & Ingredients' %}</a>
<a class="dropdown-item" href="{% url 'view_import' %}"><i
class="fas fa-file-import"></i> {% trans 'Import Recipe' %}</a>

View File

@ -74,7 +74,7 @@
};
let select2IngredientEditor = function (cell, onRendered, success, cancel, editorParams) {
return select2Editor(cell, onRendered, success, cancel, editorParams, '{% url 'dal_ingredient' %}')
return select2Editor(cell, onRendered, success, cancel, editorParams, '{% url 'dal_food' %}')
};
let select2Editor = function (cell, onRendered, success, cancel, editorParams, url) {

View File

@ -22,7 +22,7 @@
<br/>
<h4>{% trans 'Units' %}</h4>
<form action="{% url 'edit_ingredient' %}" method="post"
<form action="{% url 'edit_food' %}" method="post"
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two units ?' %}')">
{% csrf_token %}
{{ units_form|crispy }}
@ -32,7 +32,7 @@
</form>
<h4>{% trans 'Ingredients' %}</h4>
<form action="{% url 'edit_ingredient' %}" method="post"
<form action="{% url 'edit_food' %}" method="post"
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two ingredients ?' %}')">
{% csrf_token %}
{{ ingredients_form|crispy }}

View File

@ -362,7 +362,7 @@
},
searchIngredients: function (query) {
this.ingredients_loading = true
this.$http.get("{% url 'dal_ingredient' %}" + '?q=' + query).then((response) => {
this.$http.get("{% url 'dal_food' %}" + '?q=' + query).then((response) => {
this.ingredients = response.data.results
if (this.recipe_data !== undefined) {
for (let x of Array.from(this.recipe_data.recipeIngredient)) {

View File

@ -7,7 +7,7 @@ from django.urls import reverse, NoReverseMatch
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension
from cookbook.models import get_model_name, CookLog
from cookbook.models import get_model_name
from recipes import settings
register = template.Library()

View File

@ -1,7 +1,7 @@
from django.contrib import auth
from django.urls import reverse
from cookbook.models import Recipe, RecipeIngredient, Ingredient, Unit, Storage
from cookbook.models import Recipe, RecipeIngredient, Unit, Storage, Food
from cookbook.tests.views.test_views import TestViews
@ -76,7 +76,7 @@ class TestEditsRecipe(TestViews):
recipe = Recipe.objects.get(pk=recipe.pk)
self.assertEqual('Changed', recipe.name)
Ingredient.objects.create(name='Egg')
Food.objects.create(name='Egg')
Unit.objects.create(name='g')
r = self.user_client_1.post(url,

View File

@ -46,7 +46,7 @@ urlpatterns = [
path('edit/recipe/convert/<int:pk>/', edit.convert_recipe, name='edit_convert_recipe'), # for internal use only
path('edit/storage/<int:pk>/', edit.edit_storage, name='edit_storage'),
path('edit/ingredient/', edit.edit_ingredients, name='edit_ingredient'),
path('edit/ingredient/', edit.edit_ingredients, name='edit_food'),
path('delete/recipe-source/<int:pk>/', delete.delete_recipe_source, name='delete_recipe_source'),
@ -65,7 +65,7 @@ urlpatterns = [
path('api/recipe-from-url/<path:url>/', api.recipe_from_url, name='api_recipe_from_url'),
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
path('dal/ingredient/', dal.IngredientsAutocomplete.as_view(), name='dal_ingredient'),
path('dal/food/', dal.IngredientsAutocomplete.as_view(), name='dal_food'),
path('dal/unit/', dal.UnitAutocomplete.as_view(), name='dal_unit'),
path('docs/markdown/', views.markdown_info, name='docs_markdown'),
@ -81,7 +81,7 @@ urlpatterns = [
]
generic_models = (Recipe, RecipeImport, Storage, RecipeBook, MealPlan, SyncLog, Sync, Comment, RecipeBookEntry, Keyword, Ingredient)
generic_models = (Recipe, RecipeImport, Storage, RecipeBook, MealPlan, SyncLog, Sync, Comment, RecipeBookEntry, Keyword, Food)
for m in generic_models:
py_name = get_model_name(m)

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)