changed behavior of delete original
This commit is contained in:
parent
4c90664aa2
commit
1d562452df
@ -25,7 +25,7 @@ urlpatterns = [
|
|||||||
path('edit/storage/<int:pk>/', edit.edit_storage, name='edit_storage'),
|
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_ingredient'),
|
||||||
|
|
||||||
path('delete/recipe-source/<int:pk>/', delete.RecipeSourceDelete.as_view(), name='delete_recipe_source'),
|
path('delete/recipe-source/<int:pk>/', delete.delete_recipe_source, name='delete_recipe_source'),
|
||||||
|
|
||||||
path('data/sync', data.sync, name='data_sync'), # TODO move to generic "new" view
|
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'),
|
path('data/batch/edit', data.batch_edit, name='data_batch_edit'),
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
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.utils.translation import gettext as _
|
||||||
from django.views.generic import DeleteView
|
from django.views.generic import DeleteView
|
||||||
|
|
||||||
@ -20,24 +22,20 @@ class RecipeDelete(LoginRequiredMixin, DeleteView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class RecipeSourceDelete(LoginRequiredMixin, DeleteView):
|
def delete_recipe_source(request, pk):
|
||||||
template_name = "generic/delete_template.html"
|
recipe = get_object_or_404(Recipe, pk=pk)
|
||||||
model = Recipe
|
|
||||||
success_url = reverse_lazy('index')
|
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
if recipe.storage.method == Storage.DROPBOX:
|
||||||
self.object = self.get_object()
|
Dropbox.delete_file(recipe) # TODO central location to handle storage type switches
|
||||||
if self.object.storage.method == Storage.DROPBOX:
|
if recipe.storage.method == Storage.NEXTCLOUD:
|
||||||
Dropbox.delete_file(self.object) # TODO central location to handle storage type switches
|
Nextcloud.delete_file(recipe)
|
||||||
if self.object.storage.method == Storage.NEXTCLOUD:
|
|
||||||
Nextcloud.delete_file(self.object)
|
|
||||||
|
|
||||||
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):
|
return HttpResponseRedirect(reverse('edit_recipe', args=[recipe.pk]))
|
||||||
context = super(RecipeSourceDelete, self).get_context_data(**kwargs)
|
|
||||||
context['title'] = _("Recipe")
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
class RecipeImportDelete(LoginRequiredMixin, DeleteView):
|
class RecipeImportDelete(LoginRequiredMixin, DeleteView):
|
||||||
|
Loading…
Reference in New Issue
Block a user