diff --git a/cookbook/templates/books.html b/cookbook/templates/books.html index f2ff3bafb..c22c41870 100644 --- a/cookbook/templates/books.html +++ b/cookbook/templates/books.html @@ -19,11 +19,18 @@ {% for b in book_list %}
-
+ +
+

+ + + +

+
+
@@ -32,13 +39,18 @@ {% if b.recipes %} - {% else %} {% trans 'There are no recipes in this book yet.' %} - {% endif %}
diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 662c5ae2e..ff13a392c 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -133,7 +133,8 @@
{% csrf_token %}
- +
@@ -166,17 +167,19 @@
-
+ diff --git a/cookbook/urls.py b/cookbook/urls.py index bb999f2f0..10d209cbf 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -33,6 +33,7 @@ urlpatterns = [ path('edit/import//', edit.ImportUpdate.as_view(), name='edit_import'), path('edit/storage//', edit.edit_storage, name='edit_storage'), path('edit/comment//', edit.CommentUpdate.as_view(), name='edit_comment'), + path('edit/recipe-book//', edit.RecipeBookUpdate.as_view(), name='edit_recipe_book'), path('redirect/delete///', edit.delete_redirect, name='redirect_delete'), @@ -42,6 +43,8 @@ urlpatterns = [ path('delete/import//', edit.ImportDelete.as_view(), name='delete_import'), path('delete/storage//', edit.StorageDelete.as_view(), name='delete_storage'), path('delete/comment//', edit.CommentDelete.as_view(), name='delete_comment'), + path('delete/recipe-book//', edit.RecipeBookDelete.as_view(), name='delete_recipe_book'), + path('delete/recipe-book-entry//', edit.RecipeBookEntryDelete.as_view(), name='delete_recipe_book_entry'), 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/edit.py b/cookbook/views/edit.py index 0c098d4e5..724965c40 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -11,7 +11,8 @@ from django.utils.translation import gettext as _ from django.views.generic import UpdateView, DeleteView from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm, InternalRecipeForm, CommentForm -from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeIngredients +from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeIngredients, RecipeBook, \ + RecipeBookEntry from cookbook.provider.dropbox import Dropbox from cookbook.provider.nextcloud import Nextcloud @@ -188,6 +189,22 @@ class ImportUpdate(LoginRequiredMixin, UpdateView): return context +class RecipeBookUpdate(LoginRequiredMixin, UpdateView): + template_name = "generic/edit_template.html" + model = RecipeBook + fields = ['name'] + + # TODO add msg box + + 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 RecipeUpdate(LoginRequiredMixin, UpdateView): model = Recipe form_class = ExternalRecipeForm @@ -198,11 +215,13 @@ class RecipeUpdate(LoginRequiredMixin, UpdateView): old_recipe = Recipe.objects.get(pk=self.object.pk) if not old_recipe.name == self.object.name: if self.object.storage.method == Storage.DROPBOX: - Dropbox.rename_file(old_recipe, self.object.name) # TODO central location to handle storage type switches + Dropbox.rename_file(old_recipe, + self.object.name) # TODO central location to handle storage type switches if self.object.storage.method == Storage.NEXTCLOUD: Nextcloud.rename_file(old_recipe, self.object.name) - self.object.file_path = os.path.dirname(self.object.file_path) + '/' + self.object.name + os.path.splitext(self.object.file_path)[1] + self.object.file_path = os.path.dirname(self.object.file_path) + '/' + self.object.name + \ + os.path.splitext(self.object.file_path)[1] messages.add_message(self.request, messages.SUCCESS, _('Changes saved!')) return super(RecipeUpdate, self).form_valid(form) @@ -296,3 +315,25 @@ class CommentDelete(LoginRequiredMixin, DeleteView): context = super(CommentDelete, self).get_context_data(**kwargs) context['title'] = _("Comment") return context + + +class RecipeBookDelete(LoginRequiredMixin, DeleteView): + template_name = "generic/delete_template.html" + model = RecipeBook + success_url = reverse_lazy('view_books') + + def get_context_data(self, **kwargs): + context = super(RecipeBookDelete, self).get_context_data(**kwargs) + context['title'] = _("Recipe Book") + return context + + +class RecipeBookEntryDelete(LoginRequiredMixin, DeleteView): + template_name = "generic/delete_template.html" + model = RecipeBookEntry + success_url = reverse_lazy('view_books') + + def get_context_data(self, **kwargs): + context = super(RecipeBookEntryDelete, self).get_context_data(**kwargs) + context['title'] = _("Bookmarks") + return context