removed some deprecated stuff

This commit is contained in:
vabene1111 2021-09-23 15:19:10 +02:00
parent ea472158f9
commit b949fe6a90
5 changed files with 7 additions and 181 deletions

View File

@ -5,11 +5,10 @@ from django.forms import widgets
from django.utils.translation import gettext_lazy as _
from django_scopes import scopes_disabled
from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField
from emoji_picker.widgets import EmojiPickerTextInput
from hcaptcha.fields import hCaptchaField
from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe,
RecipeBook, RecipeBookEntry, Storage, Sync, Unit, User,
from .models import (Comment, InviteLink, Keyword, MealPlan, Recipe,
RecipeBook, RecipeBookEntry, Storage, Sync, User,
UserPreference, MealType, Space,
SearchPreference)
@ -158,53 +157,6 @@ class ExportForm(ImportExportBase):
self.fields['recipes'].queryset = Recipe.objects.filter(space=space).all()
class UnitMergeForm(forms.Form):
prefix = 'unit'
new_unit = SafeModelChoiceField(
queryset=Unit.objects.none(),
widget=SelectWidget,
label=_('New Unit'),
help_text=_('New unit that other gets replaced by.'),
)
old_unit = SafeModelChoiceField(
queryset=Unit.objects.none(),
widget=SelectWidget,
label=_('Old Unit'),
help_text=_('Unit that should be replaced.'),
)
def __init__(self, *args, **kwargs):
space = kwargs.pop('space')
super().__init__(*args, **kwargs)
self.fields['new_unit'].queryset = Unit.objects.filter(space=space).all()
self.fields['old_unit'].queryset = Unit.objects.filter(space=space).all()
# TODO Deprecated
class FoodMergeForm(forms.Form):
prefix = 'food'
new_food = SafeModelChoiceField(
queryset=Food.objects.none(),
widget=SelectWidget,
label=_('New Food'),
help_text=_('New food that other gets replaced by.'),
)
old_food = SafeModelChoiceField(
queryset=Food.objects.none(),
widget=SelectWidget,
label=_('Old Food'),
help_text=_('Food that should be replaced.'),
)
def __init__(self, *args, **kwargs):
space = kwargs.pop('space')
super().__init__(*args, **kwargs)
self.fields['new_food'].queryset = Food.objects.filter(space=space).all()
self.fields['old_food'].queryset = Food.objects.filter(space=space).all()
class CommentForm(forms.ModelForm):
prefix = 'comment'
@ -220,33 +172,6 @@ class CommentForm(forms.ModelForm):
}
# class KeywordForm(MoveNodeForm):
# class Meta:
# model = Keyword
# fields = ('name', 'icon', 'description')
# exclude = ('sib_order', 'parent', 'path', 'depth', 'numchild')
# widgets = {'icon': EmojiPickerTextInput}
# class FoodForm(forms.ModelForm):
# def __init__(self, *args, **kwargs):
# space = kwargs.pop('space')
# super().__init__(*args, **kwargs)
# self.fields['recipe'].queryset = Recipe.objects.filter(space=space).all()
# self.fields['supermarket_category'].queryset = SupermarketCategory.objects.filter(space=space).all()
# class Meta:
# model = Food
# fields = ('name', 'description', 'ignore_shopping', 'recipe', 'supermarket_category')
# widgets = {'recipe': SelectWidget}
# field_classes = {
# 'recipe': SafeModelChoiceField,
# 'supermarket_category': SafeModelChoiceField,
# }
class StorageForm(forms.ModelForm):
username = forms.CharField(
widget=forms.TextInput(attrs={'autocomplete': 'new-password'}),
@ -344,21 +269,6 @@ class ImportRecipeForm(forms.ModelForm):
}
class RecipeBookForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
space = kwargs.pop('space')
super().__init__(*args, **kwargs)
self.fields['shared'].queryset = User.objects.filter(userpreference__space=space).all()
class Meta:
model = RecipeBook
fields = ('name', 'icon', 'description', 'shared')
widgets = {'icon': EmojiPickerTextInput, 'shared': MultiSelectWidget}
field_classes = {
'shared': SafeModelMultipleChoiceField,
}
class MealPlanForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
space = kwargs.pop('space')

View File

