From 1d562452df1382c21ea703eea6ae2c0f36722f4b Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 17 Mar 2020 18:54:44 +0100 Subject: [PATCH] changed behavior of delete original --- cookbook/urls.py | 2 +- cookbook/views/delete.py | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cookbook/urls.py b/cookbook/urls.py index facce35e..9c4963df 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -25,7 +25,7 @@ urlpatterns = [ path('edit/storage//', edit.edit_storage, name='edit_storage'), path('edit/ingredient/', edit.edit_ingredients, name='edit_ingredient'), - path('delete/recipe-source//', delete.RecipeSourceDelete.as_view(), name='delete_recipe_source'), + path('delete/recipe-source//', delete.delete_recipe_source, name='delete_recipe_source'), path('data/sync', data.sync, name='data_sync'), # TODO move to generic "new" view path('data/batch/edit', data.batch_edit, name='data_batch_edit'), diff --git a/cookbook/views/delete.py b/cookbook/views/delete.py index 3947d8f3..1bb0695d 100644 --- a/cookbook/views/delete.py +++ b/cookbook/views/delete.py @@ -1,5 +1,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin -from django.urls import reverse_lazy +from django.http import HttpResponseRedirect +from django.shortcuts import get_object_or_404 +from django.urls import reverse_lazy, reverse from django.utils.translation import gettext as _ from django.views.generic import DeleteView @@ -20,24 +22,20 @@ class RecipeDelete(LoginRequiredMixin, DeleteView): return context -class RecipeSourceDelete(LoginRequiredMixin, DeleteView): - template_name = "generic/delete_template.html" - model = Recipe - success_url = reverse_lazy('index') +def delete_recipe_source(request, pk): + recipe = get_object_or_404(Recipe, pk=pk) - def delete(self, request, *args, **kwargs): - self.object = self.get_object() - if self.object.storage.method == Storage.DROPBOX: - Dropbox.delete_file(self.object) # TODO central location to handle storage type switches - if self.object.storage.method == Storage.NEXTCLOUD: - Nextcloud.delete_file(self.object) + if recipe.storage.method == Storage.DROPBOX: + Dropbox.delete_file(recipe) # TODO central location to handle storage type switches + if recipe.storage.method == Storage.NEXTCLOUD: + Nextcloud.delete_file(recipe) - return super(RecipeSourceDelete, self).delete(request, *args, **kwargs) + recipe.storage = None + recipe.file_path = '' + recipe.file_uid = '' + recipe.save() - def get_context_data(self, **kwargs): - context = super(RecipeSourceDelete, self).get_context_data(**kwargs) - context['title'] = _("Recipe") - return context + return HttpResponseRedirect(reverse('edit_recipe', args=[recipe.pk])) class RecipeImportDelete(LoginRequiredMixin, DeleteView):