recipe books
This commit is contained in:
parent
8fcafcc25a
commit
d90b012601
@ -45,6 +45,8 @@ class InternalRecipeForm(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class CommentForm(forms.ModelForm):
|
class CommentForm(forms.ModelForm):
|
||||||
|
prefix = 'comment'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Comment
|
model = Comment
|
||||||
fields = ('text',)
|
fields = ('text',)
|
||||||
@ -82,6 +84,14 @@ class RecipeBookForm(forms.ModelForm):
|
|||||||
fields = ('name',)
|
fields = ('name',)
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeBookEntryForm(forms.ModelForm):
|
||||||
|
prefix = 'bookmark'
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = RecipeBookEntry
|
||||||
|
fields = ('book',)
|
||||||
|
|
||||||
|
|
||||||
class SyncForm(forms.ModelForm):
|
class SyncForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Sync
|
model = Sync
|
||||||
|
@ -102,7 +102,13 @@ class RecipeBook(models.Model):
|
|||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class RecipeBookEntry(models.Model):
|
class RecipeBookEntry(models.Model):
|
||||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||||
book = models.ForeignKey(RecipeBook, on_delete=models.CASCADE)
|
book = models.ForeignKey(RecipeBook, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.recipe.name
|
||||||
|
@ -29,13 +29,22 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<div class="collapse" id="collapse_{{ b.book.pk }}">
|
<div class="collapse" id="collapse_{{ b.book.pk }}">
|
||||||
Test
|
{% if b.recipes %}
|
||||||
{% for r in b.recipes %}
|
<ul>
|
||||||
{{ r }}
|
{% for r in b.recipes %}
|
||||||
{% endfor %}
|
<li><a href="#" onClick='openRecipe({{r.recipe.pk}})'>{{ r.recipe.name }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
{% trans 'There are no recipes in this book yet.' %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% include 'include/recipe_open_modal.html' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -12,8 +12,16 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-9">
|
||||||
|
<h3>{{ recipe.name }} <a href="{% url 'edit_recipe' recipe.pk %}"><i class="fas fa-pencil-alt"></i></a></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col col-md-3" style="text-align: right">
|
||||||
|
<button class="btn btn-success" onclick="$('#bookmarkModal').modal({'show':true})"><i
|
||||||
|
class="fas fa-bookmark"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>{{ recipe.name }} <a href="{% url 'edit_recipe' recipe.pk %}"><i class="fas fa-pencil-alt"></i></a></h3>
|
|
||||||
{% if recipe.storage %}
|
{% if recipe.storage %}
|
||||||
<small>{% trans 'in' %} <a
|
<small>{% trans 'in' %} <a
|
||||||
href="{% url 'edit_storage' recipe.storage.pk %}">{{ recipe.storage.name }}</a></small><br/>
|
href="{% url 'edit_storage' recipe.storage.pk %}">{{ recipe.storage.name }}</a></small><br/>
|
||||||
@ -125,7 +133,7 @@
|
|||||||
<form method="POST" class="post-form">
|
<form method="POST" class="post-form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<textarea name="text" cols="15" rows="2" class="textarea form-control" required id="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">
|
<div class="input-group-append">
|
||||||
<input type="submit" value="{% trans 'Comment' %}" class="btn btn-success">
|
<input type="submit" value="{% trans 'Comment' %}" class="btn btn-success">
|
||||||
</div>
|
</div>
|
||||||
@ -147,10 +155,36 @@
|
|||||||
{% include 'include/recipe_open_modal.html' %}
|
{% include 'include/recipe_open_modal.html' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- Bookmark Modal -->
|
||||||
|
<div class="modal fade" id="bookmarkModal" tabindex="-1" role="dialog" aria-labelledby="bookmarkModalLabel"
|
||||||
|
aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="bookmarkModalLabel">Modal title</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" class="post-form">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ bookmark_form|crispy }}
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function reloadIngredients() {
|
function reloadIngredients() {
|
||||||
factor = Number($('#in_factor').val())
|
factor = Number($('#in_factor').val());
|
||||||
ingredients = {
|
ingredients = {
|
||||||
{% for i in ingredients %}
|
{% for i in ingredients %}
|
||||||
{{ i.pk }}: {{ i.amount|unlocalize }},
|
{{ i.pk }}: {{ i.amount|unlocalize }},
|
||||||
|
@ -30,24 +30,33 @@ def recipe_view(request, pk):
|
|||||||
comments = Comment.objects.filter(recipe=recipe)
|
comments = Comment.objects.filter(recipe=recipe)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = CommentForm(request.POST)
|
comment_form = CommentForm(request.POST, prefix='comment')
|
||||||
if form.is_valid():
|
if comment_form.is_valid():
|
||||||
comment = Comment()
|
comment = Comment()
|
||||||
comment.recipe = recipe
|
comment.recipe = recipe
|
||||||
comment.text = form.cleaned_data['text']
|
comment.text = comment_form.cleaned_data['text']
|
||||||
comment.created_by = request.user
|
comment.created_by = request.user
|
||||||
|
|
||||||
comment.save()
|
comment.save()
|
||||||
|
|
||||||
messages.add_message(request, messages.SUCCESS, _('Comment saved!'))
|
messages.add_message(request, messages.SUCCESS, _('Comment saved!'))
|
||||||
return HttpResponseRedirect(reverse('view_recipe', args=[pk]))
|
|
||||||
else:
|
bookmark_form = RecipeBookEntryForm(request.POST, prefix='bookmark')
|
||||||
messages.add_message(request, messages.ERROR, _('There was an error saving this comment!'))
|
if bookmark_form.is_valid():
|
||||||
else:
|
bookmark = RecipeBookEntry()
|
||||||
form = CommentForm()
|
bookmark.recipe = recipe
|
||||||
|
bookmark.book = bookmark_form.cleaned_data['book']
|
||||||
|
|
||||||
|
bookmark.save()
|
||||||
|
|
||||||
|
messages.add_message(request, messages.SUCCESS, _('Bookmark saved!'))
|
||||||
|
|
||||||
|
comment_form = CommentForm()
|
||||||
|
bookmark_form = RecipeBookEntryForm()
|
||||||
|
|
||||||
return render(request, 'recipe_view.html',
|
return render(request, 'recipe_view.html',
|
||||||
{'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'form': form})
|
{'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'comment_form': comment_form,
|
||||||
|
'bookmark_form': bookmark_form})
|
||||||
|
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
@ -57,6 +66,6 @@ def books(request):
|
|||||||
books = RecipeBook.objects.filter(user=request.user).all()
|
books = RecipeBook.objects.filter(user=request.user).all()
|
||||||
|
|
||||||
for b in books:
|
for b in books:
|
||||||
book_list.append( {'book': b, 'recipes': RecipeBookEntry.objects.filter(book=b).all()})
|
book_list.append({'book': b, 'recipes': RecipeBookEntry.objects.filter(book=b).all()})
|
||||||
|
|
||||||
return render(request, 'books.html', {'book_list': book_list})
|
return render(request, 'books.html', {'book_list': book_list})
|
||||||
|
Loading…
Reference in New Issue
Block a user