@ -89,7 +89,6 @@ urlpatterns = [
path('edit/recipe/convert/<int:pk>/', edit.convert_recipe, name='edit_convert_recipe'),
path('edit/storage/<int:pk>/', edit.edit_storage, name='edit_storage'),
path('edit/ingredient/', edit.edit_ingredients, name='edit_food'), # TODO deprecate?
path('delete/recipe-source/<int:pk>/', delete.delete_recipe_source, name='delete_recipe_source'),
@ -111,7 +110,7 @@ urlpatterns = [
path('api/ingredient-from-string/', api.ingredient_from_string, name='api_ingredient_from_string'),
path('api/share-link/<int:pk>', api.share_link, name='api_share_link'),
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'), # TODO is this deprecated?
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'), # TODO is this deprecated? not yet, some old forms remain, could likely be changed to generic API endpoints
path('dal/food/', dal.IngredientsAutocomplete.as_view(), name='dal_food'), # TODO is this deprecated?
path('dal/unit/', dal.UnitAutocomplete.as_view(), name='dal_unit'), # TODO is this deprecated?

View File

@ -11,9 +11,9 @@ from django.views.generic.edit import FormMixin
from django_scopes import scopes_disabled
from cookbook.forms import (CommentForm, ExternalRecipeForm,
FoodMergeForm, MealPlanForm,
RecipeBookForm, StorageForm, SyncForm,
UnitMergeForm)
MealPlanForm,
StorageForm, SyncForm,
)
from cookbook.helper.permission_helper import (GroupRequiredMixin,
OwnerRequiredMixin,
group_required)
@ -198,20 +198,6 @@ class ImportUpdate(GroupRequiredMixin, UpdateView):
return context
class RecipeBookUpdate(OwnerRequiredMixin, UpdateView, SpaceFormMixing):
template_name = "generic/edit_template.html"
model = RecipeBook
form_class = RecipeBookForm
def get_success_url(self):
return reverse('view_books')
def get_context_data(self, **kwargs):
context = super(RecipeBookUpdate, self).get_context_data(**kwargs)
context['title'] = _("Recipe Book")
return context
class MealPlanUpdate(OwnerRequiredMixin, UpdateView, SpaceFormMixing):
template_name = "generic/edit_template.html"
model = MealPlan
@ -275,51 +261,3 @@ class ExternalRecipeUpdate(GroupRequiredMixin, UpdateView, SpaceFormMixing):
'delete_recipe_source', args=[self.object.pk]
)
return context
# TODO deprecate
@group_required('user')
def edit_ingredients(request):
if request.method == "POST":
success = False
units_form = UnitMergeForm(request.POST, prefix=UnitMergeForm.prefix, space=request.space)
if units_form.is_valid():
new_unit = units_form.cleaned_data['new_unit']
old_unit = units_form.cleaned_data['old_unit']
if new_unit != old_unit:
with scopes_disabled():
recipe_ingredients = Ingredient.objects.filter(unit=old_unit).filter(Q(step__recipe__space=request.space) | Q(step__recipe__isnull=True)).all()
for i in recipe_ingredients:
i.unit = new_unit
i.save()
old_unit.delete()
success = True
messages.add_message(request, messages.SUCCESS, _('Units merged!'))
else:
messages.add_message(request, messages.ERROR, _('Cannot merge with the same object!'))
food_form = FoodMergeForm(request.POST, prefix=FoodMergeForm.prefix, space=request.space)
if food_form.is_valid():
new_food = food_form.cleaned_data['new_food']
old_food = food_form.cleaned_data['old_food']
if new_food != old_food:
ingredients = Ingredient.objects.filter(food=old_food).filter(Q(step__recipe__space=request.space) | Q(step__recipe__isnull=True)).all()
for i in ingredients:
i.food = new_food
i.save()
old_food.delete()
success = True
messages.add_message(request, messages.SUCCESS, _('Foods merged!'))
else:
messages.add_message(request, messages.ERROR, _('Cannot merge with the same object!'))
if success:
units_form = UnitMergeForm(space=request.space)
food_form = FoodMergeForm(space=request.space)
else:
units_form = UnitMergeForm(space=request.space)
food_form = FoodMergeForm(space=request.space)
return render(request, 'forms/ingredients.html', {'units_form': units_form, 'food_form': food_form})

View File

@ -13,7 +13,7 @@ from django.utils.translation import gettext as _
from django.views.generic import CreateView
from cookbook.forms import (ImportRecipeForm, InviteLinkForm,
MealPlanForm, RecipeBookForm, Storage, StorageForm)
MealPlanForm, Storage, StorageForm)
from cookbook.helper.permission_helper import (GroupRequiredMixin,
group_required)
from cookbook.models import (InviteLink, MealPlan, MealType, Recipe,
@ -136,26 +136,6 @@ def create_new_external_recipe(request, import_id):
return render(request, 'forms/edit_import_recipe.html', {'form': form})
class RecipeBookCreate(GroupRequiredMixin, CreateView, SpaceFormMixing):
groups_required = ['user']
template_name = "generic/new_template.html"
model = RecipeBook
form_class = RecipeBookForm
success_url = reverse_lazy('view_books')
def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.space = self.request.space
obj.save()
return HttpResponseRedirect(reverse('view_books'))
def get_context_data(self, **kwargs):
context = super(RecipeBookCreate, self).get_context_data(**kwargs)
context['title'] = _("Recipe Book")
return context
class MealPlanCreate(GroupRequiredMixin, CreateView, SpaceFormMixing):
groups_required = ['user']
template_name = "generic/new_template.html"

View File

@ -4,7 +4,6 @@ django-annoying==0.10.6
django-autocomplete-light==3.8.2
django-cleanup==5.2.0
django-crispy-forms==1.12.0
django-emoji-picker==0.0.6
django-filter==2.4.0
django-tables2==2.4.0
djangorestframework==3.12.4