recipe books working

This commit is contained in:
vabene1111 2019-12-25 13:11:18 +01:00
parent d90b012601
commit 49f7afd8d2
4 changed files with 76 additions and 17 deletions

View File

@ -19,11 +19,18 @@
{% for b in book_list %}
<div class="row">
<div class="col col-md-12">
<div class="col col-md-10">
<a data-toggle="collapse" href="#collapse_{{ b.book.pk }}" role="button" aria-expanded="false"
aria-controls="collapse_{{ b.book.pk }}"><h4>{{ b.book.name }}</h4></a>
<hr/>
</div>
<div class="col col-md-2" style="text-align: right">
<h4>
<a href="{% url 'edit_recipe_book' b.book.pk %}"> <i class="fas fa-pencil-alt"></i></a>
<a href="{% url 'delete_recipe_book' b.book.pk %}"><i class="fas fa-trash-alt"></i></a>
</h4>
</div>
<hr/>
</div>
<div class="row">
@ -32,13 +39,18 @@
{% if b.recipes %}
<ul>
{% for r in b.recipes %}
<li><a href="#" onClick='openRecipe({{r.recipe.pk}})'>{{ r.recipe.name }}</a></li>
<div class="row">
<div class="col col-md-10">
<li><a href="#" onClick='openRecipe({{ r.recipe.pk }})'>{{ r.recipe.name }}</a></li>
</div>
<div class="col col-md-2" style="text-align: right">
<a href="{% url 'delete_recipe_book_entry' r.pk %}"><i class="fas fa-trash-alt"></i></a>
</div>
</div>
{% endfor %}
</ul>
{% else %}
{% trans 'There are no recipes in this book yet.' %}
{% endif %}
</div>
</div>

View File

@ -133,7 +133,8 @@
<form method="POST" class="post-form">
{% csrf_token %}
<div class="input-group mb-3">
<textarea name="comment-text" cols="15" rows="2" class="textarea form-control" required id="comment-id_text"></textarea>
<textarea name="comment-text" cols="15" rows="2" class="textarea form-control" required
id="comment-id_text"></textarea>
<div class="input-group-append">
<input type="submit" value="{% trans 'Comment' %}" class="btn btn-success">
</div>
@ -166,17 +167,19 @@
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form method="POST" class="post-form">
<form method="POST" class="post-form">
<div class="modal-body">
{% csrf_token %}
{{ bookmark_form|crispy }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" value="{% trans 'Save' %}" class="btn btn-success">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>

View File

@ -33,6 +33,7 @@ urlpatterns = [
path('edit/import/<int:pk>/', edit.ImportUpdate.as_view(), name='edit_import'),
path('edit/storage/<int:pk>/', edit.edit_storage, name='edit_storage'),
path('edit/comment/<int:pk>/', edit.CommentUpdate.as_view(), name='edit_comment'),
path('edit/recipe-book/<int:pk>/', edit.RecipeBookUpdate.as_view(), name='edit_recipe_book'),
path('redirect/delete/<slug:name>/<int:pk>/', edit.delete_redirect, name='redirect_delete'),
@ -42,6 +43,8 @@ urlpatterns = [
path('delete/import/<int:pk>/', edit.ImportDelete.as_view(), name='delete_import'),
path('delete/storage/<int:pk>/', edit.StorageDelete.as_view(), name='delete_storage'),
path('delete/comment/<int:pk>/', edit.CommentDelete.as_view(), name='delete_comment'),
path('delete/recipe-book/<int:pk>/', edit.RecipeBookDelete.as_view(), name='delete_recipe_book'),
path('delete/recipe-book-entry/<int:pk>/', 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'),

View File

@ -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