fixed unauthenticated recipe viewing

This commit is contained in:
vabene1111
2020-06-16 11:49:02 +02:00
parent dee7249347
commit 62c049a6de
2 changed files with 27 additions and 17 deletions

View File

@@ -49,11 +49,13 @@
<a class="btn btn-light" onclick="window.print()" data-toggle="tooltip" <a class="btn btn-light" onclick="window.print()" data-toggle="tooltip"
data-placement="top" title="{% trans 'Print' %}"><i data-placement="top" title="{% trans 'Print' %}"><i
class="fas fa-print"></i></a> class="fas fa-print"></i></a>
<a class="btn btn-primary" href="{% url 'view_export' %}?r={{ recipe.pk }}" target="_blank" rel="noopener noreferrer" <a class="btn btn-primary" href="{% url 'view_export' %}?r={{ recipe.pk }}" target="_blank"
rel="noopener noreferrer"
data-toggle="tooltip" data-toggle="tooltip"
data-placement="top" title="{% trans 'Export recipe' %}"><i data-placement="top" title="{% trans 'Export recipe' %}"><i
class="fas fa-file-export"></i></a> class="fas fa-file-export"></i></a>
<a class="btn btn-primary" href="{% url 'new_share_link' recipe.pk %}" target="_blank" rel="noopener noreferrer" <a class="btn btn-primary" href="{% url 'new_share_link' recipe.pk %}" target="_blank"
rel="noopener noreferrer"
data-toggle="tooltip" data-toggle="tooltip"
data-placement="top" title="{% trans 'Create share link' %}"><i class="fas fa-share-alt"></i></a> data-placement="top" title="{% trans 'Create share link' %}"><i class="fas fa-share-alt"></i></a>
</div> </div>
@@ -279,6 +281,7 @@
<br/> <br/>
{% endfor %} {% endfor %}
{% if request.user.is_authenticated %}
<div class="d-print-none"> <div class="d-print-none">
<form method="POST" class="post-form"> <form method="POST" class="post-form">
@@ -292,6 +295,7 @@
</div> </div>
</form> </form>
</div> </div>
{% endif %}
{% if recipe.storage %} {% if recipe.storage %}
{% include 'include/recipe_open_modal.html' %} {% include 'include/recipe_open_modal.html' %}
@@ -340,7 +344,9 @@
}); });
function roundDecimals(num) { function roundDecimals(num) {
return +(Math.round(num + "e+{{ request.user.userpreference.ingredient_decimals }}") + "e-{{ request.user.userpreference.ingredient_decimals }}"); let decimals = {% if request.user.userpreference.ingredient_decimals %}
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %}
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
} }
function reloadIngredients() { function reloadIngredients() {

View File

@@ -77,10 +77,14 @@ def recipe_view(request, pk, share=None):
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!')) messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
return HttpResponseRedirect(reverse('index')) return HttpResponseRedirect(reverse('index'))
ingredients = RecipeIngredient.objects.filter(recipe=recipe) ingredients = RecipeIngredient.objects.filter(recipe=recipe).all()
comments = Comment.objects.filter(recipe=recipe) comments = Comment.objects.filter(recipe=recipe)
if request.method == "POST": if request.method == "POST":
if not request.user.is_authenticated:
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to perform this action!'))
return HttpResponseRedirect(reverse('view_recipe', kwargs={'pk': recipe.pk, 'share': share}))
comment_form = CommentForm(request.POST, prefix='comment') comment_form = CommentForm(request.POST, prefix='comment')
if comment_form.is_valid(): if comment_form.is_valid():
comment = Comment() comment = Comment()